know yourselves. information, computer, 7 wonders, various.

Saturday, November 11, 2017

C++ programming language part: 48 Classes and Objects


Classes and Objects

The important elements of a object-oriented language are classes. You can define many objects and functions of the same classes. All the objects share the same copy of the member function but maintains a separate copy of the member data.The stracture of a class as follows: 

Class specifier
The specifier for a class starts with the keyword class and Name , the body of the class delimites by braces and is terminated by a semicolon,
class nova
{
     // member data
    // member function
};


Defining Object
An object suppose K is an instant of a class called nova as follows
nova k;                // k is called object


Access Specifiers
The body of the class contains two keyword: private and public
Private data or function can only be accesses from within the class. Public data or functions, on the other hand, are accessible outside the class. It is not possible to access the member data directly from function main() as they are private to the nova class. These data can be accessed only from the member function of that class.

  
 Program 38_1
            //class & object.demo
            #include
            #include
            class nova           //class defined
            {
            private:
               int age;         // member data
               char name[10];
public:
            void data_in()   // member function
            {
                        cout<<" Type your age "<
                        cin>>age;
                        cout<<"Type your name "<
                        cin>>name;
            }
               void data_out()   // member function
            {
                        cout<<" The age is "<
                        cout<<" The name is "<
            }
            };

            void main()
            {
             nova k;               // k is called object
             k.data_in();       //would be k->data_in() if pointer
             k.data_out();
           }

Program 38_2
            class nova           //class defined
            { private:
               int a,b,c;         // member data
             public:
              void data_in()   // member function
            { cout<<" Type two nunbers "<
               cin>>a>>b;  }
            void add()       // member function
            {  c=a+b;  }
            void data_out()   // member function
            {  cout<<" The sum is "<
            };
            void main()
            {
             nova k;               // k is called object
             k.data_in();       //would be k->data_in() if pointer
             k.add();
             k.data_out();  

             }





জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯

C++ programming language part: 49 Scope Resolution Operator


Scope Resolution Operator


The member functions are defined within the class specifier. These function can be also be defined outside the boundaries of the class the scope resulution operator

Program 39_1
            class nova                    //class defined
            { private:
               int age;                                 // member data
               char name[10];         //member data
              public:
              void data_in();          // member function
              void data_out();        // member function
            };
               void nova::data_in()             //scope resolution operator
            {  cout<<" Type your age "<
             cin>>age;
             cout<<"Type your name "<
             cin>>name;    }
               void nova::data_out()          //scope resolution operator
            { cout<<" The age is "<
             cout<<" The name is "<
            void main()
            {  nova k;                    // k is called object
             k.data_in();                 //would be k->data_in() if pointer
             k.data_out();  }

SUBscript

Program 41_1
                void main()
                {
            char days[7][10]={"sun","mon","tus","wed","ths","fri","sat"};
            char months[12][10]={"jan","feb","mar","apl","may","june","july","aug","sep","oct","nov","dec"};
                int i,j;
                cout<<"Type date of the months "<
            cin>>i;
                cout<<"Type number of the month "<
                cin>>j;
                int d;
                d=1%7;
                cout<<"The day is "<
                cout<<"The month is "<
                }


Program 41_2
            class bappi                   //class defined
            {
            private:
               int a,b;         // member data
            public:
               void date(int x,int y)
               {
                a=x;
                b=y;
                char days[7][10]={"sun","mon","tus","wed","ths","fri","sat"};
char months[12][10]={"jan","feb","mar","apl","may","june","july","aug","sep","oct","nov","dec"};
                int i;
                a=i%7;
                cout<<"The day is "<
                cout<<"The month is "<
               }
               };
              void main()
            {
             clrscr();
             int kk,ll;
             cout<<"Type the day "<
             cin>>kk;
             cout<<"Type the month "<
             cin>>ll;
             bappi k;
             k.date(kk,ll);

            }




Part- 86 assign the content of twostring



জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯