c++

Program to implement concept of multilevel inheritance

#include #include class sci { public: float mc,mp,mm; void entry(); void display(); }; class ads:public sci { public: float mphy,mpaint; void entry(); void display(); }; class opf:public ads { private: float total,perc; public: void calc(); void display(); }; void sci::entry() { cout<>mc; cout<>mp; cout<>mm; } void sci::display() { } void ads::entry() { sci::entry(); cout<>mphy; cout<>mpaint; […]

Program to enter the elements of array

#include #include main() { int a[20],i,n; clrscr(); cout<>n; cout<<"n Enter the element:n"; for(i=0;i<n;i++) { cout<<"n A["<<i<>a[i]; } cout<<"nnn"; cout<<"n Entered elemment of array were:"; for(i=0;i<n;i++) { cout<<"n A["<<i<<"]="<<a[i]; } getch(); }

Program to implement concept of single inheritance

#include #include class emp { private: int eid; float sal; public: void getdata(); void display(); }; class emp_phy:public emp { private: float ht,wt; public: void getdata(); void display(); }; void emp::getdata() { cout<>eid; cout<>sal; } void emp::display() { cout<<"n Employee ID:"<<eid; cout<<"n Salary:"<<sal; } void emp_phy::getdata() { emp::getdata(); cout<>wt; cout<>ht; } void emp_phy::display() { emp::display(); […]

Write a programof implement the concept of 2 classes having friendship

#include #include #include class first { Private: char name[15]; int eid; float sal; public: void getdata(); void display(); }; class second { private: char sex; float ht,wt; public: void getdata(); void display(); }; void first::getdata() { cout<>name; cout<>eid; cout<>sal; } void first::display() { cout<<"tttt"<<name<<"tt"<<eid<<"t"<<sal; } void second::getdata() { cout<>sex; cout<>ht; cout<>wt; } void second::display() { […]

Program to update content of data member by using concept of friend function.

#include #include class bca { private: int x; float y; char z; public: void getdata(); void display(); friend void update(bca); }; void bca::getdata() { cout<>x; cout<>y; cout<>z; } void bca::display() { cout<<"n Integer value is:"<<x; cout<<"n Floating point value is:"<<y; cout<<"n Entered character value is:"<<z; } void update(bca t) { t.x=(t.x)+15; t.y=(t.y)+15; t.z=(t.z)+15; } main() […]

Program to implement concept of copy constructor.

#include #include class manmeet { private: int x; float y; public: void getdata(); void display(); manmeet swap (manmeet); }; void manmeet::getdata() { cout<>x; cout<>y; } void manmeet::display() { cout<<"n Entered value of x was:"<<x; cout<<"n Entered value of y was:"<<y; } manmeet manmeet::swap(manmeet p) { manmeet t; t.x=p.x; t.y=p.y; return(t); } main() { clrscr(); manmeet […]

Write a program to implement the concept of parameterized constructor

#include #include class trial { private: int age; float wt; public: void getdata(); void display(); trial(int); trial(int,float); trial() { } }; void trial::getdata() { cout<>age; cout<>wt; } void trial::display() { cout<<"n The Age of Student Was:"<<age; cout<<"n The Weight of Student Was:"<<wt; } trial::trial(int t) { age=t; } trial::trial(int p,float q) { age=p; wt=q; } […]