| | |
Please Help Me abuot C++ Problem :icon_question:
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 16
Reputation:
Solved Threads: 0
Question is:
"Implement a Person class that includes data members to represent name, address, and identification number. The class interface includes methods that provide appropriate access to the data members. Derive a CollegeStudent class and a Professor class from Person. Each of these derived classes should add appropriate data members and methods. Implemente a test client to test the hierarchy. Propose classes to derive from CollegeStudent and Professor. What data members and methods might these derived classes add?"
Does anyone write these program tahnks for your attention...
"Implement a Person class that includes data members to represent name, address, and identification number. The class interface includes methods that provide appropriate access to the data members. Derive a CollegeStudent class and a Professor class from Person. Each of these derived classes should add appropriate data members and methods. Implemente a test client to test the hierarchy. Propose classes to derive from CollegeStudent and Professor. What data members and methods might these derived classes add?"
Does anyone write these program tahnks for your attention...
•
•
Join Date: May 2008
Posts: 87
Reputation:
Solved Threads: 8
Ummmm what specifically are you having difficulty with? It is pretty much straightforward OOP...classes and inheritance...
If you haven't learned the subject, thats another issue entirely, in which case I would suggest doing a google search on C++ classes and inheritance, and then posting back here with more specific issues...
If you haven't learned the subject, thats another issue entirely, in which case I would suggest doing a google search on C++ classes and inheritance, and then posting back here with more specific issues...
•
•
Join Date: May 2008
Posts: 87
Reputation:
Solved Threads: 8
I would assume a test client is simply a driver that tests the various levels of your program...i.e. creating a driver to test the different classes....
And you could propose tons of classes to be derived from CollegeStudent and Professor....there are pretty much no bounds, for example:
You could derive GraduateStudent and UndergraduateStudent from CollegeStudent, which encapsulate the years as a student, years left in the program, program itself, any previous schools attended, current school, etc etc.
You could derive various departments from the professor class, for example MathProfessor derived from Professor, which implements the subjects taught, years as a math prof, tenure, schools taught at, faculty association, etc etc.
Of course, some of these members might already be implemented in the Professor or CollegeStudent class, so you would instead make more specific members...
Really you could go on forever...basically deriving classes as they meet your needs. Essentially, deriving classes allows you to inherit certain properties (from the Person, Professor/CollegeStudent or other base classes), and expand upon others (by adding specifics in the new classes)...
hopefully that helps?
And you could propose tons of classes to be derived from CollegeStudent and Professor....there are pretty much no bounds, for example:
You could derive GraduateStudent and UndergraduateStudent from CollegeStudent, which encapsulate the years as a student, years left in the program, program itself, any previous schools attended, current school, etc etc.
You could derive various departments from the professor class, for example MathProfessor derived from Professor, which implements the subjects taught, years as a math prof, tenure, schools taught at, faculty association, etc etc.
Of course, some of these members might already be implemented in the Professor or CollegeStudent class, so you would instead make more specific members...
Really you could go on forever...basically deriving classes as they meet your needs. Essentially, deriving classes allows you to inherit certain properties (from the Person, Professor/CollegeStudent or other base classes), and expand upon others (by adding specifics in the new classes)...
hopefully that helps?
Last edited by n1337; May 14th, 2008 at 6:51 pm.
•
•
Join Date: May 2008
Posts: 16
Reputation:
Solved Threads: 0
might it be like this?
it has error so much but i cant analyze it
#include <iostream>
using namespace std;
class Person{
char name,adress;
int id_num;
public:
Person();
void goster();
};
Person::goster()
{
cout<<"Name="<<name<<endl;
cout<<"Address="<<address<<endl;
cout<<"ID Number="<<id_num<<endl;
}
class CollegeStudent:public Person{
public:
char nameofclass
void goster2();
};
CollegeStudent::goster2();
{
cout<<"Name of Class"<<namepfclass<<endl;
}
class Professor:public Person{
public:
char dept_of_prof
void goster3();
};
Professor::goster3();
{
cout<<"Department of Profession"<<dept_of_prof<<endl;
}
int main(){
int test;
Person p1;
Professor p2;
CollegeStudent p3;
cout<<"if you Professor press 1 and College Student press 2"<<endl;
cin>>test;
if(test==1)
{
p2.goster3;
}
if(test==2)
{
p3.goster2;
}
return 0;
}
it has error so much but i cant analyze it
#include <iostream>
using namespace std;
class Person{
char name,adress;
int id_num;
public:
Person();
void goster();
};
Person::goster()
{
cout<<"Name="<<name<<endl;
cout<<"Address="<<address<<endl;
cout<<"ID Number="<<id_num<<endl;
}
class CollegeStudent:public Person{
public:
char nameofclass
void goster2();
};
CollegeStudent::goster2();
{
cout<<"Name of Class"<<namepfclass<<endl;
}
class Professor:public Person{
public:
char dept_of_prof
void goster3();
};
Professor::goster3();
{
cout<<"Department of Profession"<<dept_of_prof<<endl;
}
int main(){
int test;
Person p1;
Professor p2;
CollegeStudent p3;
cout<<"if you Professor press 1 and College Student press 2"<<endl;
cin>>test;
if(test==1)
{
p2.goster3;
}
if(test==2)
{
p3.goster2;
}
return 0;
}
•
•
•
•
might it be like this?
it has error so much but i cant analyze it
And always use code-tags when posting code
But nevertheless it may give the OP an idea on how to start.
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
Just pointing out some very simple errors you have there ...
Don't get overwhelmed by the amount of errors/warnings the compiler produces. Instead, start from the top, working out one error at a time and recompile. Eventually your code compiles ... and you learn the various error codes and their meaning along the way. If you have documentation on your compiler's error codes - refer to that documentation.
class CollegeStudent:public Person
{
public:
char nameofclass ;// need a semicolon here
void goster2();
};
CollegeStudent::goster2() // ; <- must not have a semicolon there
{
cout<<"Name of Class"<<nameofclass<<endl; // A typo there, typos are fatal
}
...
if(test==1)
{
p2.goster3(); // () needed to make a call to the function
}•
•
•
•
it has error so much but i cant analyze it
Last edited by mitrmkar; May 15th, 2008 at 7:50 am.
At mertucci:
I apologize, I didn't realize you were the original poster.
To make up for my rudeness, I've modded your code, so that it compiles.
I'm not saying it is done yet (I'm not even saying it's great code), you need to add a lot more, but this should get you started:
I apologize, I didn't realize you were the original poster.
To make up for my rudeness, I've modded your code, so that it compiles.
I'm not saying it is done yet (I'm not even saying it's great code), you need to add a lot more, but this should get you started:
cpp Syntax (Toggle Plain Text)
#include <string> #include <iostream> using namespace std; class Person{ std::string name,address ; int id_num; public: Person() { name = "blank"; address= "none yet"; id_num=0; }; void goster(){ cout<<"Name="<<name<<endl; cout<<"Address="<<address<<endl; cout<<"ID Number="<<id_num<<endl;}; }; class CollegeStudent:public Person{ public: char nameofclass; CollegeStudent() { nameofclass = 'c'; } void goster2() { cout<<"Name of Class: "<<nameofclass<<endl; } }; class Professor:public Person{ public: char dept_of_prof; Professor() { dept_of_prof = '0'; } void goster3() { cout<<"Department of Profession: "<<dept_of_prof<<endl;} ; }; int main(){ int test; Person p1; Professor p2; CollegeStudent p3; cout<<"if you Professor press 1 and College Student press 2"<<endl; cin>>test; if(test==1) { p2.goster3(); } if(test==2) { p3.goster2(); } cin.ignore(); cin.get(); return 0; }
Last edited by niek_e; May 15th, 2008 at 8:06 am.
![]() |
Other Threads in the C++ Forum
- Previous Thread: stack of stack....
- Next Thread: Dynamic class help
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






