| | |
Inheritance Class ...... help needed asap
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 41
Reputation:
Solved Threads: 0
Well it is an assignment question here is the question :
Implement a base class Person. Derive classes Student and Instructor from Person. A person has
a name and a birthday. A student has a major, and an instructor has a salary. Write the class
definitions, the constructors, and the member functions print() for all classes.
this is what i have got so far any kind of help will be good :
Well i have managed to get the base class person but it gives error can someone help me out with whats wrong and how to implement the other required derived class student and instructor
Implement a base class Person. Derive classes Student and Instructor from Person. A person has
a name and a birthday. A student has a major, and an instructor has a salary. Write the class
definitions, the constructors, and the member functions print() for all classes.
this is what i have got so far any kind of help will be good :
c Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class Person{ public: Person( string nam, string day); string get_name()const; string get_date()const; void print()const; private: string name; string date; }; Person::Person( string nam,string day){ name= nam; date= day; } string Person::get_name() const { return name; } string Person::get_date() const { return date; } void Person:: print()const{ cout<<" Mr/Mrs."<<name<<" was born on "<<date<<"\n";} int main (){ string nam1; string dat1; cout<< " Please enter the name of student \n"; cin>>nam1; cout<< " Please enter the date of birth in the format dd/mm/yyyy \n"; cin>>dat1; Person(nam1,dat1); return 0; }
Well i have managed to get the base class person but it gives error can someone help me out with whats wrong and how to implement the other required derived class student and instructor
Last edited by Ancient Dragon; Apr 11th, 2007 at 8:45 am. Reason: correct code tags and reformat code so it can be read
First learn how to properly format your programs. I helped you out this time by doing it for you just so you can see how it should be done. There is absolutely nothing wrong with being generous with spaces and line feeds -- makes your program a lot easier to read.
>> it gives error
what error? I suspect it might be because you did not include <string> header file.
>>and how to implement the other required derived class student and instructor
here is how to declare Student. Other derived classes are the same format.
>> it gives error
what error? I suspect it might be because you did not include <string> header file.
>>and how to implement the other required derived class student and instructor
here is how to declare Student. Other derived classes are the same format.
C++ Syntax (Toggle Plain Text)
class Student : public Person { // your code here };
Last edited by Ancient Dragon; Apr 11th, 2007 at 8:50 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2007
Posts: 41
Reputation:
Solved Threads: 0
#include <iostream>
#include <string>
using namespace std;
class Person{
public:
Person( string nam, string day);
string get_name()const;
string get_date()const;
void print()const;
private:
string name;
string date;
};
Person:
erson( string nam,string day){
name= nam;
date= day;
}
string Person::get_name() const {return name;}
string Person::get_date() const {return date;}
void Person:: print()const{
cout<<" Mr/Mrs."<<name<<" was born on "<<date<<"\n";}
int main (){
string nam1;string dat1;
cout<< " Please enter the name of student \n";
cin>>nam1;
cout<< " Please enter the date of birth in the format dd/mm/yyyy \n";
cin>>dat1;
Person(nam1,dat1);
return 0;
}
Last edited by raj157; Apr 11th, 2007 at 12:43 pm.
I meant, do something like:
C++ Syntax (Toggle Plain Text)
Person obj(nam1, dat1); obj.print(); // call the member function print
I don't accept change; I don't deserve to live.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Memory Question
- Next Thread: transform char to integers
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






