Answer to Question #329948 in C++ for mak

Question #329948

Write a program that creates a class called student. The data members of the class are name and age.

·      Create a nullary constructor and initialize the class object.

·      Create a parameterized constructor that can set the values being passed from the main function.

·      Create a display function called showall( ) which will be used to show values that have been set.

Use the default copy constructor to show that copying of simple objects can be accomplished through the use of the default copy constructor.


1
Expert's answer
2022-04-18T08:40:54-0400
#include <iostream>
#include <string>

using namespace std;

class Student
{
	string name;
	int age;
public:
	Student() {}
	Student(string _name, int _age):name(_name),age(_age) {}
	void Assign()
	{
		cout << "Please, enter a name of student: ";
		cin >> name;
		cout << "Please, enter an age of student: ";
		cin >> age;
	}
	void Showall()
	{
		cout << "The name of student is " << name
			<< "\nThe age of student is " << age<<endl;
	}
};




int main()
{
	Student a("Jack", 18);
	cout << "Info about student a(parametrized constructor):\n";
	a.Showall();
	Student b;
	b.Assign();
	cout << "Info about student b(nullary constructor):\n";
	b.Showall();
	Student c(b);
	cout << "Info about student c(default copy constructor):\n";
	c.Showall();
}







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