Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started