Â
The Code given below can be used in TURBO C++ Compilers: -
#include<iostream.h>
#include<conio.h>
// base class
class Physics
{
public:
int phy;
float p;
void getPhyPercent()
{
cout << "Enter Student's phy marks out of 80: ";
cin >> phy;
p = (float)phy / 80 * 100;
}
};
// base class
class Chemistry
{
public:
int chem;
float c;
void getChemPercent()
{
cout << "Enter Student's Chemistry marks out of 80: ";
cin >> chem;
c = (float)chem / 80 * 100;
}
};
// base class 3
class Maths
{
public:
int maths;
float m;
void getMathsPercent()
{
cout << "Enter Student's Maths marks out of 80: ";
cin >> maths;
m = (float)maths / 80 * 100;
}
};
// first sub class
class AggregatePercent : public Physics, public Chemistry, public Maths
{
public:
float agg;
void getAgg()
{
agg = p + c + m;
agg /= 3;
}
};
// second sub class
class Percents : public AggregatePercent
{
public:
void printPercents()
{
cout << "Physics Percentage = " << p << "\n";
cout << "Chemistry Percentage = " << c << "\n";
cout << "Maths Percentage = " << m << "\n";
cout << "Aggregate Percentage = " << agg << "\n";
}
};
// main function
void main()
{
clrscr();
Percents obj;
int stuId;
char stuName[25];
cout << "Enter student details: \n";
cout << "Enter Student ID: ";
cin >> stuId;
cout << "Enter Student Name: ";
cin >> stuName;
obj.getPhyPercent();
obj.getChemPercent();
obj.getMathsPercent();
obj.getAgg();
obj.printPercents();
getch();
}
//.......Coded by SHREYA IDATE
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
// base class
class Physics
{
public:
int phy, from = 80;
float p;
void getPhyPercent()
{
cout << "Enter Student's phy marks out of 80: ";
cin >> phy;
p = (float)phy / from * 100;
}
};
// base class
class Chemistry
{
public:
int chem, from = 80;
float c;
void getChemPercent()
{
cout << "Enter Student's Chemistry marks out of 80: ";
cin >> chem;
c = (float)chem / from * 100;
}
};
// base class 3
class Maths
{
public:
int maths, from = 80;
float m;
void getMathsPercent()
{
cout << "Enter Student's Maths marks out of 80: ";
cin >> maths;
m = (float)maths / from * 100;
}
};
// first sub class
class AggregatePercent : public Physics, public Chemistry, public Maths
{
public:
float agg;
void getAgg()
{
agg = p + c + m;
agg /= 3;
}
};
// second sub class
class Percents : public AggregatePercent
{
public:
void printPercents()
{
cout << "Physics Percentage = " << p << "\n";
cout << "Chemistry Percentage = " << c << "\n";
cout << "Maths Percentage = " << m << "\n";
cout << "Aggregate Percentage = " << agg << "\n";
}
};
// main function
int main()
{
Percents obj;
int stuId;
char stuName[25];
cout << "Enter student details: \n";
cout << "Enter Student ID: ";
cin >> stuId;
cout << "Enter Student Name: ";
cin >> stuName;
obj.getPhyPercent();
obj.getChemPercent();
obj.getMathsPercent();
obj.getAgg();
obj.printPercents();
return 0;
}
//.......Coded by SHREYA IDATE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP