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
#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;
}
Comments
Leave a comment