Student Person class program c++

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<string>
using namespace std;
class Person
{

protected:

int idNum;
int age;
char initial;
public:

Person(int id, int years, char init);
void showPerson();
};

Person::Person(int id, int years, char init)
{
idNum = id;
age = years;
initial = init;
}
void Person::showPerson()
{
cout<<"Person ID# "<<idNum<<" Age: "<<age<<
" Initial:"<<initial;

}
class Student : public Person
{
private:
double gpa;
public:
	Student(int x, int y, char ch, double d) : Person(x,y,ch), gpa(d) {}
	void showStudent();
};
void Student::showStudent()
{
cout<<"Student ID #"<<idNum;
cout<<" Avg: "<<gpa<<endl;
showPerson();
cout<<endl<<" Age: "<<age<<".";
cout<<" Initial: "<<initial<<endl;
}
int main()
{
Person per(387, 23, 'A');
cout<<endl<<"Person..."<<endl;
per.showPerson();
cout<<endl<<endl<<"Student..."<<endl;
Student stu(388, 18, 'B', 3.8);
stu.showStudent();

cin.get();
cin.get();
return 0;
}
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
From the first glance, your program appears to have lot of syntactical errors.

You have defined setData but calling setdeta.

gpa is defined wrongly

idNum is private to Person and you don't have access to it in showStudent method
Thank, you I made all the changes and it works.
Topic archived. No new replies allowed.