Professional Documents
Culture Documents
PROGRAM: 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
ALGORITHM:-1. Start.
2. Create a main class named staff.
3. Make subclasses such as teacher , typist , officer .
4. Enter the required information.
5. Print the result.
6. Stop.
PROGRAM:-
#include <iostream>
#include <string>
using namespace std;
// Staff class
class Staff {
protected:
int code;
string name;
public:
void get_staff_info() {
cout << "Enter code: ";
cin >> code;
cout << "Enter name: ";
cin >> name;
}
void display_staff_info() {
cout << "Code: " << code << endl;
cout << "Name: " << name << endl;
}
};
// Teacher class
class Teacher : public Staff {
protected:
string subject;
int publication;
public:
void get_teacher_info() {
get_staff_info();
cout << "Enter subject: ";
cin >> subject;
cout << "Enter publication: ";
cin >> publication;
}
void display_teacher_info() {
display_staff_info();
cout << "Subject: " << subject << endl;
cout << "Publication: " << publication << endl;
}
};
// Officer class
class Officer : public Staff {
protected:
string grade;
public:
void get_officer_info() {
get_staff_info();
cout << "Enter grade: ";
cin >> grade;
}
void display_officer_info() {
display_staff_info();
cout << "Grade: " << grade << endl;
}
};
// Typist class
class Typist : public Staff {
protected:
int speed;
float daily_wages;
public:
void get_typist_info() {
get_staff_info();
Subject :- Object Oriented Programming Using C++ SUBJECT CODE:- 22CSH-103
3
int main() {
Teacher t;
Officer o;
Typist ty;
return 0;
}
PROGRAM’S EXPLANATION (in brief) - This program is a simple C++ language program used
to explain the concept of inheritance .
4] To retrieve the output from the arithmetic method, select the print option.
OUTPUT:-
LEARNING OUTCOMES:–
Understanding the ways of execution and debugging the programs in C++ language.
Helps to build and compile a simple C++ language program to print information of a student.
PRACTICAL – 2.1(b)
PROGRAM: Create a class student with student uid and getnumber() and putnumber() as member
functions to get the values and display them. 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 the result class. If it gives any
error, resolve it by adding the required functionality.
ALGORITHM:-1. Start.
2. Create a main class named student.
3. Make subclasses such as test, sports, result.
4. Enter the required information.
5. Print the result.
6. Stop.
PROGRAM:-
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
string UID;
public:
void getnumber()
{
cout<<("\n Enter UID of Student:- ");
cin>>UID;
}
void putnumber()
{
cout<<("\n The UID of the student is:- ")<<UID;
}
};
class test: virtual public student
{
public:
int marks1;
int marks2;
void getmarks()
{
Subject :- Object Oriented Programming Using C++ SUBJECT CODE:- 22CSH-103
6
int main()
{ result stud;
stud.getnumber();
stud.getmarks();
stud.getscore();
stud.display();
Subject :- Object Oriented Programming Using C++ SUBJECT CODE:- 22CSH-103
7
return 0;
}
PROGRAM’S EXPLANATION (in brief) - This program is a simple C++ language program used
to explain, a simple and parameterized constructor.
4] To retrieve the output from the arithmetic method, select the print option.
OUTPUT:-
LEARNING OUTCOMES:–
Understanding the ways of execution and debugging the programs in C++ language.
Helps to build and compile a simple C++ language program to print information of a student.
PRACTICAL –2.1(c)
PROGRAM:- Write a program to illustrate how the constructors are implemented and the order in
which they are called when the classes are inherited. Use three classes named alpha, beta, gamma
such that alpha, beta are base classes and gamma is the derived classes inheriting alpha
&beta. Pass four variables to the gamma class object which will further send one
integer variable to alpha(), one float type variable to beta(). Show the order of
execution by invoking the constructor of the derived class.
ALGORITHM – 1. Start.
2. Make two main classes named alpha and beta.
3. Now make an inherited class gamma from the alpha and beta class.
4. Enter the integers and float numbers.
5. Print the result.
6. Stop.
PROGRAM CODE:–
#include<iostream>
using namespace std;
class alpha
{
int x;
public:
alpha(int i)
{
x=i;
cout<<"\n alpha initialized\n";
}
void show_x()
{
cout<<"x="<<x<<"\n";
}
};
class beta
{
float y;
public:
beta(float j)
{
y=j;
cout<<"\n beta initialized\n";
}
void show_y()
{
cout<<"y="<<y<<"\n";
}
};
void show_mn()
{
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
}
};
int main()
{
int i,m,n;
float j;
cout<<("\n Enter three integer values:- ");
cin>>i>>m>>n;
cout<<("\n Enter one float value:- ");
cin>>j;
gamma g(i,j,m,n);
g.show_x();
g.show_y();
g.show_mn();
return 0;
}
PROGRAM’S EXPLANATION (in brief) - This program is a simple C++ language program, using
a constructor and destructor.
RESULT –
LEARNING OUTCOMES –
Understanding the ways of execution and debugging the programs in C++ language.
Helps to build and compile a simple C++ language program for use of the inherited class.
2. Viva 8
3. Conduct 12
Total Marks 30