Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. Create a class Student with data members regno, name and age. Student class contains two member fimctions (do nothing functions) named get data() and put data() The clus Arts and Science has been derived from Class Student Class Arts has the data members ml.m2.m3,avg and get data() function to get the details of arts student(inherits the dilla members from class Student) and put data() function to display the details. Class Science has the data members ml.m2,m3.avg and get data() function to get the details of Science students inherits the data members from Student) and put data() function to display the details Science student. Compare the aveage of Arts student and Science student averages and display the greater one on screen. "Note: Class Student must be an abstract class.

What I have tried:

#include<iostream>

using namespace std;
class student{
public:
string regno;
string name;
int age;
virtual void getdata()=0;
virtual void putdata()=0;
};

class arts:public student{
public:
float m1,m2,m3,avg;
void getdata(){
cin>>regno>>name>>age>>m1>>m2>>m3;
avg=(m1+m2+m3)/3.00;
}
void putdata(){
cout << regno<<endl;
cout="" <<="" name<<endl;
="" age<<endl;
="" m1<<endl;
="" m2<<endl;
="" m3<<endl;
="" avg<<endl;
="" }
};

class="" science="" :public="" student{
="" public:
="" float="" p1,p2,p3;
="" void="" getdata(){
="" cin="">>regno>>name>>age>>p1>>p2>>p3;
avg=(p1+p2+p3)/3.00;
}
void putdata(){
cout << regno<<endl;
cout="" <<="" name<<endl;
="" age<<endl;
="" p1<<endl;
="" p2<<endl;
="" p3<<endl;
="" cout<<avg<<endl;
="" }
=""
};

int="" main()="" {
="" arts="" o1;
="" science="" o2;
="" o1.getdata();
="" o2.getdata();
="" o1.putdata();
="" o2.putdata();
="" if(o1.avg=""> o2.avg)
cout<
Posted
Updated 17-Jun-21 9:00am
Comments
CPallini 17-Jun-21 7:52am    
Do your code work?
If not, please report the exact error message(s).
Tia _____ 17-Jun-21 8:37am    
my programme isnt taking input after regno and name and printing garbage value
(pasted below)
-------------------------------------------------
20bce2596

saumya

20

bce2596
0
0

5.885040-39

e

1.96168e-39

16
0
0




2.54408e-29
0
8.48827e-38
8.48827e-30
Patrice T 17-Jun-21 15:16pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Tia _____ 18-Jun-21 14:35pm    
hey i am new to this platform . thank you for telling me . will do so :)
OriginalGriff 17-Jun-21 8:13am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

C++
void putdata(){
cout << regno<<endl;
cout << name<<endl;
 age<<endl; // this and the following three lines do nothing.
 p1<<endl;
 p2<<endl;
 p3<<endl;
 cout<<avg<<endl;
 }

In fact that code should not even compile.
 
Share this answer
 
Comments
Tia _____ 18-Jun-21 14:30pm    
actually i printed all the outputs in one line like cout<
Your biggest mistake is not toe Learn C++ and understand the details of your task. The next is to read the assigment like the fineprint.
You need to implement each detail one after the other and so find the solution.

tip: make more output and less input amd print calculation details

C++
"Enter m1: " >> cout;
cin >> m1;

ps: the student class must be abstract
 
Share this answer
 
Comments
Richard MacCutchan 17-Jun-21 16:26pm    
"Enter m1: " >> cout; : wrong way round I think.
Tia _____ 18-Jun-21 14:33pm    
how should i declare an abstract class. as per my knowledge , an abstract class compulsorily has atleast a pure virtual function . i have declared putdata() and getdata() as pure virtual functions . how else can i declare them . thank u for your help :)
Read your assignment again: you have completely missed most of the details.

For example, does the Student class exist? (Hint: no.)
If it does exist, is it abstract? Why not?

That looks like you grabbed some code from the internet in the hope it might do what you need to hand in - and it won't. Not even close.
I'd throw the lot away, and start again ...
 
Share this answer
 
v2
Comments
Tia _____ 18-Jun-21 14:27pm    
as my tutor taught me an abstract class must have a virtual function . the functions get data and putdata() in the student class are pure virtual function .
and this was the question asked in my test and i tried solving it , i got it wrong in the exam so seeked for help . ig for such basic problems the internet would be the best place to find correct answer . lol! how should i declare abstract class , if not this way ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900