Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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;
	}
	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
Comments
johny10151981 at 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 at 13-Oct-11 6:18am
   
A variable name will not conflict with a namespace name.
Philippe Mori at 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.

1 solution

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  

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



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 13 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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