Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
#include<iostream.h>
#include<conio.h>

class student
{
	public:
	int rno;
	//float per;
	char name[20];
	void getdata()
	{
		cout<<"Enter RollNo :- \t";
		cin>>rno;
		cout<<"Enter Name :- \t";
		cin>>name;
		
	}
	
};
class marks : public student
{
public:
	int m1,m2,m3,tot;
	float per;
	void getmarks()
	{
		getdata();
		cout<<"Enter Marks 1 :- \t";
		cin>>m1;
		cout<<"Enter Marks 2 :- \t";
		cin>>m2;
		cout<<"Enter Marks 2 :- \t";
		cin>>m3;
	}
	void display()
	{
		getmarks();
		cout<<"Roll Not \t Name \t Marks1 \t marks2 \t Marks3 \t Total \t Percentage";
		cout<<rno<<"\t"<<name<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<tot<<"\t"<<per;
	}
};
void main()
{
	student std;
	clrscr();
	std.getmarks();
	std.display();
	getch();
}
C++

Posted
Updated 17-Oct-16 5:52am
Comments
Mohibur Rashid 13-Oct-11 1:25am    
and what is your problem then??

you defined std variable?
a namespace has been defined name std. It must conflict.
Richard MacCutchan 13-Oct-11 6:18am    
A variable name will not conflict with a namespace name.
Philippe Mori 13-Oct-11 8:19am    
It doesn't make any sense to derive marks from student (marks are not a student). Thus the whole question is meaningless and don't worth any point.
Member 12105626 9-Jul-16 2:54am    
Wrong object create...

No, that won't work:
You have declared std as a member of the student class, not a marks class. So it does not have access to the getmarks or display methods.
Try changing the definition to be a member of the marks class - it will then have all the members of marks, plus all the members of student.

What you have done is a bit like saying "A physics textboook is a book, so any book must contain information about my physics course".
 
Share this answer
 
C++
#include<iostream.h>
#include<conio.h>

class student
{
	public:
	int rno;
	//float per;
	char name[20];
	void getdata()
	{
		cout<<"Enter RollNo :- \t";
		cin>>rno;
		cout<<"Enter Name :- \t";
		cin>>name;
		
	}
	
};
class marks : public student
{
public:
	int m1,m2,m3,tot;
	float per;
	void getmarks()
	{
		getdata();
		cout<<"Enter Marks 1 :- \t";
		cin>>m1;
		cout<<"Enter Marks 2 :- \t";
		cin>>m2;
		cout<<"Enter Marks 2 :- \t";
		cin>>m3;
                              tot=m1+m2+m3;
                              per=tot/3;
	}
	void display()
	{
		
		cout<<"Roll Not \t Name \t Marks1 \t marks2 \t Marks3 \t Total \t Percentage";
		cout<<rno<<"\t"<<name<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<tot<<"\t"<<per;
	}
};
void main()
{
	marks m;
	clrscr();
	m.getmarks();
	m.display();
	getch();
}
 
Share this answer
 
Comments
jeron1 17-Oct-16 12:44pm    
Hopefully they have figured it out in the last 5 years.
[no name] 17-Oct-16 13:01pm    
And, despite what you think, it is not at all helpful to do someone else's homework assignments for them. The only thing that they will learn is that someone will do their work for them.
Shiva Singh 17-Oct-16 14:26pm    
hmm but i updated the code there were some errors and code was not complete. :-)
[no name] 18-Oct-16 6:06am    
hmm.... but it doesn't matter. His homework assignment was due a long time ago and those internet points are really worthless.
Shiva Singh 18-Oct-16 9:43am    
Oh ok.

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