#include <iostream>
ung namespace std;
#include <string> class snident
string name="DefaultName":
string birthyear= "9999":
Your Code Here
int main(){
sident $1;
student $2("Geoffrey Hinton"); student $3("Yann LeCun", "1960");
s1.print_info(); print_info();
$3.print_info():
$2.change year(1947");
s1 change_name("YourName");
s1.change year("YourBirth Year>");
$2.print info(); $1.print_info();
return 0;
Complete the student class so the main function above produces the following output:
Name: DefaultName, Birth Year: 9999
Name: Geoffrey Hinton, Birth Year: 9999.
Name: Yann LeCun, Birth Year: 1960 Name: Geoffrey Hinton, Birth Year: 1947.
Name: YourName, Birth Year: <Your Birth Year>
#include <iostream>
#include <string>
using namespace std;
class student
{
string name = "DefaultName";
string birthyear = "9999";
public:
student() {}
student(string _name, string _birthyear)
:name(_name), birthyear(_birthyear) {}
student(string _name) :name(_name) {}
void print_info()
{
cout << "\nName: " << name << ", BirthtYear: " << birthyear;
}
void change_year(string year)
{
birthyear = year;
}
void change_name(string nm)
{
name = nm;
}
};
int main()
{
student s1;
student s2("Geoffrey Hinton");
student s3("Yann LeCun", "1960");
s1.print_info();
s2.print_info();
s3.print_info();
s2.change_year("1947");
s1.change_name("YourName");
s1.change_year("YourBirth Year");
s2.print_info();
s1.print_info();
return 0;
}
Comments
Leave a comment