Answer to Question #234292 in C++ for xyz

Question #234292

create a class student which store name roll no. age of the student. Derive a class test from student class which store marks of 5 subjects input and display the details of student


1
Expert's answer
2021-09-07T14:16:29-0400
#include <iostream>
#include <string>


using namespace std;




class Student
{
protected:
	string name;
	int rollno;
	int age;
public:
	void setData(string name,int rollno,int age){
		this->rollno = rollno;
		this->name = name;
		this->age = age;
	}
};


class Test: public Student
{
private:
	int marks[5];
public:
	void addmarks(int marks[]){ 
		for(int i=0;i<5;i++){
			this->marks[i] = marks[i];
		}
	}
	void generateReceipt()
	{
		
		cout<<"Name: "<<this->name<<"\n";
		cout<<"Roll No: "<<this->rollno<<"\n";
		cout<<"Age: "<<this->age<<"\n";
		cout<<"All marks:\n";
		for(int i=0;i<5;i++){
			cout<< this->marks[i]<<" ";
		}
		cout<<"\n\n";
	}
};


int main()
{
	Test Test;
	int marks[]={85,90,65,89,98};
	Test.setData("Mary Clark",055462256,25);
	Test.addmarks(marks);
	Test.generateReceipt();




	int pause;
	cin>>pause;
	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