Oodp 7
Oodp 7
RA2111050010010
S S R Subramanya Hemant Konduri
QUESTION 1
Code
#include <iostream>
using namespace std;
// Base class
class std_basic_info {
private:
char name[30];
int age;
char gender;
public:
void getBasicInfo(void);
void putBasicInfo(void);
};
void std_basic_info::getBasicInfo(void)
{
cout << "Name: ";
cin >> name;
cout << "Age: ";
cin >> age;
cout << "Gender: ";
cin >> gender;
}
void std_basic_info::putBasicInfo(void)
{
cout << "Name: " << name << ",Age: " << age << ",Gender: " << gender << endl;
}
// Derived class
class std_result_info : public std_basic_info {
private:
int totalM;
float perc;
char grade;
public:
void getResultInfo(void);
void putResultInfo(void);
};
void std_result_info::getResultInfo(void)
{
void std_result_info::putResultInfo(void)
{
cout << "Total Marks: " << totalM<< endl;
}
int main()
{
std_result_info std;
std.getBasicInfo();
std.getResultInfo();
std.putBasicInfo();
std.putResultInfo();
return 0;
}
OUTPUT
QUESTION 2
CODE
#include <iostream>
#include <stdio.h>
using namespace std;
class basicInfo {
protected:
char name[30];
int empId;
char gender;
public:
void getBasicInfo(void)
{
cout << "Enter Name: ";
cin.getline(name, 30);
cout << "Enter Emp. Id: ";
cin >> empId;
cout << "Enter Gender: ";
cin >> gender;
}
};
class deptInfo {
protected:
char deptName[30];
char assignedWork[30];
int time2complete;
public:
void getDeptInfo(void)
{
cout << "Enter Department Name: ";
cin.ignore(1);
cin.getline(deptName, 30);
cout << "Enter assigned work: ";
fflush(stdin);
cin.getline(assignedWork, 30);
cout << "Enter time in hours to complete work: ";
cin >> time2complete;
}
};
getBasicInfo();
cout << "Enter employee's department info: " << endl;
getDeptInfo();
}
void printEmployeeInfo(void)
{
cout << "Employee's Information is: " << endl;
cout << "Basic Information...:" << endl;
cout << "Name: " << name << endl;
cout << "Employee ID: " << empId << endl;
cout << "Gender: " << gender << endl
<< endl;
int main()
{
employee emp;
emp.getEmployeeInfo();
emp.printEmployeeInfo();
return 0;
}
OUTPUT
QUESTION 3
#include <iostream>
using namespace std;
class Number {
private:
int num;
public:
void getNumber(void)
{
cout << "Enter an integer number: ";
cin >> num;
}
int returnNumber(void)
{
return num;
}
};
int main()
{
Square objS;
Cube objC;
int sqr, cube;
objS.getNumber();
sqr = objS.getSquare();
cout << "Square of " << objS.returnNumber() << " is: " << sqr << endl;
objC.getNumber();
cube = objC.getCube();
cout << "Cube of " << objS.returnNumber() << " is: " << cube << endl;
return 0;
}
OUTPUT
QUESTION 4
#include <iostream>
#include <stdio.h>
using namespace std;
class basicInfo {
protected:
char name[30];
int empId;
char gender;
public:
void getBasicInfo(void)
{
cout << "Enter Name: ";
cin.ignore(1);
cin.getline(name, 30);
cout << "Enter Emp. Id: ";
cin >> empId;
cout << "Enter Gender: ";
cin >> gender;
}
};
public:
void getDeptInfo(void)
{
getBasicInfo();
cout << "Enter Department Name: ";
cin.ignore(1);
cin.getline(deptName, 30);
cout << "Enter assigned work: ";
fflush(stdin);
cin.getline(assignedWork, 30);
cout << "Enter time in hours to complete work: ";
cin >> time2complete;
}
void printDeptInfo(void)
{
cout << "Employee's Information is: " << endl;
cout << "Basic Information...:" << endl;
cout << "Name: " << name << endl;
cout << "Employee ID: " << empId << endl;
cout << "Gender: " << gender << endl
<< endl;
public:
void getLoanInfo(void)
{
getBasicInfo();
cout << "Enter Loan Details: ";
cin.ignore(1);
cin.getline(loanDetails, 30);
cout << "Enter loan amount: ";
cin >> loanAmount;
}
void printLoanInfo(void)
{
cout << "Employee's Information is: " << endl;
cout << "Basic Information...:" << endl;
cout << "Name: " << name << endl;
cout << "Employee ID: " << empId << endl;
cout << "Gender: " << gender << endl
<< endl;
int main()
{
deptInfo objD;
objD.getDeptInfo();
objD.printDeptInfo();
loanInfo objL;
objL.getLoanInfo();
objL.printLoanInfo();
return 0;
}
OUTPUT
QUESTION 5
CODE
#include <iostream>
class Fruit
{
public:
Fruit()
fruitCounter++;
~Fruit()
fruitCounter--;
};
public:
applesCounter++;
~Apples()
applesCounter--;
};
public:
Mangoes():Fruit()
{
mangoesCounter++;
~Mangoes()
mangoesCounter--;
};
int Fruit::fruitCounter = 0;
int Apples::applesCounter = 0;
int Mangoes::mangoesCounter = 0;
int main()
Apples firstApple,secondApple,thirdApple;
Mangoes firstMango,secondMango,thirdMango,fourthMango;
cout << "Total number of fruits: " << Fruit::fruitCounter << endl;
return 0;
}
OUTPUT
QUESTION 6
#include <iostream>
#include <cmath>
class Marks {
public:
int rollNumber;
char *name;
int *marks; // array of marks
int sum_of_marks() {
int sum = 0;
return sum;
}
double avarage() {
return round(((double)sum_of_marks() / num_marks) * 100) / 100;
}
delete[]marks;
~Marks() {
delete[]marks;
}
};
};
};
class Mathematics : public Marks {
public:
};
int main()
{
int num;
for (int i = 0; i < num; i++) { // Generate marks and roll numbers
cl1_phys[i].GenerateMarks(9);
cl1_chem[i].GenerateMarks(5);
cl1_math[i].GenerateMarks(2);
}
cout << "\nThe total marks of each student of a class in Physics, Chemistry and
Mathematics: \n\n";
for (int i = 0; i < num; i++) { // sums of marks
cout << "Roll number of student is " << cl1_phys[i].rollNumber << endl;
cout << "The total marks in Physics is " << cl1_phys[i].sum_of_marks() <<
endl;
cout << "The total marks in Chemistry is " << cl1_chem[i].sum_of_marks()
<< endl;
cout << "The total marks in Mathematics is " << cl1_math[i].sum_of_marks()
<< endl;
cout << "The average mark in Physics is " << cl1_phys[i].avarage() << endl;
cout << "The average mark in Chemistry is " << cl1_chem[i].avarage() <<
endl;
cout << "The average mark in Mathematics is " << cl1_math[i].avarage() <<
endl;
return 0;
}
OUTPUT
QUESTION 7
CODE
#include<iostream>
using namespace std;
class Circle
{
protected:
float radius ;
public:
void Enter_r(void)
{
cout << "\n\t Enter the radius: "; cin >> radius ;
}
void Display_ca(void)
{
cout << "\t The area = " << (22/7 * radius*radius) ;
}
};
class Rectangle
{
protected:
float length, breadth ;
public:
void Enter_lb(void)
{
cout << "\t Enter the length : "; cin >> length ;
cout << "\t Enter the breadth : "; cin >> breadth ;
}
void Display_ar(void)
{
cout << "\t The area = " << (length * breadth);
}
};
int main()
{
Circle c ;
cout << "\n Getting the radius of the circle\n" ;
c.Enter_r( );
c.Display_ca( );
Rectangle r ;
cout << "\n\n Getting the length and breadth of the rectangle\n\n";
r.Enter_lb( );
r.Display_ar( );
Cylinder cy ;
cout << "\n\n Getting the height and radius of the cylinder\n";
cy.Enter_r( );
cy.Enter_lb( );
cy.volume_cy( );
return 0;
}
OUTPUT
QUESTION 8
CODE
#include <iostream>
using namespace std;
class Base {
private:
int pvt = 1;
protected:
int prot = 2;
public:
int pub = 3;
int main() {
PublicDerived object1;
cout << "Private = " << object1.getPVT() << endl;
cout << "Protected = " << object1.getProt() << endl;
cout << "Public = " << object1.pub << endl;
return 0;
}
OUTPUT
QUESTION 9
CODE
#include <iostream>
class A{
private:
int a;
protected:
int p;
public:
void get_a(int a){
this->a=a;
}
void put_a(){
cout<<"a="<<a<<endl;
}
};
class B: public A{
private:
int b;
public:
void get_b(int b){
this->b=b;
}
void get_p(int p){
this->p=p;
}
void put_b(){
cout<<"b="<<b<<endl;
}
void put_p(){
cout<<"p="<<p<<endl;
}
};
int main(){
B objB;
objB.get_a(10);
objB.get_b(20);
objB.get_p(30);
objB.put_a();
objB.put_b();
objB.put_p();
return 0;
}
OUTPUT
QUESTION 10
CODE
#include<iostream>
#include<stdio.h>
void input()
{
getdata();
cout<<"\n enter the marks1: ";
cin>>sub1;
cout<<"\n enter the marks2: ";
cin>>sub2;
cout<<"\n enter the marks3: ";
cin>>sub3;
}
void output()
{
putdata();
cout<<"\n marks1: "<<sub1;
cout<<"\n marks2: "<<sub2;
cout<<"\n marks3: "<<sub3<<"\n";
}
void calculate ()
{
per= (sub1+sub2+sub3)/3;
cout<<"\n total percentage :: "<<per<<"\n";
}
};
int main()
{
marks m1;
int ch;
int count=0;
do
{
cout<<"\n1.input data";
cout<<"\n2.output data";
cout<<"\n3.Calculate percentage";
cout<<"\n4.exit\n";
cout<<"\nEnter the choice :: ";
cin>>ch;
switch (ch)
{
case 1:
m1.input();
count++;
break;
case 2:
m1.output();
break;
case 3:
m1.calculate();
break;
}
} while (ch!=4);
}
OUTPUT