Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Defined a structure called that has the following field: a: Name that is strin

ID: 639734 • Letter: 1

Question

1.Defined a structure called that has the following field:

a: Name that is string;

b: Gpa that is double;

c:Age that is int;

2.In main create an array of student called student of size 4. Enter values to this array and output the values and check if it works.

3.If part 2 works, define a function to read the values into this array and then test the function.

4.Define a student pointer and place an address of a student variable in it. Place values into that location using the pointer. This is a practice for how to use >operator.

This is my code, but I don't know how to do the part4.

#include <iostream>

using namespace std;

int SIZE;

struct Student

{

string name;

double gpa;

int age;

};

void readValues(Student s[]);

int main()

{

Student students[4];

SIZE= 4;

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

{

cout << "Student:" << i+1 << endl;

cout << "input name:";

cin >> students[i].name;

cout << "input gpa:";

cin >> students[i].gpa;

cout << "input age:";

cin >> students[i].age;

cout << endl;

}

cout << endl;

cout << endl;

readValues(students);

}

void readValues(Student s[])

{

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

{

cout << "Student " << s[i].name << endl;

cout << "age:" << s[i].age << endl;

cout << "gpa:" << s[i].gpa << endl;

}

}

Explanation / Answer

struct Student
{
string name[100]; // string of up to 100 characters
int age; // name of field is "age". type is "int"
double gpa; // name of field is "gpa". type is "float"
};

Student students[100]; // here we declare an array of students
// of type "Array of Student". The name: "students"

int
main()
{
Student the_student; // declare a variable

the_student.age = 5;
sprintf(the_student.name, "Jim"); // remember the_student.anme = "jim"
// does not work.
the_student.gpa = 3.32;

print_student(the_student);
  
the_student = improve_gpa_of(the_student); // Note: we can return
// structures from functions.
}