Professional Documents
Culture Documents
SEMESTER: 2nd
Practical 5.1: Write a program that takes information about institute staff information for
3) Typist code, name, speed and daily wages and displays it using hierarchal inheritance
PROGRAM CODE
#include <iostream>
using namespace std;
#include <string>
class staff{
public:
string code, name, subject , publication;
string offcode, offname, offgrade; string
typcode, typname;
int speed, wages;
};
};
};
};
int main() {
int n;
if (n == 1)
{ teacher obj1;
obj1.tdetail();
obj1.tsdetail();
}
else if (n == 2)
{ officer obj2;
obj2.offdetail();
obj2.offsdetail();
}
else {
typist obj3;
obj3.typdetail();
obj3.typsdetail();
OBJECT ORIENTED PROGRAMMING USING
C++ LAB
}
return 0;}
Input screenshot
Output screenshot
OBJECT ORIENTED PROGRAMMING USING
C++ LAB
WHAT’S NEW
Practical 5.2: Create a class student having student uid and getnumber() ,putnumber() as member functions to get
the values and display it. Derive a class test having marks in different subjects and getmarks () and putmarks() as
member functions to get and display the values. Derive another class sports from student class having sports score
and getscore(), putscore() as member functions to get and display the values. Derive a class result from test
and sports class and define a function display() to calculate total marks. Implement it with the object of result
class. If it gives any error, resolve it by adding the required functionality.
PROGRAM CODE
#include<iostream>
class student
public:
int uid;
void getnumber() {
cin>>uid;
void putnumber() {
};
public:
float a,b,c;
void getmarks(){
endl; cin>>a;
endl; cin>>b;
endl; cin>>c;
void putmarks() {
cout<<"subject1 marks is" <<a << endl <<"subject2 marks is" <<b <<endl<<"subject1 marks is"<< c<< endl;
};
public:
float sc;
void getscore(){
cin>>sc;
};
public:
void display()
{ putnumber(
); putmarks();
putscore();
};
int main() {
result std1;
std1.getnumber();
std1.getmarks();
std1.getscore();
std1.display();
return 0;
Input screenshot
Program Code
#include<iostream>
class alpha
int x;
public:
alpha(int i)
x=i;
void show_x()
cout<<"x="<<x<<"\n";
};
class beta
float y;
public:
beta(float j)
y=j;
cout<<"beta initialized\n";
void show_y()
cout<<"y="<<y<<"\n";
};
int m,n;
public:
m=c,n=d;
cout<<"gamma initialized\n";
void show_mn()
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
};
int main()
gamma g(23,78.75,210,390);
g.show_x();
g.show_y();
g.show_mn();
return 0;
Input screenshot
WHAT’S NEW
LEARNING OUTCOMES