Hi everyone I need major help i took a class in c++ and was doing fine until the last challenge, I need help with it in every way, below is what is wanted but I cant understand anything please help me
This program will include error trapping with try and catch.
Put a throw in each function which gets user input and throw a string "Bad Major" if a Major of 0 is entered. The input functions are specified in 2, 4 and 7 below.
Create a global structure as follows:
struct Student
{
char Name[30];
float GPA;
int Major;
};
In main create 2 instances of that structure. Call them S1 and S2.
Create and call a function named StudentData:
S2 = StudentData( S1 ); //this is the call to the function
The function receives as a parameter a reference to the structure (prototyping will handle this) and will return a reference to the structure. Use couts and cins for getting data from the user. For testing purposes, change the data in S1 so that the GPA is 3.5 and the Major is 2. Since you are to use cins for getting data from the user, you are the user and just enter these values. After the call to the function both S1 and S2 will contain the same data.
In main print the data stored in the structures S1 and S2 using cout.
Call a function named ChangeData with a pointer to S2 as the argument:
ChangeData( &S2 ); //this is the call to the function
Change the data in S2 so that the GPA is 3.0 and the Major is 1. (Using these values for testing…)
Back in main print the data stored in the structure S2 using cout.
Now create an array of 2 structures in main. Call the array Students.
Create a function, GetStudents, which will receive the array and an int representing the number of elements(2). In the function, loop through the data and get all three fields from the user using cin, cin.getline and cout statements. Organize like this:
for (...........) { cout prompt to user cin.getline for name cout prompt to user cin for GPA cout promp to user cin for Major cin.ignore(1); }
The problem is that a cin for a numeric value will leave the ENTER key in the keyboard buffer and that is OK with cin and other numbers but not with strings, thus we must remove it on our own. cin.ignore should handle this for us.
Call the function GetStudents from main.
Create a function, PrintStudents, which will receive the same arguments as GetStudents. It will print out the array of students on 2 lines, 1 line per student.