Click here to Skip to main content
13,560,066 members
Rate this:
 
Please Sign up or sign in to vote.
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();
}
Posted 12-Oct-11 19:22pm
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.
User-12072167 9-Jul-16 2:54am
   
Wrong object create...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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".
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

#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();
}
  Permalink  
Comments
jeron1 17-Oct-16 12:44pm
   
Hopefully they have figured it out in the last 5 years.
NotPolitcallyCorrect 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.
ShivaSingh 17-Oct-16 14:26pm
   
hmm but i updated the code there were some errors and code was not complete. :-)
NotPolitcallyCorrect 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.
ShivaSingh 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.180527.3 | Last Updated 17 Oct 2016
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100