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)
#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;
}
Comments
Leave a comment