Question: In C++ Define a default constructor that initializes the data members, integer age and string name, with the default values 0 and Unspecified, respectively. Ex:

In C++

Define a default constructor that initializes the data members, integer age and string name, with the default values 0 and "Unspecified", respectively.

Ex: If the input is 60 Kim, then the output is:

Age: 0, Name: Unspecified Age: 60, Name: Kim

Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters.

#include #include using namespace std;

class Student { public: Student(); void SetAge(int studentAge); void SetName(string studentName); void Print();

private: int age; string name; };

/* Your code goes here */

void Student::SetAge(int studentAge) { age = studentAge; }

void Student::SetName(string studentName) { name = studentName; }

void Student::Print() { cout << "Age: " << age << ", Name: " << name << endl; }

int main() { int newAge; string newName; Student myStudent;

myStudent.Print(); cin >> newAge; cin >> newName;

myStudent.SetAge(newAge); myStudent.SetName(newName);

myStudent.Print();

return 0; }

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!