Answer to Question #323238 in C++ for Mominul

Question #323238

#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>

1
Expert's answer
2022-04-04T07:47:48-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS