Wa0045.
Wa0045.
24BSIT080
ASSIGNMENT-4
QUE.1 Write a program to take a number from user using a member function and display the
number using a friend function.
CODE:
#include <iostream>
class Number {
int num;
public:
void input() {
};
void display(Number n) {
cout << "The number is: " << n.num << endl;
int main() {
Number n;
n.input();
display(n);
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.2Write a program to input price of two products in a member function and display the total bill
amount using a friend function.
CODE:
#include <iostream>
class Product {
public:
void input() {
};
void displayTotal(Product p) {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
cout << "Total bill amount: " << total << endl;
int main() {
Product p;
p.input();
displayTotal(p);
return 0;
OUTPUT:
QUE.3 Write a program to input three numbers in a member function and display the maximum
number using a friend function
CODE:
#include <iostream>
class Numbers {
int a, b, c;
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
public:
void input() {
};
void displayMax(Numbers n) {
cout << "The maximum number is: " << maxNum << endl;
int main() {
Numbers n;
n.input();
displayMax(n);
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.4 Write a program to calculate Simple Interest using a friend function. The input must be taken
using a member function defined outside the class.
CODE:
#include <iostream>
class Interest {
public:
void input() {
};
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
float calculateSI(Interest i) {
int main() {
Interest i;
i.input();
return 0;
OUTPUT:
QUE.5 Write a program for Single Inheritance. Create a base class that accepts one number. Create
a derived class that displays this number using a member function
CODE:
#include <iostream>
class Base {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
protected:
int number;
public:
void input() {
};
public:
void display() {
cout << "The number is: " << number << endl;
};
int main() {
Derived d;
d.input();
d.display();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.6Write a program for Multi-Level Inheritance. Define a class Parent to accept Father_name and
Mother_name. Create a subclass Child1 with a data member Chname1. Create another separate
class Child2 with ChName2, Father_Name, and Mother_Name. Further, derive a subclass Son from
both Child1 and Child2. Further, derive a subclass Son from both Child1 and Child2 with a data
member Son_Name. Accept input for all attributes and display the information using inheritance.
CODE:
#include<iostream>
class parent
protected:
char fname[20];
char mname[20];
public:
void getdata()
cin>>fname;
cin>>mname;
void putdata()
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
protected:
char cname1[20];
public:
void getdata()
parent :: getdata();
cin>>cname1;
void putdata()
parent :: putdata();
};
protected:
char cname2[20];
public:
void getdata(
{
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
parent::getdata();
cin>>cname2;
void putdata()
parent :: putdata();
};
protected:
char sname[20];
public:
void getdata()
child1 :: getdata();
child2 :: getdata();
cin>>sname;
void putdata()
child1 :: putdata();
child2 :: putdata();
};
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
int main()
son s;
s.getdata();
s.putdata();
return 0;
}OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.7 Write a program for Single Inheritance. Define a class Student to accept RollNo and
Student_Name. Create a subclass Marks to store marks for two subjects Sub1 and Sub2. Accept
input for all attributes and display the details using inheritance.
CODE:
#include <iostream>
class Student {
protected:
int rollNo;
string studentName;
public:
void input() {
};
protected:
public:
void inputMarks() {
input();
void display() {
};
int main() {
Marks m;
m.inputMarks();
m.display();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.8 Write a program for Multi-Level Inheritance. Define a class Student to accept RollNo and
Student_Name. Create a subclass Marks to store marks for two subjects Sub1 and Sub2. Further,
derive a subclass Result from Marks to calculate the Total and percentage. Accept input for all
attributes and display the details using inheritanc
CODE:
#include <iostream>
class Student {
protected:
int rollNo;
string studentName;
public:
void input() {
};
protected:
public:
void inputMarks() {
input();
};
public:
void display() {
cout << "Percentage: " << percentage << "%" << endl;
};
int main() {
Result r;
r.inputMarks();
r.display();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.9 Write a program for Multiple Inheritance. Define a class Education to accept Degree and
Class. Define another parent class Language with a data member Lang. Derive three subclasses:
Sales_Representative (includes Age,) Medical_Representative (includes Age and Experience) and
Worker. Accept input for all attributes and display the details using inheritance.
CODE:
#include <iostream>
class Education {
protected:
string degree;
string className;
public:
void inputEducation() {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
class Language {
protected:
string lang;
public:
void inputLanguage() {
};
protected:
int age;
public:
void inputSalesRep() {
inputEducation();
inputLanguage();
void display() {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
int main() {
SalesRepresentative sr;
sr.inputSalesRep();
sr.display();
return 0;
OUTPUT:
QUE.10 Write a program for Hierarchical Inheritance. Define a class Employee to accept Code and
EName. Create two subclasses: Teaching (includes Department and Publication) and Non-Teaching
(includes Designation and extra_holiday). Accept input for all attributes and display the details using
inheritanc
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
CODE:
#include <iostream>
class Employee {
protected:
int code;
string eName;
public:
void input() {
};
protected:
string department;
string publication;
public:
void inputTeaching() {
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
void displayTeaching() {
};
protected:
string designation;
int extraHolidays;
public:
void inputNonTeaching() {
void displayNonTeaching() {
};
int main() {
Teaching t;
NonTeaching nt;
t.inputTeaching();
t.displayTeaching();
nt.inputNonTeaching();
nt.displayNonTeaching();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.11 Write a program for Arithmetic Operations using Base and Derived Class. Define a base class
that accepts one number. Create a derived class that accepts another number. Perform basic
arithmetic operations (+ , - , * , /) using a member function in a derived class.
CODE:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
#include <iostream>
class Base {
protected:
float number1;
public:
};
private:
float number2;
public:
void arithmeticOperations() {
if (number2 != 0)
else
};
int main() {
calc.arithmeticOperations();
return 0;
OUTPUT:
QUE.12 Write a program to initialize two data members i.e. height and width by using default
constructor in a base class “Shape” and Calculate area of Rectangle by using a member function in a
derived class “Rectangle”.
CODE:
#include <iostream>
class Shape {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
protected:
float height;
float width;
public:
};
public:
float area() {
};
int main() {
Rectangle rect;
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.13 Write a program to enter Employee_ID, Employee_Name in a Base class by using member
function and enter Employee_Department and Number_of_ Leaves applied in a derived class. Show
the data using a member function of a derived class (member function definition must be outside
the class).
CODE:
#include <iostream>
class Employee {
protected:
int Employee_ID;
string Employee_Name;
public:
void input() {
};
private:
string Employee_Department;
int Number_of_Leaves;
public:
void inputDetails() {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
input();
void display() {
};
int main() {
DerivedEmployee emp;
emp.inputDetails();
emp.display();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.14 Write a program to input one number in a class “A” and another number in a class “B”. Now,
make summation of these two numbers in a derived class “C”.
CODE:
#include <iostream>
class A {
protected:
int num1;
public:
void input() {
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
class B {
protected:
int num2;
public:
void input() {
};
public:
void sum() {
};
int main() {
C obj;
obj.A::input();
obj.B::input();
obj.sum();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.15 Write a program for Multiple Inheritance. Define a base class “Father” to accept
Father_Salary. Define another base class “Mother” to accept Mother_Salary. Create a derived class
Income that calculates Total_Salary.
CODE:
#include <iostream>
class Father {
protected:
float Father_Salary;
public:
void inputFatherSalary() {
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
class Mother {
protected:
float Mother_Salary;
public:
void inputMotherSalary() {
};
public:
void calculateTotalSalary() {
};
int main() {
Income familyIncome;
familyIncome.inputFatherSalary();
familyIncome.inputMotherSalary();
familyIncome.calculateTotalSalary();
return 0;
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
OUTPUT:
QUE.16 Write a program for Student’s Marks, Total, Percentage and Grade Calculation. Define a
base class Internal to input IOOP, FOS, FCBP, BME, FCN internal marks. Define another base class
External to input IOOP, FOS, FCBP, BME, FCN external marks. Create a derived class Final to calculate
Total_Marks, Percentage and Grade (i.e. Distinction, First, Second, Pass, and Fail)
CODE:
#include <iostream>
class Internal {
protected:
public:
void inputInternalMarks() {
cout << "Enter Internal Marks (IOOP, FOS, FCBP, BME, FCN): ";
cin >> IOOP >> FOS >> FCBP >> BME >> FCN;
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
class External {
protected:
public:
void inputExternalMarks() {
cout << "Enter External Marks (IOOP, FOS, FCBP, BME, FCN): ";
cin >> IOOP >> FOS >> FCBP >> BME >> FCN;
};
public:
void calculateResults() {
string grade;
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
int main() {
Final student;
student.inputInternalMarks();
student.inputExternalMarks();
student.calculateResults();
return 0;
OUTPUT:
QUE.17 Write a program for Patient Appointment Details using Multiple Inheritance. Define a base
class Patient with Patient_Name and Disease_Name. Defne another base class Hospital with
Hospital_Name and City. Create a derive class Appointment with data members as Doctor_Name
and Consulting_Fees. Display all apointment details using a member function.
CODE:
#include <iostream>
class Internal {
protected:
public:
void inputInternalMarks() {
cout << "Enter Internal Marks (IOOP, FOS, FCBP, BME, FCN): ";
cin >> IOOP >> FOS >> FCBP >> BME >> FCN;
};
class External {
protected:
public:
void inputExternalMarks() {
cout << "Enter External Marks (IOOP, FOS, FCBP, BME, FCN): ";
cin >> IOOP >> FOS >> FCBP >> BME >> FCN;
};
public:
void calculateResults() {
string grade;
};
int main() {
Final student;
student.inputInternalMarks();
student.inputExternalMarks();
student.calculateResults();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.18 Write a program for Patient Appointment Details using Multiple Inheritance. Define a base
class Patient with Patient_Name and Disease_Name. Defne another base class Hospital with
Hospital_Name and City. Create a derive class Appointment with data members as Doctor_Name
and Consulting_Fees. Display all apointment details using a member function.
CODE:
#include <iostream>
class Surname {
protected:
string surname;
public:
void inputSurname() {
};
protected:
string Middle_Name;
public:
void inputMiddleName() {
inputSurname();
}
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
private:
string First_Name;
public:
void inputFirstName() {
inputMiddleName();
void displayFullName() {
cout << "Full Name: " << First_Name << " " << Middle_Name << " " << surname << ;
};
int main() {
Child child;
child.inputFirstName();
child.displayFullName();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.19 Write a program for Patient and Chemist details using Inheriatnce. Define a base class
Patient to accept Patient_ID and Name. Create an intermediate class Doctor with Doctor_Name and
Speciality. Derive a class Chemist from Doctor with Medicine_Name, Quantity and Price. Display all
the details using a member function defined outside the class.
CODE:
#include <iostream>
class Patient {
protected:
int Patient_ID;
string Name;
public:
void inputPatientDetails() {
};
protected:
string Doctor_Name;
string Speciality;
public:
void inputDoctorDetails() {
inputPatientDetails();
};
private:
string Medicine_Name;
int Quantity;
float Price;
public:
void inputChemistDetails() {
inputDoctorDetails();
void displayDetails() {
};
int main() {
Chemist chemist;
chemist.inputChemistDetails();
chemist.displayDetails();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
QUE.20 Write a program for Area Calculation of different shapes using inheritance. Define a base
class Area to accept Length and Width. Derive three subclasses: Rectangle to calculate L * W, Square
to calculate L * L, and Cuboid to Calculate 2 (LW + LH + WH). Implement member functions in their
respective derived classes.
CODE:
#include <iostream>
class Area {
protected:
float length;
float width;
public:
void inputDimensions() {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
};
public:
float calculateArea() {
};
public:
float calculateArea() {
};
public:
float calculateArea() {
};
int main() {
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
Rectangle rect;
rect.inputDimensions();
Square sq;
sq.inputDimensions();
Cuboid cub;
cub.inputDimensions();
return 0;
OUTPUT:
QUE.21
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4
CODE:
#include <iostream>
class GrandFather {
protected:
int No_of_Houses;
public:
No_of_Houses = houses;
};
protected:
int Plot_Area;
public:
Plot_Area = area;
};
class Mother {
protected:
int Gold_Occupied;
public:
Gold_Occupied = gold;
};
public:
void displayTotalProperty() {
cout << "Plot Area: " << Plot_Area << " square feet" << ;
cout << "Gold Occupied: " << Gold_Occupied << " grams" << ;
};
int main() {
Son son;
son.setHouses(3);
son.setPlotArea(5000);
son.setGoldOccupied(100);
son.displayTotalProperty();
return 0;
OUTPUT:
CTUC103 IOOP
24BSIT080
ASSIGNMENT-4