Answer to Question #241427 in C++ for Laiba Noor

Question #241427
Write a class marks with three data members to store three marks. Write three member functions, set_marks() to input marks, sum() to calculate and return the sum and avg() to calculate and return average marks.
1
Expert's answer
2021-09-23T13:46:37-0400
#include<iostream>
using namespace std;


class marks{
private:
	int mark1;
	int mark2;
	int mark3;


public:
	void set_marks(){
		cout<<"Enter mark 1: ";
		cin>>mark1;
		cout<<"Enter mark 2: ";
		cin>>mark2;
		cout<<"Enter mark 3: ";
		cin>>mark3;
	}


	int sum(){
		return mark1+mark2+mark3;
	}


	float avg(){
		return (float)( sum())/3.0;
	}
};


int main() {
	int num;


	marks mark;
	mark.set_marks();
	cout<<"Sum: "<<mark.sum()<<"\n";
	cout<<"Avg: "<<mark.avg()<<"\n";


	cin>>num;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS