Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER MUST BE IN C++ Consider a struct Student with data members: age (an integer), id (an integer), GPA (a float) and three member functions

ANSWER MUST BE IN C++

Consider a struct Student with data members: age(an integer), id (an integer), GPA (a float) and three member functions as follows:

struct Student

{

int age;

int id;

float GPA;

int getAge( ) { return age; };

int getId( ) {return id; };

float getGPA( ) {return GPA; };

};

Write a main routine in which you create an array of Student with 3 elements. Use cout to ask users for inputting the values for these three students, and use cin to grab users input from keyboard. Then, assign the user input to the three elements. For example, the first element may be with the content (age=19, id = 425540, GPA=3.0), the second element with the content (age=20, id=410020, GPA=2.8), and the third element with the information (age=21, id=440020, GPA=3.1).

Next, pass the array to a function, PrintStruct(arg1, arg2), in which arg1 should be the array of Student and arg2 is the length of the array (=3 in this case). In PrintStruct(arg1, arg2), write a for loop to print out the information of each student by using the three member functions of the struct and cout (in this case, we have three students in total).

Write another function, AverageGPA(arg 1, arg 2, arg 3), in which arg1 should be the array of Student, arg2 is the length of the array (=3 in this case), and arg3 is a floating number for the average GPA of these three students and should be passed by reference back to the main().

The skeletons of the main( ) and PrintStruct() are as follows:

void main( )

{

// create an array of Employee with two elements

..

// ask user input from keyboard for each element

// set the values for the two elements of the array

// call PrintStruct( ) with a proper parameter list

PrintStruct( arg1, arg2);

AverageGPA( arg1, arg2, arg3);

cout << Average GPA = << arg3 << endl;

}

void PrintStruct(arg1, arg2)

{

// for loop

Output the information to screen by calling the member functions of the struct

}

void AverageGPA(arg1, arg2, arg3)

{

// calculate the GPA of three students by a for loop

// arg3 should be fed back to the main( ) via pass-by-reference

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions