Question: C++: write a structure called student that has three members called id(int), gpa(double), name(name[size]). In main declare an array of pointers of type student. The

C++: write a structure called student that has three members called id(int), gpa(double), name(name[size]). In main declare an array of pointers of type student. The size of this array should be 4. Create 2 variables of type student and place the address of each in location 0 and 1 of this array. Create two other structures dynamically and place the address in the other two locations of this array. Pass this array to a function to read values for each item. Write a display function to display all values in the array.
#include
using namespace std;
below is what I currently have but it isn't working properly. Thank you.
#include
using namespace std;
struct student{
int id;
char name[30];
double gpa;
};
string readValue(student *ptr[]){
for(int i=1; i<4; i++){
cout<<"Enter student"<
cin>>ptr[i]->id;
cout<<"Enter student"<
cin.ignore();
cin.getline(ptr[i]->name, 30);
cout<<"Enter student"<
cin.ignore();
cin>>ptr[i]->gpa;
}
}
void displayValue(student *ptr[]){
for(int i=1; i<4; i++){
cout<<"Student"<id<
cout<<"Student"<name<
cout<<"Student"<gpa<
}
}
int main(){
student data;
student *ptr[4];
ptr[0]=new student;
ptr[1]=&data;
student data2;
student data3;
ptr[2]=&data2;
ptr[3]=&data3;
readValue(ptr);
displayValue(ptr);
return 0;
}

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!