Answer to Question #178172 in C++ for Hari bashkar

Question #178172

Create the class Student consisting of data members register_no and name. Define array of objects by using constructor Student() to assign the values for the class Student data members, display() member function is used to display the information of student. Finally free the resources of data objects using destructor member function. (Note: Define object size of two)


1
Expert's answer
2021-04-04T11:15:39-0400
#include <iostream>
#include <string>
 
using namespace std;
 
class Student
{
public:
	Student();
	~Student();
	void Display();
private:
	string name;
	int register_no;
};
 
Student::Student()
{
	int no;
	string name_;
	cout << "Enter student name: ";
	cin >> name_;
	cout << "Enter student number: ";
	cin >> no;
	name = name_;
	register_no = no;
}
 
Student::~Student()
{
	
}
 
void Student::Display()
{
	cout << register_no << " " << name << endl;
}
 
int main()
{
	int numberOfStudents = 0;
	cout << "Enter number of students: ";
	cin >> numberOfStudents;
	Student* Team = new Student[numberOfStudents];
	cout << endl;
	for (int i = 0; i < numberOfStudents; i++)
	{
		Team[i].Display();
	}
	system("pause");
	delete[]Team;
	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