Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Describe the Kanban method of managing projects.

Answered: 1 week ago

Question

What do you think accounts for the fact that turnover is low?

Answered: 1 week ago