create a student class to store 3 subject marks .Overload the display() function to 1. Display total using 3 subject marks 2. Display average using the total.
#include <iostream>
using namespace std;
//class definition
class Student
{
private:
int a;
int b;
int c;
int average;
public:
//member function declaration
void readMarks(void);
void printMarks(void);
int display(void);
};
//member function definitions
void Marks::readMarks(void)
{
cout<<"Enter first mark: ";
cin>>a;
cout<<"Enter second mark: ";
cin>>b;
cout<<"Enter third mark: ";
cin>>c;
}
void Marks::printMarks(void)
{
cout<<"Mark One= "<<a<<",Mark Two = "<<b<<" Mark Three"<<c<<endl;
}
int Marks::display(void)
{
sum = (a+b+c);
return sum;
}
int Marks::display(void)
{
average = sum/3;
return average;
}
//main function
int main()
{
//declaring object
Student s1;
int add, average; //variable to store addition
//take input
s1.readMarks();
//find addition
add=num.display();
//find average
average=sum/3;
//print numbers
s1.printMarks();
//print addition
cout<<"Addition/sum= "<<sum<<endl;
court<<" Average "<<average<<end1;
return 0;
}
Comments
Leave a comment