Exercise: Constructors
NOT Collected
Below is a class called Student. Alter the code to create two constructors.
The first takes no parameters and sets the variables of the class instance
to some default values of your choice. The second constructor takes the
values of Name, Age, SS# and Advisor and uses them to initialize the instance.
You must also create a program called School which has a main()
function that creates a few Student object, one using the constructor with
no paramters and another using the constructor with parameters.
class Student {
public:
String Name;
int age;
int SSNum;
String Advisor;
void PrintInfo();
}
//now in Student.cpp file
void Student::PrintInfo(){
cout << "Name: " << Name << endl;
cout << "age: " << age << endl;
cout << "SS#: " << SSNum << endl;
cout << "Advisor: " << Advisor << endl;
}
|