Question: I have 5 C++ files (2 headers, 2 cpp files, and 1 main file). Everything works fine expect for the display() function. The program runs

I have 5 C++ files (2 headers, 2 cpp files, and 1 main file). Everything works fine expect for the display() function. The program runs and takes input but will only display the text and not the values from the get functions and the phone number just prints a random set of numbers. What am I doing wrong? Please.

main.cpp

1 #include

2 #include "Student.h"

3 #include "Phone.h"

4

5 using namespace std;

6

7 int main()

8 {

9 Student s;

10 string fn;

11 string ln;

12 string mi;

13 string dob;

14 string gender;

15 string id;

16

17 Phone p;

18 int area;

19 int exchange;

20 int line;

21 const int texts = 10;

22

23 s.setFirstName(fn);

24 s.setLastName(ln);

25 s.setMiddleInitial(mi);

26 s.setDateOfBirth(dob);

27 s.setGender(gender);

28 s.setStudentId(id);

29

30 p.setArea(area);

31 p.setExchange(exchange);

32 p.setLine(line);

33

34 s.display();

35 cout <<"first name is " << s.getFirstName() << endl;

36 cout <<"last name is " << s.getLastName() << endl;

37

38 p.display();

39 cout << "Phone number is " << p.getArea() << "-" << p.getExchange() << "-" << p.getLine() << endl;

40 }

Student.cpp

1 #include

2 #include "Student.h"

3 using namespace std;

4

5 Student::Student(){

6 firstName = " ";

7 lastName = " ";

8 middleInitial = " ";

9 dateOfBirth = " ";

10 gender = " ";

11 studentId = " ";

12 }

13

14 void Student::setFirstName(string fn){

15 firstName = fn;

16 }

17

18 void Student::setLastName(string ln){

19 lastName = ln;

20 }

21

22 void Student::setMiddleInitial(string mi){

23 middleInitial = mi;

24 }

25

26 void Student::setDateOfBirth(string dob){

27 dateOfBirth = dob;

28 }

29

30 void Student::setGender(string gender){

31 gender = gender;

32 }

33

34 void Student::setStudentId(string id){

35 studentId = id;

36 }

37

38 string Student::getFirstName(){

39 return firstName;

40 }

41

42 string Student::getLastName(){

43 return lastName;

44 }

45

46 string Student::getMiddleInitial(){

47 return middleInitial;

48 }

49

50 string Student::getDateOfBirth(){

51 return dateOfBirth;

52 }

53

54 string Student::getGender(){

55 return gender;

56 }

57

58 string Student::getStudentId(){

59 return studentId;

60 }

61

62 void Student::display(){

63

64 string fn;

65 string ln;

66

67 cout << "First: " << endl;

68 cin >> fn;

69 cout << "last: " << endl;

70 cin >> ln;

71 }

Student.h

1 #ifndef STUDENT_H

2 #define STUDENT_H

3

4

5 #include

6 using namespace std;

7

8 class Student {

9 public:

10 Student();

11 Student(string studentId, string firstName, string lastName, string middleInitial, string dateOfBirth, string gender);

12 void setFirstName(string);

13 void setLastName(string);

14 void setMiddleInitial(string);

15 void setDateOfBirth(string);

16 void setGender(string);

17 void setStudentId(string);

18 void display();

19

20 std::string getFirstName();

21 std::string getLastName();

22 std::string getMiddleInitial();

23 std::string getDateOfBirth();

24 std::string getGender();

25 std::string getStudentId();

26

27 private:

28 std::string studentId;

29 std::string firstName;

30 std::string lastName;

31 std::string middleInitial;

32 std::string dateOfBirth;

33 std::string gender;

34 };

35 #endif

Phone.cpp

1 #include

2 #include "Phone.h"

3

4 using namespace std;

5

6 Phone::Phone(){

7 int area = 0;

8 int exchange = 0;

9 int line = 0;

10 const int texts = 10;

11 }

12

13 void Phone::setArea(int area){

14 area = area;

15 }

16

17 void Phone::setExchange(int exchange){

18 exchange = exchange;

19 }

20

21 void Phone::setLine(int line){

22 line = line;

23 }

24

25 int Phone::getArea(){

26 return area;

27 }

28

29 int Phone::getExchange(){

30 return exchange;

31 }

32

33 int Phone::getLine(){

34 return line;

35 }

36

37 void Phone::display(){

38

39 int area;

40 int exchange;

41 int line;

42

43 cout << "Area code: " << endl;

44 cin >> area;

45

46 cout << "Exchange: " << endl;

47 cin >> exchange;

48

49 cout << "Line: " << endl;

50 cin >> line;

51 }

Phone.h

1 #ifndef PHONE_H

2 #define PHONE_H

3

4 #include

5 using namespace std;

6

7 class Phone {

8 private:

9 int area;

10 int exchange;

11 int line;

12 const int texts = 10;

13

14 public:

15 Phone();

16 Phone(int area, int exchange, int line, const int texts);

17 int getArea();

18 int getExchange();

19 int getLine();

20 void setArea(int);

21 void setExchange(int);

22 void setLine(int);

23 void display();

24 };

25 #endif

Sample Output

First:

Bob

last:

Ross

first name is

last name is

Area code:

555

Exchange:

444

Line:

1234

Phone number is -1634512600-32712-882079472

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!