OBJECT ORIENTED PROGRAMMINGS 2010




Q 1) Define a class to represent a bank account. Include the following members:
Data Members:
   Name of the Depositor
   Account Number
   Type of Account
   Balance amount in the account

Member Functions:
   To assign the initial values.
   To deposit an account.
   To withdraw an amount after checking the balance.

Write a C++ main program to display account number, name and balance.




 1|Page
OBJECT ORIENTED PROGRAMMINGS 2010



#include<iostream.h>
#include<conio.h> //for clrscr()
#include<stdio.h> //for gets()
#include<iomanip.h>
const int LEN=30;
const int max=100;
class members
{ private:
 char name[LEN];
 unsigned long bal_amount;
 char acctype[LEN];
 public:
 unsigned long accnumb;
 members()
 { bal_amount =1000000;
 }
 void getdata()
 { cout<<"Enter Name:"<<endl;
   gets(name);
   cout<<"Enter AccountNo:"<<endl;
   cin>>accnumb;
   cout<<"Enter the Account-type:"<<endl;
   gets(acctype);
   cout<<"Enter the balance amount:"<<endl;
   cin>>bal_amount;
 }
 void putdata()
 { cout<<"Name: "<<name<<"t";
   cout<<"AccountNo: "<<accnumb<<"t";
   cout<<"Account Type: "<<acctype<<"t";
   cout<<"Balance Amount: "<<bal_amount<<"t";
   cout<<endl;
 }
 void withdraw()
 { unsigned long wdraw_amount;
   cout<<"Enter the amount U want to withdraw: t";
   cin>>wdraw_amount;
   cout<<endl;
   if(wdraw_amount>bal_amount || wdraw_amount%100!=0)
   { cout<<"U have entered the wrong amount."<<endl;
     cout<<"Amount less than balance and multiple of 100 only can be
withdrawn"<<endl;
     wdraw_amount=0;
   }
   else
2|Page
OBJECT ORIENTED PROGRAMMINGS 2010


  bal_amount= bal_amount-wdraw_amount;
  cout<<"Amount withdrawn: t"<<wdraw_amount<<"t";
  cout<<"Balance: t"<<bal_amount<<"t"<<endl;
  }
  void check_balance()
  {
    cout<<"Balance: t"<<bal_amount<<endl;
  }
  void deposit_amount()
  { unsigned long d_amount;
    cout<<"Enter the amount U want to deposit: t";
    cin>>d_amount;
    cout<<endl;
    bal_amount=bal_amount+d_amount;
    cout<<"Balance: t"<<bal_amount<<endl;
  }
};
void main()
{
 clrscr();
 members m[max];
 unsigned long acc_no;
 int n;
 cout<<"The no of records U want 2 be entered: t"<<endl;
 cin>>n;
 cout<<"Enter the following Records"<<endl;
 for (int i=0;i<n;++i)
 {
  cout<<"Record:t"<<i+1<<endl;
  m[i].getdata();
 }
 clrscr();
 for (i=0; i<n; ++i)
 {cout<<"Record "<<i+1<<endl;
  m[i].putdata();
 }
 char ch;
 cout<<"Do u want 2 continue for any account?"<<endl;
 cin>>ch;
 clrscr();
 while(ch=='y')
 {
  cout<<"Enter ur account not"<<endl;
  cin>>acc_no;
  for(i=0; i<n; i++)
  { if(acc_no==m[i].accnumb)
    { int opt;
3|Page
OBJECT ORIENTED PROGRAMMINGS 2010


     m[i].putdata();
     char ans;
     cout<<"Do U want 2 continue for any account-process(y/n)?t";
     cin>>ans;
     cout<<endl;
     while(ans=='y')
     {
        cout<<"Enter ur option (1-check balance, 2-deposit, 3-withdraw)"<<endl;
        cin>>opt;
        cout<<endl;
        switch(opt)
        { case 1: m[i].check_balance();
                   break;
           case 2: m[i].deposit_amount();
                   break;
           case 3: m[i].withdraw();
                   break;
           deafault: cout<<"Wrong Option"<<endl;
         }
         cout<<"Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry?"<<endl;
         cin>>ans;
         cout<<endl;
        }
      }
     }
   cout<<"Do U want 2 continue for any other account?"<<endl;
   cin>>ch;
   }
   getch();
  }




OUTPUT
The no of records U want 2 be entered:
3
Enter the following Records
Record     1
Name:
Sarvesh
Enter Account No:
123456
Enter the Account-type:
Current
Enter the balance amount:
91234567

4|Page
OBJECT ORIENTED PROGRAMMINGS 2010


Record     2
Name:
Prashant
Enter Account No:
456789
Enter the Account-type:
Saving
Enter the balance amount:
90234567
Record     3
Name:
Rajeev
Enter Account No:
789012
Enter the Account-type:
Current
Enter the balance amount:
98765432

Clear-screen..............

Record    1
Name: Sarvesh       Account No: 123456         Account-type: Current      Balance amount: 91234567
Record    2
Name: Prashant        Account No: 456789       Account-type: Saving       Balance amount: 90234567
Record    3
Name: Rajeev          Account No: 789012       Account-type: Current      Balance amount: 98765432
Do u want 2 continue for any account?
y

Clear-screen...

Enter ur account no
789012
Name: Rajeev           Account No: 789012         Account-type: Current   Balance amount: 98765432
Do U want 2 continue for any account-process(y/n)? y
Enter ur option (1-check balance, 2-deposit, 3-withdraw)
1
Balance: 98765432
Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry?
y
Enter ur option (1-check balance, 2-deposit, 3-withdraw)
2
Enter the amount U want to deposit: 67890543
Balance: 166655975
Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry?
y
Enter ur option (1-check balance, 2-deposit, 3-withdraw)
3
Enter the amount U want to withdraw: 4567890
U have entered the wrong amount.
Amount less than balance and multiple of 100 only can be withdrawn
Amount withdrawn:           0        Balance: 166655975
Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry?
y
Enter ur option (1-check balance, 2-deposit, 3-withdraw)
5|Page
OBJECT ORIENTED PROGRAMMINGS 2010


3
Enter the amount U want to withdraw: 4567800
Amount withdrawn:      4567800         Balance:        162088175
Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry?
n
Do U want 2 continue for any other account?
n




        Q 2) Write an operator overloading program to write S3+=S2.




6|Page
OBJECT ORIENTED PROGRAMMINGS 2010




#include<iostream.h>
#include<conio.h>
class numb
{ private:
  int i;
  public:
  numb()
  { i=10;
  }
  void operator++()
  { i=i+1;
    cout<<i<<endl;
  }
};
void main()
{ numb n;
  clrscr();
  int j;
  cout<<"How many times u want to increment the value?t";
  cin>>j;
  for(int m=0;m<j;++m)
  {n.operator++();
  }
  getch();
}


OUTPUT
7|Page
OBJECT ORIENTED PROGRAMMINGS 2010


How many times u want to increment the value? 8
11
12
13
14
15
16
17
18




// overloading prefix ++ incrementer operator for obtaining Fibonacci series
#include<iostream.h>
#include<conio.h>
class fibonacci
{ private:
  unsigned long int f0, f1, fib;
  public:
  fibonacci(); //constructor
  void operator++();
  void display();
};
fibonacci::fibonacci()
{ f0=0;
  f1=1;
  fib=f0+f1;
}
void fibonacci::display()
{ cout<<fib<<"t";
}
void fibonacci::operator++()
{f0=f1;
 f1=fib;
 fib=f0+f1;
}

8|Page
OBJECT ORIENTED PROGRAMMINGS 2010


void main()
{
clrscr();
fibonacci obj;
int n;
cout<<"How many fibonacci numbers are to be displayed? n";
cin>>n;
for(int i=0; i<=n-1;++i)
{
obj.display();
++obj;
}
getch();
}


OUTPUT

How many fibonacci numbers are to be displayed?

10

1    2     3     5     8     13      21     34    55   89




Q 3) Write an operator overloading program to Overload ‘>’ operator so as to
find greater among two instances of the class.
9|Page
OBJECT ORIENTED PROGRAMMINGS 2010




//overloading of comparison operators
#include<iostream.h>
#include<conio.h>
class sample
{ private:
          int value;
  public:
          sample();
          sample( int one);
          void display();
          int operator > (sample obj);
};
sample::sample()
{
 value = 0;
 }
sample::sample( int one)
10 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


{
 value = one;
}
void sample::display()
{
 cout<<"value "<<value<<endl;
}
int sample::operator > (sample obja)
{
 return (value > obja.value);
}
void main()
{
 clrscr();
 sample obja(20);
 sample objb(100);
 cout<<(obja>objb)<<endl;
 cout<<(objb>obja)<<endl;
 getch();
}


OUTPUT

0

1




11 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010




                  Q 4) WAP using Single and Multiple Inheritance.




//single inheritance using array of objects
#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 physical_fit:public basic_info
{
 private: float height,weight;
 public: void getdata();
         void display();
};
void basic_info::getdata()
12 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


{
 cout<<"ENTER A NAME ? n";
 cin>>name;
 cout<<"ROLL No. ? n";
 cin>>rollno;
 cout<<"SEX ? n";
 cin>>sex;
}
void basic_info::display()
{
 cout<<name<<"        ";
 cout<<rollno<<"       ";
 cout<<sex<<"      ";
}
void physical_fit::getdata()
{
 basic_info::getdata();
 cout<<"HEIGHT ? n";
 cin>>height;
 cout<<"WEIGHT ? n";
 cin>>weight;
}
void physical_fit::display()
{
 basic_info::display();
 cout<<setprecision(2);
 cout<<height<<" ";
 cout<<weight<<"        ";
}
void main()
{
 clrscr();
 physical_fit a[max];
 int i,n;
 cout<<"HOW MANY STUDENTS ? n";
 cin>>n;
 cout<<"ENTER THE FOLLOWING INFORMATION n";
 for(i=0;i<=n-1;++i)
 {
  cout<<"RECORD : "<<i+1<<endl;
  a[i].getdata();
 }
 cout<<endl;
 cout<<"_________________________________________________ n";
 cout<<"NAME ROLLNO SEX HEIGHT WEIGHT n";
 cout<<"_________________________________________________ n";
 for(i=0;i<=n-1;++i)
13 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


 {
  a[i].display();
  cout<<endl;
 }
 cout<<endl;
 cout<<"_________________________________________________ n";
 getch();
}




OUTPUT

HOW MANY STUDENTS?
3
ENTER THE FOLLOWING INFORMATION
RECORD: 1
ENTER A NAME?
Sarvesh
ROLL No. ?
13
 SEX?
M
 HEIGHT?
174
WEIGHT?
59
RECORD : 2
ENTER A NAME?
Prashant
ROLL No. ?
19
 SEX ?
M
 HEIGHT?
166
WEIGHT?
63
RECORD : 3
ENTER A NAME ?
Rajeev
ROLL No. ?
23
 SEX ?
M
 HEIGHT?
14 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


164
WEIGHT?
53

_________________________________________________
 NAME         ROLLNO SEX HEIGHT WEIGHT
 _________________________________________________

Sarvesh        13        M       174       59

Prashant       19        M       166       63

Rajeev          23       M       164       53

_________________________________________________




#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class baseA
{
 public: int a;
};
class baseB
{
 public: int a;
};

15 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


class baseC
{
 public: int a;
};
class derivedD: public baseA,public baseB, public baseC
{
 public: int a;
};
void main()
{
 clrscr();
 derivedD objd;
 objd.a=10; //local to the derived class
 cout<<"n VALUE OF a IN THE DERIVED CLASS = "<<objd.a;
 cout<<endl;
 cout<<"n VALUE OF a IN THE baseA = "<<objd.baseA::a;
 cout<<endl;
 cout<<"n VALUE OF a IN THE baseB = "<<objd.baseB::a;
 cout<<endl;
 cout<<"n VALUE OF a IN THE baseC = "<<objd.baseC::a;
 cout<<endl;
 cout<<endl;
 getch();
}




#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class baseA
{
 public: int a;
};
class baseB
16 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


{
 public: int a;
};
class baseC
{
 public: int a;
};
class derivedD: public baseA,public baseB, public baseC
{
 public: int a;
};
void main()
{
 clrscr();
 derivedD objd;
 objd.a=10;
 objd.baseA::a=20;
 objd.baseB::a=30;
 objd.baseC::a=40;
 cout<<"n VALUE OF a IN THE DERIVED CLASS = "<<objd.a;
 cout<<endl;
 cout<<"n VALUE OF a IN THE baseA = "<<objd.baseA::a;
 cout<<endl;
 cout<<"n VALUE OF a IN THE baseB = "<<objd.baseB::a;
 cout<<endl;
 cout<<"n VALUE OF a IN THE baseC = "<<objd.baseC::a;
 cout<<endl;
 cout<<endl;
 getch();
}




OUTPUT


VALUE OF a IN THE DERIVED CLASS = 10
VALUE OF a IN THE baseA = 20
VALUE OF a IN THE baseB = 30

17 | P a g e
OBJECT ORIENTED PROGRAMMINGS 2010


VALUE OF a IN THE baseC = 40




18 | P a g e

Rajeev oops 2nd march

  • 1.
    OBJECT ORIENTED PROGRAMMINGS2010 Q 1) Define a class to represent a bank account. Include the following members: Data Members:  Name of the Depositor  Account Number  Type of Account  Balance amount in the account Member Functions:  To assign the initial values.  To deposit an account.  To withdraw an amount after checking the balance. Write a C++ main program to display account number, name and balance. 1|Page
  • 2.
    OBJECT ORIENTED PROGRAMMINGS2010 #include<iostream.h> #include<conio.h> //for clrscr() #include<stdio.h> //for gets() #include<iomanip.h> const int LEN=30; const int max=100; class members { private: char name[LEN]; unsigned long bal_amount; char acctype[LEN]; public: unsigned long accnumb; members() { bal_amount =1000000; } void getdata() { cout<<"Enter Name:"<<endl; gets(name); cout<<"Enter AccountNo:"<<endl; cin>>accnumb; cout<<"Enter the Account-type:"<<endl; gets(acctype); cout<<"Enter the balance amount:"<<endl; cin>>bal_amount; } void putdata() { cout<<"Name: "<<name<<"t"; cout<<"AccountNo: "<<accnumb<<"t"; cout<<"Account Type: "<<acctype<<"t"; cout<<"Balance Amount: "<<bal_amount<<"t"; cout<<endl; } void withdraw() { unsigned long wdraw_amount; cout<<"Enter the amount U want to withdraw: t"; cin>>wdraw_amount; cout<<endl; if(wdraw_amount>bal_amount || wdraw_amount%100!=0) { cout<<"U have entered the wrong amount."<<endl; cout<<"Amount less than balance and multiple of 100 only can be withdrawn"<<endl; wdraw_amount=0; } else 2|Page
  • 3.
    OBJECT ORIENTED PROGRAMMINGS2010 bal_amount= bal_amount-wdraw_amount; cout<<"Amount withdrawn: t"<<wdraw_amount<<"t"; cout<<"Balance: t"<<bal_amount<<"t"<<endl; } void check_balance() { cout<<"Balance: t"<<bal_amount<<endl; } void deposit_amount() { unsigned long d_amount; cout<<"Enter the amount U want to deposit: t"; cin>>d_amount; cout<<endl; bal_amount=bal_amount+d_amount; cout<<"Balance: t"<<bal_amount<<endl; } }; void main() { clrscr(); members m[max]; unsigned long acc_no; int n; cout<<"The no of records U want 2 be entered: t"<<endl; cin>>n; cout<<"Enter the following Records"<<endl; for (int i=0;i<n;++i) { cout<<"Record:t"<<i+1<<endl; m[i].getdata(); } clrscr(); for (i=0; i<n; ++i) {cout<<"Record "<<i+1<<endl; m[i].putdata(); } char ch; cout<<"Do u want 2 continue for any account?"<<endl; cin>>ch; clrscr(); while(ch=='y') { cout<<"Enter ur account not"<<endl; cin>>acc_no; for(i=0; i<n; i++) { if(acc_no==m[i].accnumb) { int opt; 3|Page
  • 4.
    OBJECT ORIENTED PROGRAMMINGS2010 m[i].putdata(); char ans; cout<<"Do U want 2 continue for any account-process(y/n)?t"; cin>>ans; cout<<endl; while(ans=='y') { cout<<"Enter ur option (1-check balance, 2-deposit, 3-withdraw)"<<endl; cin>>opt; cout<<endl; switch(opt) { case 1: m[i].check_balance(); break; case 2: m[i].deposit_amount(); break; case 3: m[i].withdraw(); break; deafault: cout<<"Wrong Option"<<endl; } cout<<"Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry?"<<endl; cin>>ans; cout<<endl; } } } cout<<"Do U want 2 continue for any other account?"<<endl; cin>>ch; } getch(); } OUTPUT The no of records U want 2 be entered: 3 Enter the following Records Record 1 Name: Sarvesh Enter Account No: 123456 Enter the Account-type: Current Enter the balance amount: 91234567 4|Page
  • 5.
    OBJECT ORIENTED PROGRAMMINGS2010 Record 2 Name: Prashant Enter Account No: 456789 Enter the Account-type: Saving Enter the balance amount: 90234567 Record 3 Name: Rajeev Enter Account No: 789012 Enter the Account-type: Current Enter the balance amount: 98765432 Clear-screen.............. Record 1 Name: Sarvesh Account No: 123456 Account-type: Current Balance amount: 91234567 Record 2 Name: Prashant Account No: 456789 Account-type: Saving Balance amount: 90234567 Record 3 Name: Rajeev Account No: 789012 Account-type: Current Balance amount: 98765432 Do u want 2 continue for any account? y Clear-screen... Enter ur account no 789012 Name: Rajeev Account No: 789012 Account-type: Current Balance amount: 98765432 Do U want 2 continue for any account-process(y/n)? y Enter ur option (1-check balance, 2-deposit, 3-withdraw) 1 Balance: 98765432 Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry? y Enter ur option (1-check balance, 2-deposit, 3-withdraw) 2 Enter the amount U want to deposit: 67890543 Balance: 166655975 Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry? y Enter ur option (1-check balance, 2-deposit, 3-withdraw) 3 Enter the amount U want to withdraw: 4567890 U have entered the wrong amount. Amount less than balance and multiple of 100 only can be withdrawn Amount withdrawn: 0 Balance: 166655975 Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry? y Enter ur option (1-check balance, 2-deposit, 3-withdraw) 5|Page
  • 6.
    OBJECT ORIENTED PROGRAMMINGS2010 3 Enter the amount U want to withdraw: 4567800 Amount withdrawn: 4567800 Balance: 162088175 Do U want 2 continue for next withdrawl/ deposit/ balance-inquiry? n Do U want 2 continue for any other account? n Q 2) Write an operator overloading program to write S3+=S2. 6|Page
  • 7.
    OBJECT ORIENTED PROGRAMMINGS2010 #include<iostream.h> #include<conio.h> class numb { private: int i; public: numb() { i=10; } void operator++() { i=i+1; cout<<i<<endl; } }; void main() { numb n; clrscr(); int j; cout<<"How many times u want to increment the value?t"; cin>>j; for(int m=0;m<j;++m) {n.operator++(); } getch(); } OUTPUT 7|Page
  • 8.
    OBJECT ORIENTED PROGRAMMINGS2010 How many times u want to increment the value? 8 11 12 13 14 15 16 17 18 // overloading prefix ++ incrementer operator for obtaining Fibonacci series #include<iostream.h> #include<conio.h> class fibonacci { private: unsigned long int f0, f1, fib; public: fibonacci(); //constructor void operator++(); void display(); }; fibonacci::fibonacci() { f0=0; f1=1; fib=f0+f1; } void fibonacci::display() { cout<<fib<<"t"; } void fibonacci::operator++() {f0=f1; f1=fib; fib=f0+f1; } 8|Page
  • 9.
    OBJECT ORIENTED PROGRAMMINGS2010 void main() { clrscr(); fibonacci obj; int n; cout<<"How many fibonacci numbers are to be displayed? n"; cin>>n; for(int i=0; i<=n-1;++i) { obj.display(); ++obj; } getch(); } OUTPUT How many fibonacci numbers are to be displayed? 10 1 2 3 5 8 13 21 34 55 89 Q 3) Write an operator overloading program to Overload ‘>’ operator so as to find greater among two instances of the class. 9|Page
  • 10.
    OBJECT ORIENTED PROGRAMMINGS2010 //overloading of comparison operators #include<iostream.h> #include<conio.h> class sample { private: int value; public: sample(); sample( int one); void display(); int operator > (sample obj); }; sample::sample() { value = 0; } sample::sample( int one) 10 | P a g e
  • 11.
    OBJECT ORIENTED PROGRAMMINGS2010 { value = one; } void sample::display() { cout<<"value "<<value<<endl; } int sample::operator > (sample obja) { return (value > obja.value); } void main() { clrscr(); sample obja(20); sample objb(100); cout<<(obja>objb)<<endl; cout<<(objb>obja)<<endl; getch(); } OUTPUT 0 1 11 | P a g e
  • 12.
    OBJECT ORIENTED PROGRAMMINGS2010 Q 4) WAP using Single and Multiple Inheritance. //single inheritance using array of objects #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 physical_fit:public basic_info { private: float height,weight; public: void getdata(); void display(); }; void basic_info::getdata() 12 | P a g e
  • 13.
    OBJECT ORIENTED PROGRAMMINGS2010 { cout<<"ENTER A NAME ? n"; cin>>name; cout<<"ROLL No. ? n"; cin>>rollno; cout<<"SEX ? n"; cin>>sex; } void basic_info::display() { cout<<name<<" "; cout<<rollno<<" "; cout<<sex<<" "; } void physical_fit::getdata() { basic_info::getdata(); cout<<"HEIGHT ? n"; cin>>height; cout<<"WEIGHT ? n"; cin>>weight; } void physical_fit::display() { basic_info::display(); cout<<setprecision(2); cout<<height<<" "; cout<<weight<<" "; } void main() { clrscr(); physical_fit a[max]; int i,n; cout<<"HOW MANY STUDENTS ? n"; cin>>n; cout<<"ENTER THE FOLLOWING INFORMATION n"; for(i=0;i<=n-1;++i) { cout<<"RECORD : "<<i+1<<endl; a[i].getdata(); } cout<<endl; cout<<"_________________________________________________ n"; cout<<"NAME ROLLNO SEX HEIGHT WEIGHT n"; cout<<"_________________________________________________ n"; for(i=0;i<=n-1;++i) 13 | P a g e
  • 14.
    OBJECT ORIENTED PROGRAMMINGS2010 { a[i].display(); cout<<endl; } cout<<endl; cout<<"_________________________________________________ n"; getch(); } OUTPUT HOW MANY STUDENTS? 3 ENTER THE FOLLOWING INFORMATION RECORD: 1 ENTER A NAME? Sarvesh ROLL No. ? 13 SEX? M HEIGHT? 174 WEIGHT? 59 RECORD : 2 ENTER A NAME? Prashant ROLL No. ? 19 SEX ? M HEIGHT? 166 WEIGHT? 63 RECORD : 3 ENTER A NAME ? Rajeev ROLL No. ? 23 SEX ? M HEIGHT? 14 | P a g e
  • 15.
    OBJECT ORIENTED PROGRAMMINGS2010 164 WEIGHT? 53 _________________________________________________ NAME ROLLNO SEX HEIGHT WEIGHT _________________________________________________ Sarvesh 13 M 174 59 Prashant 19 M 166 63 Rajeev 23 M 164 53 _________________________________________________ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class baseA { public: int a; }; class baseB { public: int a; }; 15 | P a g e
  • 16.
    OBJECT ORIENTED PROGRAMMINGS2010 class baseC { public: int a; }; class derivedD: public baseA,public baseB, public baseC { public: int a; }; void main() { clrscr(); derivedD objd; objd.a=10; //local to the derived class cout<<"n VALUE OF a IN THE DERIVED CLASS = "<<objd.a; cout<<endl; cout<<"n VALUE OF a IN THE baseA = "<<objd.baseA::a; cout<<endl; cout<<"n VALUE OF a IN THE baseB = "<<objd.baseB::a; cout<<endl; cout<<"n VALUE OF a IN THE baseC = "<<objd.baseC::a; cout<<endl; cout<<endl; getch(); } #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class baseA { public: int a; }; class baseB 16 | P a g e
  • 17.
    OBJECT ORIENTED PROGRAMMINGS2010 { public: int a; }; class baseC { public: int a; }; class derivedD: public baseA,public baseB, public baseC { public: int a; }; void main() { clrscr(); derivedD objd; objd.a=10; objd.baseA::a=20; objd.baseB::a=30; objd.baseC::a=40; cout<<"n VALUE OF a IN THE DERIVED CLASS = "<<objd.a; cout<<endl; cout<<"n VALUE OF a IN THE baseA = "<<objd.baseA::a; cout<<endl; cout<<"n VALUE OF a IN THE baseB = "<<objd.baseB::a; cout<<endl; cout<<"n VALUE OF a IN THE baseC = "<<objd.baseC::a; cout<<endl; cout<<endl; getch(); } OUTPUT VALUE OF a IN THE DERIVED CLASS = 10 VALUE OF a IN THE baseA = 20 VALUE OF a IN THE baseB = 30 17 | P a g e
  • 18.
    OBJECT ORIENTED PROGRAMMINGS2010 VALUE OF a IN THE baseC = 40 18 | P a g e