I have to debut this program, I almost got it to work, but when it runs, it hangs after it displays per.showperson(). Please help. Thanks.
//DEBUG10-1
//This program demonstrates inheritance
//A Student class is derviced from a Person class
#include<iostream>
#include<string>
using namespace std;
class Person
{
private:
int idNum;
int age;
public:
char initial;
void setData(int, int, char);
void showPerson();
};
void Person::setData(int id, int years, char init)
{
idNum = id;
age = age;
init = init;
}
void Person::showPerson()
{
cout<<"Person ID# "<<idNum<<" Age: "<<age<<
" Initial:"<<initial;
}
class Student :: public Person
{
private
double gpa;
public:
void setData(int, int, char, double);
void showStudent();
};
void Student::setData(int id, int years, char init, double gradePoint)
{
Person::setDeta(id, years);
gpa = grdePoint;
}
void Student::showStudent()
{
cout<<"Student ID #"<<idNum;
cout<<" Avg: "<<gpa<<endl;
showPerson();
cout<<endl<<" Age: "<<age<<".";
cout<<" Initial: "<<initial<<endl;
}
int main()
{
Person per;
per.setData(387, 23, 'A');
cout<<endl<<"Person..."<<endl;
per.showPerson();
Student stu;
stu.setData(388, 18, 'B', 3.8);
cout<<endl<<endl<<"Student..."<<endl;
stu.showStudent();
}
1) You should use singe ':' when specify from who you inherut from
2) you forget ':' after private
3) You trying to access private function Person::setDeta() and private members Person::idNum and Person::age
4) You made a typo "grdePoints"
5) You didn't read error messages