SlideShare a Scribd company logo
1 of 26
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010




        Program No 01) Write a program using friend
                        function.




                                                                                          1
                                                                                          Page




      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                    2010

      //Declaring friend function with inline code

      #include<iostream.h>

      #include<conio.h>

      class sample

      { private:

                    int x;

          public:

                    inline void getdata();

                    friend void display(class sample);

          };

      inline void sample :: getdata()

      { cout<<" Enter a value for x n";

          cin>>x;

      }

      inline void display(class sample abc)

      { cout<<" Entered number is : "<<abc.x;

          cout<<endl;

      }

      void main()

      { clrscr();

          sample obj;

          obj.getdata();
                                                                                                 2




          cout<<" Accessing the private data by non-member";
                                                                                                 Page




      RAJEEV SHARAN          ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                 2010

          cout<<" Function n";

          display(obj);

          getch();

      }




      OUTPUT

      Enter a value for x

      75

      Accessing the private data by non-member Function

      Entered number is : 75




                                                                                              3
                                                                                              Page




      RAJEEV SHARAN       ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010




          Program No 02) Write a program to store
       information about students using file handling
                       operations.                                                        4
                                                                                          Page




      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                 2010

      // array of nested class objects using file operations

      #include<fstream.h>

      #include<string.h>

      #include<iomanip.h>

      #include<conio.h>

      const int max=100;

      class student_info

      { private:

       char name[20];

       long int rollno;

       char sex;

       public:

       void getdata();

       void display();

       class date

       { private:

        int day, month, year;

        public:

        void getdate();

        void show_date();

        class age_class

        { private:
                                                                                              5




         int age;
                                                                                              Page




      RAJEEV SHARAN       ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                  2010

            public:

            void getage();

            void show_age();

           }; // end of age class declaration

          }; // end of date class declaration

      }; // end of student_info class declaration

      void student_info:: getdata()

      { cout<<" enter a name : t";

          cin>>name;

          cout<<endl;

          cout<<" roll no : t";

          cin>>rollno;

          cout<<endl;

          cout<<" sex : t";

          cin>>sex;

          cout<<endl;

      }

      void student_info::date::getdate()

      { cout<<" enter a date of birth"<<endl;

          cout<<" day : ";

          cin>>day;

          cout<<" month : ";
                                                                                               6




          cin>>month;
                                                                                               Page




      RAJEEV SHARAN        ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                  2010

          cout<<" year : ";

          cin>>year;

      }

      void student_info :: date :: age_class :: getage()

      { cout<<" enter an age : ";

          cin>>age;

      }

      void student_info::display()

      { cout<<name<<"              ";

          cout<<rollno<<"          ";

          cout<<sex<<"        ";

      }

      void student_info:: date :: show_date()

      {cout<<day<<"/"<<month<<"/"<<year;

      }

      void student_info :: date :: age_class :: show_age()

      { cout<<"t"<<age<<endl;

      }

      void main()

      { clrscr();

          student_info obj1[max];

          student_info :: date obj2[max];
                                                                                               7




          student_info :: date :: age_class obj3[max];
                                                                                               Page




      RAJEEV SHARAN       ROLL NO-23    APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                  2010

       int n, i;

       fstream infile;

       char fname[10];

       cout<<" enter a file name to be stored?n";

       cin>>fname;

       infile.open(fname, ios::in ||ios::out ||ios::app );

       cout<<" how many students?n";

       cin>>n;

       //reading from the keyboard

       cout<<" enter the following information n";

       for(i=0; i<=n-1; ++i)

       { int j=i+1;

           cout<<" n object : "<<j<<endl;

           obj1[i].getdata();

           obj2[i].getdate();

           obj3[i].getage();

       }

       // storing onto the file

       infile.open(fname, ios::out);

       cout<<" storing onto the file................n";

       for(i=0; i<=n-1; ++i)

       { infile.write ((char*) &obj1[i], sizeof(obj1[i]));
                                                                                               8




           infile.write ((char*) &obj2[i], sizeof(obj2[i]));
                                                                                               Page




      RAJEEV SHARAN       ROLL NO-23    APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                  2010

           infile.write ((char*) &obj3[i], sizeof(obj3[i]));

       }

       infile.close();

       // reading from the file

       infile.open(fname, ios::in);

       cout<<" reading from the file................n";

       cout<<"nnn"<<endl;

       cout<<" contents of the array of nested classes n";


      cout<<"_________________________________________________________"
      <<endl;

       cout<<" name         roll no     sex      date of birth age   n";


      cout<<"_________________________________________________________
      "<<endl;

       for(i=0; i<=n-1; ++i)

       { infile.read ((char*) &obj1[i], sizeof(obj1[i]));

           infile.read ((char*) &obj2[i], sizeof(obj2[i]));

           infile.read ((char*) &obj3[i], sizeof(obj3[i]));

           obj1[i].display();

           obj2[i].show_date();

           obj3[i].show_age();

       }


      cout<<"_________________________________________________________
                                                                                               9




      "<<endl;
                                                                                               Page




      RAJEEV SHARAN       ROLL NO-23    APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                   2010

          infile.close();

          getch();

      }



      OUTPUT

      enter a file name to be stored?

      AP

      how many students?

      3

      enter the following information

      object : 1

      enter a name :

      Abhishek

      roll no : 1

      sex : M

      enter a date of birth

      day :16

      month : 6

      year: 1989

      enter an age : 20



      object : 2

       enter a name :
                                                                                                10




      Abhishek
                                                                                                Page




      roll no : 2


      RAJEEV SHARAN         ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                              2010

      sex : M

      enter a date of birth

      day :7

      month : 2

      year: 1989

      enter an age : 21



      object : 3

      enter a name :

      Adarsh

      roll no : 3

      sex : M

      enter a date of birth

      day :26

      month : 6

      year: 1989

      enter an age : 20

      storing onto the file..................................

      reading from the file............................
                                                                                                           11
                                                                                                           Page




      RAJEEV SHARAN             ROLL NO-23          APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                  2010

      contents of the array of nested classes



       name               roll no      sex        date of birth           age

      Abhishek              1           M          16/6/1989              20

      Abhishek              2           M           7/2/1989              21

      Adarsh                3           M          24/6/1989              20

      __________________________________________________________________________




                                                                                               12
                                                                                               Page




      RAJEEV SHARAN      ROLL NO-23     APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010




        Program no 03) Write a program of multiple level
                        inheritances.




                                                                                          13
                                                                                          Page




      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                    2010

      //program using multiple level of inheritance

      #include<iostream.h>

      #include<conio.h>

      #include<stdio.h>

      #include<string.h>

      #include<iomanip.h>

      const int max=100;

      class basic_info

      {

       private: char name[30];

                long int rollno;

                char sex;

       public: void getdata();

                void display();

      }; //end of class declaration

      class academic_fit:private basic_info

      { private: char course[20];

                 char semester[10];

                 int rank;

          public: void getdata();

                 void display();

      };
                                                                                                 14




      class physical_fit:private academic_fit
                                                                                                 Page




      RAJEEV SHARAN          ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                 2010

      { private: float height, weight;

          public: void getdata();

                 void display();

      };

      class financial_assist: private physical_fit

      { private: float amount;

          public: void getdata();

                void display();

      };

      void basic_info::getdata()

      {

       cout<<"ENTER A NAME ? n";

       cin>>name;

       cout<<"ROLL No. ? n";

       cin>>rollno;

       cout<<"SEX ? n";

       cin>>sex;

      }

      void basic_info::display()

      {

       cout<<name<<"t";

       cout<<rollno<<"t";
                                                                                              15




       cout<<sex<<"t";
                                                                                              Page




      RAJEEV SHARAN       ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                               2010

      }

      void academic_fit::getdata()

      {basic_info::getdata();

       cout<<"COURSE-NAME (BFTECH/MFTECH/BFDES/MFM/MFDES)?n";

       cin>>course;

       cout<<"SEMESTER (First/Second etc.)?n";

       cin>>semester;

       cout<<"RANK OF THE STUDENT?n";

       cin>>rank;

      }

      void academic_fit::display()

      { basic_info::display();

          cout<<course<<"t";

          cout<<semester<<"t";

          cout<<rank<<"t";

      }

      void physical_fit::getdata()

      { academic_fit::getdata()

       cout<<"ENTER height?n";

       cin>>height;

       cout<<"WEIGHT?";

       cin>>weight;
                                                                                            16




      }
                                                                                            Page




      RAJEEV SHARAN     ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                 2010

      void physical_fit::display()

      { academic_fit::display()

       cout<<height<<"t";

       cout<<weight<<"t";

      }

      void financial_assist::getdata()

      {physical_fit::getdata();

       cout<<"AMOUNT IN RUPEESn";

       cin>>amount;

      }

      void financial_assist::display()

      {physical_fit::display();

       cout<<setprecision(2);

       cout<<amount<<"t";

      }

      void main()

      { clrscr();

          financial_assist f[max];

          int n;

          cout<<"HOW MANY STUDENTS?n";

          cin>>n;

       cout<<"ENTER THE FOLLOWING INFORMATION FOR FINANCIAL
                                                                                              17




      ASSISTANCEn";
                                                                                              Page




          for(int i=0; i<=n-1; ++i)

      RAJEEV SHARAN       ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                   2010

          {cout<<"RECORD NO. "<<i+1<<endl;

          f[i].getdata();

          cout<<endl;

          }

      clrscr() ;

      cout<<endl;

       cout<<"ACADEMIC PERFORMANCE FOR FINANCIAL
      ASSISTANCEn";


      cout<<"_________________________________________________________
      _____________________n";

       cout<<"NAME ROLLNO SEX                       COURSE SEMESTER RANK
      HEIGHT WEIGHT AMOUNT n";


      cout<<"_________________________________________________________
      _____________________n";

          for(i=0; i<=n-1; ++i)

          {

          f[i].display();

          cout<<endl;

          }

          cout<<endl;


      cout<<"_________________________________________________________
      ______________________n";

          getch();
                                                                                                18
                                                                                                Page




      }


      RAJEEV SHARAN         ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010



      OUTPUT

      HOW MANY STUDENTS?
      3
      ENTER THE FOLLOWING INFORMATION
      RECORD: 1
      ENTER A NAME?
      Sarvesh
      ROLL No. ?
      13
      SEX?
      M
      COURSE?
      BFTECH
      SEMESTER?
      Fourth
      RANK?
      1
      HEIGHT?
      174
      WEIGHT?
      59
      AMOUNT IN RUPEES?
      60000
      RECORD : 2
      ENTER A NAME?
      Prashant
      ROLL No. ?
      19
       SEX ?
      M
      COURSE?
      BFTECH
      SEMESTER?
      Fourth
      RANK?
      3
      HEIGHT?
      166
      WEIGHT?
      63
      AMOUNT IN RUPEES?
      40000
      RECORD : 3
                                                                                          19




      ENTER A NAME ?
      Rajeev
                                                                                          Page




      ROLL No. ?


      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                      2010

      23
      SEX ?
      M
      COURSE?
      BFTECH
      SEMESTER?
      Fourth
      RANK?
      15
       HEIGHT?
      164
      WEIGHT?
      53
      AMOUNT IN RUPEES?
      80000

      ACADEMIC PERFORMANCE FOR FINANCIAL ASSISTANCE
      ___________________________________________________________________________
      NAME       ROLLNO     SEX   COURSE     SEMESTER RANK       HEIGHT WEIGHT AMOUNT
      ___________________________________________________________________________
      Sarvesh       13       M     BFTECH    Fourth         1      174       59      60000

      Prashant      19       M     BFTECH    Fourth         3      166       63      4 0000

      Rajeev        23       M     BFTECH    Fourth         15     164       53      80000

      __________________________________________________________________________________________




                                                                                                   20
                                                                                                   Page




      RAJEEV SHARAN      ROLL NO-23    APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010




      Program No 04) Write a program using virtual
                      functions.




                                                                                          21
                                                                                          Page




      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                               2010

      // virtual functions

      #include<iostream.h>
      #include<conio.h>
      #include<stdio.h>
      #include<string.h>
      class baseA
      {
       public: int a;
       virtual void getdata()
       {cout<<"enter the value for A:"<<endl;
        cin>>a;
        }
       virtual void display()
       {
       cout<<"the value of a in base class A:t"<<a;
       cout<<endl;
       }
      };
      class baseB:public baseA
      {
       public: int a;
       virtual void getdata()
       {cout<<"enter the value for B:"<<endl;
        cin>>a;
        }
        virtual void display()
       {
       cout<<"the value of a in base class B:t"<<a;
       cout<<endl;
       }
      };
      class baseC:public baseB
      {
       public: int a;
        virtual void getdata()
       {cout<<"enter the value for C:"<<endl;
        cin>>a;
        }
        virtual void display()
       {
                                                                                            22




       cout<<"the value of a in base class C:t"<<a;
                                                                                            Page




       cout<<endl;


      RAJEEV SHARAN     ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010

       }
      };
      class derivedD: public baseC
      {
       private:
       float x;
       public:
       derivedD()
       { x=12.03;
       }
        virtual void getdata()
       {cout<<"enter the value for D:"<<endl;
        cin>>a;
        }
        virtual void display()
       {
       cout<<"the value of a in derived class D:t"<<a;
       cout<<endl;
       cout<<"The value of float constant in derived class D;t"<<x<<endl;
       }
      };
      void main()
      {
       clrscr();
       derivedD objd;
       baseA obja;
       baseB objb;
       baseC objc;
       baseA *ptr[4];
       ptr[0]=&obja;
       ptr[1]=&objb;
       ptr[2]=&objc;
       ptr[3]=&objd;
       for(int i=0;i<4;i++)
       { ptr[i]->getdata();
         cout<<endl;
         }
       for(int j=0;j<4;j++)
       { ptr[j]->display();
        cout<<endl;
        }
                                                                                          23




       getch();
                                                                                          Page




      }


      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                                2010

      OUTPUT

      enter the value for A:
      65
      enter the value for B:
      78
      enter the value for C:
      45
      enter the value for D:
      89
      the value of a in base class A: 65
      the value of a in base class B: 78
      the value of a in base class C: 45
      the value of a in derived class D: 89
      The value of float constant in derived class D: 12.03




                                                                                             24
                                                                                             Page




      RAJEEV SHARAN     ROLL NO-23    APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010




       Program no 05) Write a program of exception
                       handling




                                                                                          25
                                                                                          Page




      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
OBJECT ORIENTED PROGRAMMINGS (C++)                                             2010




                                                                                          26
                                                                                          Page




      RAJEEV SHARAN   ROLL NO-23   APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE

More Related Content

What's hot

Flat panel displays and plasma panel displays
Flat panel displays and plasma panel displays Flat panel displays and plasma panel displays
Flat panel displays and plasma panel displays hemanth kumar
 
Podman - The Next Generation of Linux Container Tools
Podman - The Next Generation of Linux Container ToolsPodman - The Next Generation of Linux Container Tools
Podman - The Next Generation of Linux Container ToolsI Putu Hariyadi
 
Congestion control
Congestion controlCongestion control
Congestion controlAman Jaiswal
 
Bluetooth Details.ppt
Bluetooth Details.pptBluetooth Details.ppt
Bluetooth Details.pptVignesh kumar
 
19 Network Layer Protocols
19 Network Layer Protocols19 Network Layer Protocols
19 Network Layer ProtocolsMeenakshi Paul
 
Functional Requirements for an Interlinear Text Editor
Functional Requirements for an Interlinear Text EditorFunctional Requirements for an Interlinear Text Editor
Functional Requirements for an Interlinear Text EditorBaden Hughes
 
Data Warehouse techniques on Intermediate Census and Demographic Statistics W...
Data Warehouse techniques on Intermediate Census and Demographic Statistics W...Data Warehouse techniques on Intermediate Census and Demographic Statistics W...
Data Warehouse techniques on Intermediate Census and Demographic Statistics W...Vincenzo Patruno
 
Gstreamer plugin devpt_1
Gstreamer plugin devpt_1Gstreamer plugin devpt_1
Gstreamer plugin devpt_1shiv_nj
 
C++정리 스마트포인터
C++정리 스마트포인터C++정리 스마트포인터
C++정리 스마트포인터fefe7270
 
Firewall Architecture
Firewall Architecture Firewall Architecture
Firewall Architecture Yovan Chandel
 
IoT & Applications Digital Notes.pdf
IoT & Applications Digital Notes.pdfIoT & Applications Digital Notes.pdf
IoT & Applications Digital Notes.pdfkanaka vardhini
 
Transmission impairments(presentation)
Transmission impairments(presentation)Transmission impairments(presentation)
Transmission impairments(presentation)Vivek Kumar
 
Multiplexing in mobile computing
Multiplexing in mobile computingMultiplexing in mobile computing
Multiplexing in mobile computingZituSahu
 
Gstreamer Basics
Gstreamer BasicsGstreamer Basics
Gstreamer Basicsidrajeev
 

What's hot (20)

TCP/IP(networking)
TCP/IP(networking)TCP/IP(networking)
TCP/IP(networking)
 
Flat panel displays and plasma panel displays
Flat panel displays and plasma panel displays Flat panel displays and plasma panel displays
Flat panel displays and plasma panel displays
 
Transport Protocols
Transport ProtocolsTransport Protocols
Transport Protocols
 
Podman - The Next Generation of Linux Container Tools
Podman - The Next Generation of Linux Container ToolsPodman - The Next Generation of Linux Container Tools
Podman - The Next Generation of Linux Container Tools
 
Congestion control
Congestion controlCongestion control
Congestion control
 
Bluetooth Details.ppt
Bluetooth Details.pptBluetooth Details.ppt
Bluetooth Details.ppt
 
19 Network Layer Protocols
19 Network Layer Protocols19 Network Layer Protocols
19 Network Layer Protocols
 
Ch1 delays, loss, and throughput l5
Ch1 delays, loss, and throughput l5Ch1 delays, loss, and throughput l5
Ch1 delays, loss, and throughput l5
 
Functional Requirements for an Interlinear Text Editor
Functional Requirements for an Interlinear Text EditorFunctional Requirements for an Interlinear Text Editor
Functional Requirements for an Interlinear Text Editor
 
Data Warehouse techniques on Intermediate Census and Demographic Statistics W...
Data Warehouse techniques on Intermediate Census and Demographic Statistics W...Data Warehouse techniques on Intermediate Census and Demographic Statistics W...
Data Warehouse techniques on Intermediate Census and Demographic Statistics W...
 
Gstreamer plugin devpt_1
Gstreamer plugin devpt_1Gstreamer plugin devpt_1
Gstreamer plugin devpt_1
 
C++정리 스마트포인터
C++정리 스마트포인터C++정리 스마트포인터
C++정리 스마트포인터
 
Firewall Architecture
Firewall Architecture Firewall Architecture
Firewall Architecture
 
Multimedia lecture6
Multimedia lecture6Multimedia lecture6
Multimedia lecture6
 
IoT & Applications Digital Notes.pdf
IoT & Applications Digital Notes.pdfIoT & Applications Digital Notes.pdf
IoT & Applications Digital Notes.pdf
 
Dns ppt
Dns pptDns ppt
Dns ppt
 
Transmission impairments(presentation)
Transmission impairments(presentation)Transmission impairments(presentation)
Transmission impairments(presentation)
 
Multiplexing in mobile computing
Multiplexing in mobile computingMultiplexing in mobile computing
Multiplexing in mobile computing
 
Gstreamer Basics
Gstreamer BasicsGstreamer Basics
Gstreamer Basics
 
Congestion control
Congestion controlCongestion control
Congestion control
 

Viewers also liked

Order specification sheet
Order specification sheetOrder specification sheet
Order specification sheetRajeev Sharan
 
Inventory management
Inventory managementInventory management
Inventory managementRajeev Sharan
 
Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)
Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)
Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)Rajeev Sharan
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
P 10 p-4ac756g50(gb )
P 10 p-4ac756g50(gb )P 10 p-4ac756g50(gb )
P 10 p-4ac756g50(gb )Rajeev Sharan
 
Accounting and finance
Accounting and financeAccounting and finance
Accounting and financeRajeev Sharan
 
Human resource management
Human resource managementHuman resource management
Human resource managementRajeev Sharan
 
Customer relationship management
Customer relationship managementCustomer relationship management
Customer relationship managementRajeev Sharan
 
RECENT TRENDS OF MAINTENANCE MANAGEMENT
RECENT TRENDS OF MAINTENANCE MANAGEMENTRECENT TRENDS OF MAINTENANCE MANAGEMENT
RECENT TRENDS OF MAINTENANCE MANAGEMENTRajeev Sharan
 
Production and materials management
Production and materials managementProduction and materials management
Production and materials managementRajeev Sharan
 
Material requirement planning
Material requirement planningMaterial requirement planning
Material requirement planningRajeev Sharan
 
SETTING UP OF A GARMENT INDUSTRY
SETTING UP OF A GARMENT INDUSTRYSETTING UP OF A GARMENT INDUSTRY
SETTING UP OF A GARMENT INDUSTRYRajeev Sharan
 
Maintenance management
Maintenance managementMaintenance management
Maintenance managementRajeev Sharan
 

Viewers also liked (20)

Order specification sheet
Order specification sheetOrder specification sheet
Order specification sheet
 
Inventory management
Inventory managementInventory management
Inventory management
 
Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)
Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)
Graduation Project (SA 8000 & it's frame work for Indian Apparel Manufacturing)
 
IPR
IPRIPR
IPR
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
P 10 p-4ac756g50(gb )
P 10 p-4ac756g50(gb )P 10 p-4ac756g50(gb )
P 10 p-4ac756g50(gb )
 
Final pl doc
Final pl docFinal pl doc
Final pl doc
 
Accounting and finance
Accounting and financeAccounting and finance
Accounting and finance
 
Human resource management
Human resource managementHuman resource management
Human resource management
 
Customer relationship management
Customer relationship managementCustomer relationship management
Customer relationship management
 
Calculator code
Calculator codeCalculator code
Calculator code
 
RECENT TRENDS OF MAINTENANCE MANAGEMENT
RECENT TRENDS OF MAINTENANCE MANAGEMENTRECENT TRENDS OF MAINTENANCE MANAGEMENT
RECENT TRENDS OF MAINTENANCE MANAGEMENT
 
Production and materials management
Production and materials managementProduction and materials management
Production and materials management
 
Ergonomics
Ergonomics Ergonomics
Ergonomics
 
Material requirement planning
Material requirement planningMaterial requirement planning
Material requirement planning
 
SETTING UP OF A GARMENT INDUSTRY
SETTING UP OF A GARMENT INDUSTRYSETTING UP OF A GARMENT INDUSTRY
SETTING UP OF A GARMENT INDUSTRY
 
Shirt spec sheet
Shirt spec sheetShirt spec sheet
Shirt spec sheet
 
Maintenance management
Maintenance managementMaintenance management
Maintenance management
 
PAD FINAL DOC
PAD FINAL DOCPAD FINAL DOC
PAD FINAL DOC
 
Sp 02
Sp 02Sp 02
Sp 02
 

Similar to Declaring friend function with inline code

Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Abu Saleh
 
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo FinochiettiRoslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti.NET Conf UY
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1Teksify
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android UpdateGarth Gilmour
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYRadha Maruthiyan
 

Similar to Declaring friend function with inline code (20)

OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo FinochiettiRoslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
 
Roslyn: el futuro de C#
Roslyn: el futuro de C#Roslyn: el futuro de C#
Roslyn: el futuro de C#
 
Day 1
Day 1Day 1
Day 1
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 

More from Rajeev Sharan

More from Rajeev Sharan (20)

Supply chain management
Supply chain managementSupply chain management
Supply chain management
 
Production module-ERP
Production module-ERPProduction module-ERP
Production module-ERP
 
Supply chain management
Supply chain managementSupply chain management
Supply chain management
 
E smartx.ppt
E smartx.pptE smartx.ppt
E smartx.ppt
 
Maintenance management
Maintenance managementMaintenance management
Maintenance management
 
Maintenance management
Maintenance managementMaintenance management
Maintenance management
 
product analysis & development- sourcing
product analysis & development- sourcingproduct analysis & development- sourcing
product analysis & development- sourcing
 
Product Analysis & Development
Product Analysis & DevelopmentProduct Analysis & Development
Product Analysis & Development
 
Ergonomics
ErgonomicsErgonomics
Ergonomics
 
Total service management
Total service managementTotal service management
Total service management
 
Lean- automobile
Lean- automobileLean- automobile
Lean- automobile
 
Vb (2)
Vb (2)Vb (2)
Vb (2)
 
Vb (1)
Vb (1)Vb (1)
Vb (1)
 
Vb
VbVb
Vb
 
INVENTORY OPTIMIZATION
INVENTORY OPTIMIZATIONINVENTORY OPTIMIZATION
INVENTORY OPTIMIZATION
 
Professional practices
Professional practicesProfessional practices
Professional practices
 
Report writing.....
Report writing.....Report writing.....
Report writing.....
 
Business ethics @ tata
Business ethics @ tataBusiness ethics @ tata
Business ethics @ tata
 
Software maintenance
Software maintenance Software maintenance
Software maintenance
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 

Recently uploaded

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 

Declaring friend function with inline code

  • 1. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 Program No 01) Write a program using friend function. 1 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 2. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 //Declaring friend function with inline code #include<iostream.h> #include<conio.h> class sample { private: int x; public: inline void getdata(); friend void display(class sample); }; inline void sample :: getdata() { cout<<" Enter a value for x n"; cin>>x; } inline void display(class sample abc) { cout<<" Entered number is : "<<abc.x; cout<<endl; } void main() { clrscr(); sample obj; obj.getdata(); 2 cout<<" Accessing the private data by non-member"; Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 3. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 cout<<" Function n"; display(obj); getch(); } OUTPUT Enter a value for x 75 Accessing the private data by non-member Function Entered number is : 75 3 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 4. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 Program No 02) Write a program to store information about students using file handling operations. 4 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 5. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 // array of nested class objects using file operations #include<fstream.h> #include<string.h> #include<iomanip.h> #include<conio.h> const int max=100; class student_info { private: char name[20]; long int rollno; char sex; public: void getdata(); void display(); class date { private: int day, month, year; public: void getdate(); void show_date(); class age_class { private: 5 int age; Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 6. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 public: void getage(); void show_age(); }; // end of age class declaration }; // end of date class declaration }; // end of student_info class declaration void student_info:: getdata() { cout<<" enter a name : t"; cin>>name; cout<<endl; cout<<" roll no : t"; cin>>rollno; cout<<endl; cout<<" sex : t"; cin>>sex; cout<<endl; } void student_info::date::getdate() { cout<<" enter a date of birth"<<endl; cout<<" day : "; cin>>day; cout<<" month : "; 6 cin>>month; Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 7. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 cout<<" year : "; cin>>year; } void student_info :: date :: age_class :: getage() { cout<<" enter an age : "; cin>>age; } void student_info::display() { cout<<name<<" "; cout<<rollno<<" "; cout<<sex<<" "; } void student_info:: date :: show_date() {cout<<day<<"/"<<month<<"/"<<year; } void student_info :: date :: age_class :: show_age() { cout<<"t"<<age<<endl; } void main() { clrscr(); student_info obj1[max]; student_info :: date obj2[max]; 7 student_info :: date :: age_class obj3[max]; Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 8. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 int n, i; fstream infile; char fname[10]; cout<<" enter a file name to be stored?n"; cin>>fname; infile.open(fname, ios::in ||ios::out ||ios::app ); cout<<" how many students?n"; cin>>n; //reading from the keyboard cout<<" enter the following information n"; for(i=0; i<=n-1; ++i) { int j=i+1; cout<<" n object : "<<j<<endl; obj1[i].getdata(); obj2[i].getdate(); obj3[i].getage(); } // storing onto the file infile.open(fname, ios::out); cout<<" storing onto the file................n"; for(i=0; i<=n-1; ++i) { infile.write ((char*) &obj1[i], sizeof(obj1[i])); 8 infile.write ((char*) &obj2[i], sizeof(obj2[i])); Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 9. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 infile.write ((char*) &obj3[i], sizeof(obj3[i])); } infile.close(); // reading from the file infile.open(fname, ios::in); cout<<" reading from the file................n"; cout<<"nnn"<<endl; cout<<" contents of the array of nested classes n"; cout<<"_________________________________________________________" <<endl; cout<<" name roll no sex date of birth age n"; cout<<"_________________________________________________________ "<<endl; for(i=0; i<=n-1; ++i) { infile.read ((char*) &obj1[i], sizeof(obj1[i])); infile.read ((char*) &obj2[i], sizeof(obj2[i])); infile.read ((char*) &obj3[i], sizeof(obj3[i])); obj1[i].display(); obj2[i].show_date(); obj3[i].show_age(); } cout<<"_________________________________________________________ 9 "<<endl; Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 10. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 infile.close(); getch(); } OUTPUT enter a file name to be stored? AP how many students? 3 enter the following information object : 1 enter a name : Abhishek roll no : 1 sex : M enter a date of birth day :16 month : 6 year: 1989 enter an age : 20 object : 2 enter a name : 10 Abhishek Page roll no : 2 RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 11. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 sex : M enter a date of birth day :7 month : 2 year: 1989 enter an age : 21 object : 3 enter a name : Adarsh roll no : 3 sex : M enter a date of birth day :26 month : 6 year: 1989 enter an age : 20 storing onto the file.................................. reading from the file............................ 11 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 12. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 contents of the array of nested classes name roll no sex date of birth age Abhishek 1 M 16/6/1989 20 Abhishek 2 M 7/2/1989 21 Adarsh 3 M 24/6/1989 20 __________________________________________________________________________ 12 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 13. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 Program no 03) Write a program of multiple level inheritances. 13 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 14. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 //program using multiple level of inheritance #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<iomanip.h> const int max=100; class basic_info { private: char name[30]; long int rollno; char sex; public: void getdata(); void display(); }; //end of class declaration class academic_fit:private basic_info { private: char course[20]; char semester[10]; int rank; public: void getdata(); void display(); }; 14 class physical_fit:private academic_fit Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 15. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 { private: float height, weight; public: void getdata(); void display(); }; class financial_assist: private physical_fit { private: float amount; public: void getdata(); void display(); }; void basic_info::getdata() { cout<<"ENTER A NAME ? n"; cin>>name; cout<<"ROLL No. ? n"; cin>>rollno; cout<<"SEX ? n"; cin>>sex; } void basic_info::display() { cout<<name<<"t"; cout<<rollno<<"t"; 15 cout<<sex<<"t"; Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 16. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 } void academic_fit::getdata() {basic_info::getdata(); cout<<"COURSE-NAME (BFTECH/MFTECH/BFDES/MFM/MFDES)?n"; cin>>course; cout<<"SEMESTER (First/Second etc.)?n"; cin>>semester; cout<<"RANK OF THE STUDENT?n"; cin>>rank; } void academic_fit::display() { basic_info::display(); cout<<course<<"t"; cout<<semester<<"t"; cout<<rank<<"t"; } void physical_fit::getdata() { academic_fit::getdata() cout<<"ENTER height?n"; cin>>height; cout<<"WEIGHT?"; cin>>weight; 16 } Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 17. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 void physical_fit::display() { academic_fit::display() cout<<height<<"t"; cout<<weight<<"t"; } void financial_assist::getdata() {physical_fit::getdata(); cout<<"AMOUNT IN RUPEESn"; cin>>amount; } void financial_assist::display() {physical_fit::display(); cout<<setprecision(2); cout<<amount<<"t"; } void main() { clrscr(); financial_assist f[max]; int n; cout<<"HOW MANY STUDENTS?n"; cin>>n; cout<<"ENTER THE FOLLOWING INFORMATION FOR FINANCIAL 17 ASSISTANCEn"; Page for(int i=0; i<=n-1; ++i) RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 18. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 {cout<<"RECORD NO. "<<i+1<<endl; f[i].getdata(); cout<<endl; } clrscr() ; cout<<endl; cout<<"ACADEMIC PERFORMANCE FOR FINANCIAL ASSISTANCEn"; cout<<"_________________________________________________________ _____________________n"; cout<<"NAME ROLLNO SEX COURSE SEMESTER RANK HEIGHT WEIGHT AMOUNT n"; cout<<"_________________________________________________________ _____________________n"; for(i=0; i<=n-1; ++i) { f[i].display(); cout<<endl; } cout<<endl; cout<<"_________________________________________________________ ______________________n"; getch(); 18 Page } RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 19. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 OUTPUT HOW MANY STUDENTS? 3 ENTER THE FOLLOWING INFORMATION RECORD: 1 ENTER A NAME? Sarvesh ROLL No. ? 13 SEX? M COURSE? BFTECH SEMESTER? Fourth RANK? 1 HEIGHT? 174 WEIGHT? 59 AMOUNT IN RUPEES? 60000 RECORD : 2 ENTER A NAME? Prashant ROLL No. ? 19 SEX ? M COURSE? BFTECH SEMESTER? Fourth RANK? 3 HEIGHT? 166 WEIGHT? 63 AMOUNT IN RUPEES? 40000 RECORD : 3 19 ENTER A NAME ? Rajeev Page ROLL No. ? RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 20. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 23 SEX ? M COURSE? BFTECH SEMESTER? Fourth RANK? 15 HEIGHT? 164 WEIGHT? 53 AMOUNT IN RUPEES? 80000 ACADEMIC PERFORMANCE FOR FINANCIAL ASSISTANCE ___________________________________________________________________________ NAME ROLLNO SEX COURSE SEMESTER RANK HEIGHT WEIGHT AMOUNT ___________________________________________________________________________ Sarvesh 13 M BFTECH Fourth 1 174 59 60000 Prashant 19 M BFTECH Fourth 3 166 63 4 0000 Rajeev 23 M BFTECH Fourth 15 164 53 80000 __________________________________________________________________________________________ 20 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 21. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 Program No 04) Write a program using virtual functions. 21 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 22. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 // virtual functions #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class baseA { public: int a; virtual void getdata() {cout<<"enter the value for A:"<<endl; cin>>a; } virtual void display() { cout<<"the value of a in base class A:t"<<a; cout<<endl; } }; class baseB:public baseA { public: int a; virtual void getdata() {cout<<"enter the value for B:"<<endl; cin>>a; } virtual void display() { cout<<"the value of a in base class B:t"<<a; cout<<endl; } }; class baseC:public baseB { public: int a; virtual void getdata() {cout<<"enter the value for C:"<<endl; cin>>a; } virtual void display() { 22 cout<<"the value of a in base class C:t"<<a; Page cout<<endl; RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 23. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 } }; class derivedD: public baseC { private: float x; public: derivedD() { x=12.03; } virtual void getdata() {cout<<"enter the value for D:"<<endl; cin>>a; } virtual void display() { cout<<"the value of a in derived class D:t"<<a; cout<<endl; cout<<"The value of float constant in derived class D;t"<<x<<endl; } }; void main() { clrscr(); derivedD objd; baseA obja; baseB objb; baseC objc; baseA *ptr[4]; ptr[0]=&obja; ptr[1]=&objb; ptr[2]=&objc; ptr[3]=&objd; for(int i=0;i<4;i++) { ptr[i]->getdata(); cout<<endl; } for(int j=0;j<4;j++) { ptr[j]->display(); cout<<endl; } 23 getch(); Page } RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 24. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 OUTPUT enter the value for A: 65 enter the value for B: 78 enter the value for C: 45 enter the value for D: 89 the value of a in base class A: 65 the value of a in base class B: 78 the value of a in base class C: 45 the value of a in derived class D: 89 The value of float constant in derived class D: 12.03 24 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 25. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 Program no 05) Write a program of exception handling 25 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE
  • 26. OBJECT ORIENTED PROGRAMMINGS (C++) 2010 26 Page RAJEEV SHARAN ROLL NO-23 APPAREL PRODUCTION (08-12)/SEM-04/DFT/NIFT BANGALORE