EliteApple 0 Junior Poster in Training
#include <iostream>

using namespace std;


struct Student
{
	char Name[30];
	float GPA;
	int Major;
};

//Function prototypes
Student* StudentData(Student* S1);
void display(Student* S);
void ChangeData(Student* S2);
void GetStudents(Student array[], int size);
void PrintStudents(Student array[], int size);

//Main information build
int main()
{
	//Declare two objects of type 'Student' as wanted in step #1
	Student* S1 = new Student;
	Student* S2 = new Student;
	//Step #6
	Student Students[2];
	
	//Pass this object into the function so it can be filled up with useful information as wanted in step #2
	S2 = StudentData(S1);
	//Display new and exciting information as specified in step #3
	display(S1);
	//Function call to change data in S2 as specified in step #4
	ChangeData(S2);
	//Displays ChangeData
	display(S2);
	//Step #7
	GetStudents(Students, 2);	
    //Step #9
	PrintStudents(Students, 2);
	
	return 0;
}


//Function Definitions Which Ask For User Input And Displays Them
Student* StudentData(Student* S1)
{
	cout << "Enter name: ";
	cin >> S1->Name;
	
	cout << "Enter GPA: ";
	cin >> S1->GPA;
	
	cout << "Enter major: " ;
	cin >> S1->Major;
	
	return S1;
}

void display(Student* S)
{
	cout << "                " << endl;
    cout << "Name: " << S->Name  << endl;
    cout << "GPA: " << S->GPA   << endl;
    cout << "Major: " << S->Major << endl;
	cout << "                " << endl;
}

void ChangeData(Student* S2)
{
	cout << "\nEnter name: ";
	cin >> S2->Name;
	
	cout << "Enter GPA: ";
	cin >> S2->GPA;
	
	cout << "Enter Major: " ;
	cin >> S2->Major;
}
void GetStudents(Student array[], int size)
{
		
	for(int i=0; i<size; i++)
	{
		cin.ignore(1);
		cout << "            " << endl;
		cout << "Enter name: ";
		cin.getline(array[i].Name, 30);
		
		cout << "Enter GPA: ";
		cin >> array[i].GPA;
		
		cout << "please enter major: " ;
		cin >> array[i].Major;
		
		
	}
}
void PrintStudents(Student array[], int size)
{
	for(int i=0; i<size; i++)
    {
		cout << array[i].Name << ' ' << array[i].GPA << ' ' << array[i].Major << endl;
    }
}

this is what i need it to be
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; 
};

1. In main create 2 instances of that structure. Call them S1 and S2.

2. 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.

3. In main print the data stored in the structures S1 and S2 using cout.

4. 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…)

5. Back in main print the data stored in the structure S2 using cout.

6. Now create an array of 2 structures in main. Call the array Students.

7. 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.

8. Call the function GetStudents from main.

9. 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.