Question: c++ Array of Pointers: declare ST[5] - an array of pointers to student objects, use a for-loop to make the array point to 5 new

c++

Array of Pointers: declare ST[5] - an array of pointers to student objects, use a for-loop to make the array point to 5 new objects in the heap, use a for-loop to set the last name of each object to what the user enters, use a for-loop to get and display the name of each student. (in the client.cpp)

___________________________

student.h

#include

using namespace std;

class student

{

private:

// Data Members making up each student object (hidden from the client)

string student_name;

string student_major;

int student_grade_level;

public:

student(); // constructor

string getname();

void setname(string);

string getmajor();

void setmajor(string);

~student(); // destructor

};

____________________________________________

srudent.cpp

#include "student.h"

#include

using namespace std;

// note that student.h includes

student::student(){};

student::~student(){};

void student::setname(string s)

{

student_name = s;

}

string student::getname()

{

return student_name;

}

void student::setmajor(string s)

{

student_major = s;

}

string student::getmajor()

{

return student_major;

}

__________________________________

client.cpp

#include

#include"student.h"

using namespace std;

int main()

{

student *ST[5];

// ** declare ST[5] - an array of pointers to student objects

for (int i=0;i<5;i++)

{

ST[i]=new student;

}

// ** use a for-loop to make the array point to 5 new objects in the heap

for(int i=0;i<5;i++)

string LN;

int num =i;

cout<<"Enter the lastname of the student: "<

cin>>LN;

ST[i]->setname(LN);

// ** use a for-loop to set the last name of each object to what the user enters

// ** use a for-loop to get and display the name of each student

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!