Use the code : Miru2021
If you are having any problem regarding the output or evaluation in Elab, Then check your code here.
Table of Content
[CODE SOURCE : GOOGLE]
Tap on the image



Use the code: Miru2021
Examination
#include
using namespace std;
class A{
public:
int x;
};
class B:public A{
public:
B()
{
cin >> x;
}
};
class C{
public:
int y;
C(){
cin >> y;
}
};
class D:public B,public C
{
public:
void sum()
{
int sum;
sum=x+y;
cout << "Sum= " << sum << endl;
}
};
int main() {
D obj;
obj.sum();
return 0;
}
Multilevel Inheritance for Student Marklist
#include <iostream>
#include<string.h>
using namespace std;
class student
{
public:
Use the code: Miru2021
char fname[20],lname[20];
int phno;
void getdata()
{
cin>>fname;
cin>>lname;
cin>>phno;
}
void display()
{
cout<<"First Name: "<<fname<<endl;
cout<<"Last Name: "<<lname<<endl;
cout<<"Phone: "<<phno<<endl;
}
};
class grade:public student
{
public:
char g[5];
int score;
grade()
{
strcpy(g,"0");
score=0;
}
void calculate()
{cin>>score;
if (score <40)
strcpy(g,"D");
else if(score>=40 && score<60)
strcpy(g,"B");
else if(score>=60 && score<75)
strcpy(g,"A");
else if(score>=75 && score<90)
strcpy(g,"E");
else
strcpy(g,"O");
}
void disp()
{
cout<<"Grade: "<<g<<endl;
}
};
int main() {
grade o;
o.getdata();
o.display();
o.calculate();
o.disp();
return 0;
}
Use the code : Miru2021
Payroll
#include<iostream>
using namespace std;
class SingleInheritance{
public:
string name, gender;
int salary, age;
void getDetails(){
cin >> name >> gender >> age >> salary;
}
};
class inheritedclass:public SingleInheritance{
public:
void display(){
cout << "Name=" << name << "\nGender=" << gender << "\nAge=" << age << "\nSalary=" << salary << endl;
}
};
int main() {
inheritedclass tc;
tc.getDetails();
tc.display();
return 0;
}
Counselling
#include <iostream>
using namespace std;
class Student{
public:
virtual void getDetails()=0;
virtual void displayDetails()=0;
};
class StudentDetails:public Student{
string fname, mname;
float num;
public:
void getDetails(){
cin >> fname >> mname >> num;
}
void displayDetails(){
cout << fname << endl << mname << endl << num << endl;
}
};
int main() {
StudentDetails sd;
sd.getDetails();
sd.displayDetails();
return 0;
}
Use the code: Miru2021
Rectangle
#include<iostream>
using namespace std;
class Area
{
public:
int getArea(int length, int berth)
{
return length*berth;
}
};
class Perimeter
{
public:
int getPerimeter(int length, int berth)
{
return length+length+berth+berth;
}
};
class Rectangle:public Area,public Perimeter
{
};
int main() {
Rectangle rt;
int l,b;
cin>>l>>b;
cout<<rt.getArea(l,b)<<endl;
cout<<rt.getPerimeter(l,b)<<endl;
return 0;
}
Student and Sports
using namespace std;
class student
{
public:
int roll_no,mark_1,mark_2;
void get()
{
cin>>roll_no;
cin>>mark_1;
cin>>mark_2;
}
};
class sports
{public:
int sport_mark;
void getsm()
{
cin>>sport_mark;
}
};
class statement:public student,public sports
{
public:
int total,average;
void display()
{
total=mark_1+mark_2+sport_mark;
average=(mark_1+mark_2+sport_mark)/3;
cout<<roll_no<<endl;
cout<<total<<endl;
cout<<average;
}
};
int main()
{
statement obj;
obj.get();
obj.getsm();
obj.display();
return 0;
}
Single Level Inheritance – Rectangle
using namespace std;
class A
{
public:
int a;
void getxval()
{
cin>>a;
}
};
class B
{
public:
int b;
void getyval()
{cin>>b;
}
};
class C:public A,public B
{
int c;
public:
void sum()
{
c=a+b;
cout<<"Sum = "<<c;
}
void mul()
{
c=a*b;
cout<<"\nProduct="<<c;
}
};
int main()
{
C obj;
obj.getxval();
obj.getyval();
obj.sum();
obj.mul();
return 0;
}
Square and cube
using namespace std;
class Number
{
public:
int n;
void getNumber()
{
cin>>n;
}
void getSquare()
{
cout<<n*n<<endl;
}
void getCube()
{
cout<<n*n*n<<endl;
}
};
class Square:public Number
{
public:
Square()
{
getNumber();
getSquare();
}
};
class Cube:public Number
{
public:
Cube()
{
getNumber();
getCube();
}
};
int main()
{
Square objS;
Cube objC;
return 0;
}
Cost of Pen
#include<iostream>
using namespace std;
class A
{
public:
int pen;
void display()
{
cin>>pen;
}
};
class B
{
public:
int price;
void display()
{
cin>>price;
}
};
class C:public A,public B
{
public:
void display()
{
A::display();
B::display();
cout<<pen*price;
}
};
int main()
{
C sample;
sample.display();
return 0;
}
Programmer Information
#include <iostream>
using namespace std;
class person
{
public:
int age;
char name[20];
char gender[10];
void getdata()
{
cin>>name;
cin>>age;
cin>>gender;
}
void display()
{
cout<<"Name: "<<name<<endl;
cout<<"Age: "<<age<<endl;
cout<<"Gender: "<<gender<<endl;
}
};
class employee: public person
{
public:
char n[10];
int salary;
void getdata()
{
cin>>n;
cin>>salary;
Use the code : Miru2021
}
void display()
{
cout<<"Name of Company: "<<n<<endl;
cout<<"Salary: Rs."<<salary<<endl;
}
};
class programmer: public employee
{
public:
int pl;
void getdata()
{
cin>>pl;
}
void display()
{
cout<<"Number of programming language known: "<<pl<<endl;
}
};
int main()
{
person obj1;
employee obj2;
programmer obj3;
obj1.getdata();
obj1.display();
obj2.getdata();
obj2.display();
obj3.getdata();
obj3.display();
return 0;
}
Percentage of Student
using namespace std;
class AddData
{
public:
int mark1,mark2;
void accept_details()
{
cin>>mark1>>mark2;
}
};
class sports
{
public:
int mark3;
void get()
{
cin>>mark3;
}
};
class Total : public AddData,public sports
{
public:
int d;
void total_of_three_subjects()
{
d=(mark1+mark2+mark3)/3;
}
};
class Percentage : public Total
{
public:
int e;
void calculate_percentage()
{
e=(mark1+mark2+mark3)/3;
}
void show_result()
{
cout<<e;
}
};
int main()
{
Percentage p;
p.accept_details();
p.get();
p.total_of_three_subjects();
p.calculate_percentage();
p.show_result();
return 0;
}
Use the code : Miru2021
Bio
#include <iostream>
using namespace std;
class student
{
public:
int rollnumber, mark1, mark2;
void getdet1()
{
cin>>rollnumber;
cin>>mark1>>mark2;
}
};
class sports
{
public:
int mark3;
void getdet2()
{
cin >> mark3;
}
};
class statement:public student,public sports
{
public:
void display()
{
cout << "Roll No:" << rollnumber << endl;
cout << "Total:" << (mark1 + mark2 + mark3) << endl;
cout << "Average:" << ((mark1 + mark2 + mark3) / 3) << endl;
}



Use the code: Miru2021
Interface for Rectangle
#include <iostream>
#include <iomanip>
using namespace std;
class Area
{
public:
float getArea(float l,float h);
};
float Area::getArea(float l,float h)
{
return l*h;
}
class Perimeter
{
public:
float getPerimeter(float x,float y)
{
return (float)2*(x+y);
}
};
class Rectangle:public Area,public Perimeter
{
};
int main() {
float l,b;
Rectangle rt;
cin>>l>>b;
cout<<rt.getArea(l,b)<<endl;
cout<< std::fixed << setprecision(2) << rt.getPerimeter(l,b);
return 0;
}
Use the code: Miru2021