saving . . . saved Question about assignment given. has been deleted. Question about assignment given. has been hidden .
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 08-05-20, 3:36 a.m. vaibhavpherwani@gmail.com

Answers:

Please provide your code here. We will be happy to help.
13-05-20, 1:51 p.m. nags
#include<iostream.h>
class student
protected:
int rno;
cha name[20];
int sub1,sub2,sub3;
int sportm;
int totalm;
virtual void info()=0;
};
class marks:public student
{
public:
void info()
{cout<<"Name:";
cin>>name;
cout<<"Roll no:";
cin>>rno;
}
void input()
{cout<<"Marks of sub1: ";
cin>>sub1;
cout<<"Marks of sub2:";
cin>>sub2;
cout<<"Marks of sub3:";
cin>>sub3;
totalm=sub1+sub2+sub3;
}
void display()
{cout<<"Name:"<<name;
cout<<"roll no:"<<rno;
cout<<"Total marks:"<<totalm<<endl;
}
};
class sports:public student
{
public:
void info(){
cout<<"Sports:"<<endl;
}
void input_sport()
{cout<<"Sports marks:";
cin>>sportm;
}
};
class result:public marks,public sports
{int totals;
public:
void show();
void calc();
};
void result::show()
{cout<<"name:"<<marks::name<<endl;
cout<<"Roll no.:"<<marks::rno<<endl;
}
void result::calc()
{
totals=marks::totalm+sports::sportm;
cout<<"Total marks:"<<totals<<endl;
}
int main()
{
marks m; 
sports s;
result r;

m.info();
m.input();
m.display();
s.info();
s.input_sport();
r.show();
r.calc();
return 0;
}
In here derived class result shows incorrect results.
Hope i will get a solution for my problem soon.
Thanking you.

13-05-20, 6:49 p.m. vaibhavpherwani@gmail.com
#include<iostream>
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;
}

I'm able to enter the inputs without any errors. But my code is not able to display the name, roll.no and total marks. Can anyone please correct my code ?
18-01-22, 5:25 p.m. jayasai.surya2019@vitstudent.ac.in

Login to add comment



13-05-20, 6:48 p.m. vaibhavpherwani@gmail.com


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();)

27-05-20, 9:48 p.m. nags


Log-in to answer to this question.