Question about assignment given.
Title
Question
I need a help with assignment given where i am unable to print and calculate the total marks of 3 subjects and marks of sports.And unable to print name and roll no.
So, it will be be helpful if you provide the code for the assignment problem or explain me the problem with my code.I can provide the code file or images of the code.
Hopefully i ll get the reply as soon as possible.
Advanced-Cpp Abstract-Class 04-05 min 30-40 sec
Answers:
Please provide your code here. We will be happy to help.
Your program is having the following issues:
1) syntax error char name[20];
2) class student needs to be inherited as virtual in class marks and class sports
3) In your code, you had instantiated 3 objects in the main class, i.e., marks, sports, and result. The marks that were entered using the marks and sports objects were two separate instances, and the result object was not able to access the correct one. The solution is to use the result object alone, and access using the scope resolution operator (example, r.marks::info();)
using namespace std;
class Student
{
public:
char name[30];
char rollno[30];
int s1,s2,s3,ss;
int total;
virtual void info() = 0;
};
class Marks:public Student
{
public:
void info()
{
cout<<"Enter Name - ";
cin>>name;
cout<<"Enter Roll number - ";
cin>>rollno;
cout<<"Enter the subject marks - "<<"\n";
cin>>s1;
cin>>s2;
cin>>s3;
}
};
class Sports:public Student
{
public:
void info()
{
cout<<"Enter sports weightage - ";
cin>>ss;
total = s1+s2+s3+ss;
}
};
class Result:public Student
{
public:
void info()
{
cout<<"Name of the Student = "<<name<<"\n";
cout<<"Roll number = "<<rollno<<"\n";
cout<<"Total Marks obtained = "<<total<<"\n";
}
};
int main()
{
Marks m;
Sports s;
Result r;
m.info();
s.info();
r.info();
return 0;
Login to add comment