Hi, I need help with this C++ programming problem: Assign courseStudent\'s name
ID: 3768247 • Letter: H
Question
Hi, I need help with this C++ programming problem:
Assign courseStudent's name with Smith, age with 20, and ID with 9999. Use the print member function and a separate cout statement to output courseStudents's data. End with a newline. Sample output from the given program:
Here is the template for the problem (please use it):
#include <iostream>
#include <string>
using namespace std;
class PersonData {
public:
void SetName(string userName) {
lastName = userName;
};
void SetAge(int numYears) {
ageYears = numYears;
};
// Other parts omitted
void PrintAll() {
cout << "Name: " << lastName;
cout << ", Age: " << ageYears;
};
private:
int ageYears;
string lastName;
};
class StudentData: public PersonData {
public:
void SetID(int studentId) {
idNum = studentId;
};
int GetID() {
return idNum;
};
private:
int idNum;
};
int main() {
StudentData courseStudent;
/* Your solution goes here */
return 0;
}
You just need to insert your codes into the line with Your solution goes here. Please check your codes with the sample output above before you post. Thanks!
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class PersonData {
public:
void SetName(string userName) {
lastName = userName;
};
void SetAge(int numYears) {
ageYears = numYears;
};
// Other parts omitted
void PrintAll() {
cout << "Name: " << lastName;
cout << ", Age: " << ageYears;
};
private:
int ageYears;
string lastName;
};
class StudentData: public PersonData {
public:
void SetID(int studentId) {
idNum = studentId;
};
int GetID() {
return idNum;
};
private:
int idNum;
};
int main() {
StudentData courseStudent;
courseStudent.SetName("Smith");
courseStudent.SetAge(20);
courseStudent.SetID(999);
courseStudent.PrintAll();
cout<<courseStudent.GetID();
/* Your solution goes here */
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.