Question: Inside the main make a pointer of an Student class object and initialize with student name Heather and ID 9. Print the name and ID
Inside the main make a pointer of an Student class object and initialize with student name "Heather" and ID "9". Print the name and ID of the student. Make sure the object is deleted after printing the name and ID by explicit call to a destructor.
------------------Student Class----------------------
using namespace std; class Student { private: string student-name; int student-id; public: Student(string d, int x) { student-id=x; student-name=d; } ~Student (void){ delete student-id; student-id = nullptr; delete student-name; student-name = nullptr; } void printname() { cout << "Student name is: " << student-name; } void printid() { cout << "Student id is: " << student-id; } };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
