0
#include<iostream>
#include<iomanip>

using namespace std;


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

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);
Student Students[2];
void GetStudents(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;
	
	//Pass this object into the function so it can be filled up with useful information as wanted in step #2
	S1 = StudentData(S2);
	//Display new and exciting information as specified in step #3
	display(S1);
	display(S2);	
	//Function call to change data in S2 as specified in step #4
	ChangeData(S2);
	//Displays ChangeData
	display(S2);
	//Array
	Student Students[2];    
	
	return 0;
}


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

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* S)
{
	cout << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}
void GetStudents(Student array[], int& size)
{
	for(int i=0; i<size; i++)
	{
		cout << "Enter name: ";
		cin.getline(array[i]->Name, 30);
		
		cout << "Enter GPA: ";
		cin >> array[i]->GPA;
		
		cout << "please enter major: " ;
		cin >> array[i]->Major;
		
		cin.ignore(1);
	}
}
0

Very good.

One recommendation though, I would place your ignore() before the getline() call in efforts to clear the input buffer of any extraneous pesky newline characters.

In fact, if you don't do this, it will adversely affect your program later on.

Also, in keeping with good programming practices, move line #39 to line #28. All variable declarations should be made together at the beginning of a block of code. (having variables declared at random throughout your code will turn it into a nightmare)

So this brings us to step #8:

8. Call the function GetStudents from main.

I have full confidence in your ability to make the function call as required. As soon as you are done with this, we can move on to step #9.

Edited by Clinton Portis: n/a

0

i am getting nothing but error messages on the bottom and when you say place ignore() before getline

0

try turning all the -> into periods .

I can give you the explaination for this later on if you desire.

ok i'll give it to you now:

to keep it simple: whenever you are using a subscripted pointer, the pointer is automatically dereferrenced, therefore, you do not need to use the arrow operator.

(except when you are using an array of pointers)

Edited by Clinton Portis: n/a

0

okay that worked and the Student Students[2]; where should I put it i had it under display(S2) and i have under void changedata but it says it wants it in main and im not sure exactly where

0

and what did the getstudent really do when i run it i seen nothing changing

0

put it with the rest of your variable declarations:

//Declare two objects of type 'Student' as wanted in step #1
Student* S1 = new Student;
Student* S2 = new Student;
Student Students[2];

Your future employer will love you.

0

and what did the getstudent really do when i run it i seen nothing changing

Does your code look anything like this? If not, then maybe you should make the proper adjustments:

#include<iostream>
using namespace std;


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

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


//main driver
int main()
{
     //Declare two objects of type 'Student'; step #1
     Student* S1 = new Student;
     Student* S2 = new Student;
     //Step #6 requirement
     Student Students[2];

     //Pass this object into our function so it can be filled up with useful information; step #2
     S1 = StudentData(S2);
     //Display new and exciting information to the DOS console; step #3
     display(S1);
     display(S2);
     //Function call to change data in S2 as per step #4 requirement
     ChangeData(S2);
     //Function call to dsiplay the newly changed S2 object as per step #5
     display(S2);
     //Step #7
     GetStudents(Students, 2);

return 0;
}


//Function Definitions
Student* StudentData(Student* S)
{
     cout << "Enter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "Enter major: " ;
     cin >> S->Major;

     return S;
}

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

void ChangeData(Student* S)
{
     cout << "Enter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "please enter major: " ;
     cin >> S->Major;
}

void GetStudents(Student array[], int size)
{
     for(int i=0; i<size; i++)
     {
        cin.ignore(1);

        cout << "Enter name: ";
        cin.getline(array[i].Name, 30);

        cout << "Enter GPA: ";
        cin >> array[i].GPA;

        cout << "Enter major: " ;
        cin >> array[i].Major;
     }
}

Edited by Clinton Portis: n/a

0

if i do that it tells me its an unused variable

#include <iostream>
#include <iomanip>

using namespace std;


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

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);
void GetStudents(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;
	Student Students[2];
	
	//Pass this object into the function so it can be filled up with useful information as wanted in step #2
	S1 = StudentData(S2);
	//Display new and exciting information as specified in step #3
	display(S1);
	display(S2);	
	//Function call to change data in S2 as specified in step #4
	ChangeData(S2);
	//Displays ChangeData
	display(S2);
	
	
  
	
	return 0;
}


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

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* S)
{
	cout << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}
void GetStudents(Student array[], int& size)
{
		
	for(int i=0; i<size; i++)
	{
		
		
		cout << "Enter name: ";
		cin.getline(array[i].Name, 30);
		
		cout << "Enter GPA: ";
		cin >> array[i].GPA;
		
		cout << "please enter major: " ;
		cin >> array[i].Major;
		
		cin.ignore(1);
	}
}
0

if i do that it tells me its an unused variable

Yes, the Students[] array is declared, and not used.. that is until you complete step #8:

8. Call the function GetStudents from main.

Now the variable will be used and your compiler will stop issuing you those warnings.

its because of the &

Just take away the address operator (since we are passing in a constant)

Edited by Clinton Portis: n/a

0

i did but in your code you took out the & sign from those locations

0

i am not understanding this program isnt it suppose to do something with the numbers

0

i did but in your code you took out the & sign from those locations

Then I would suggest that you make your code look like my code.

0

yea i did once i saw it in yours i made the adjustment and tookem out

are we on step 9

0

i am not understanding this program isnt it suppose to do something with the numbers

It does nothing but record user input into different c++ data types, and then return the same user input back to the dos console.

Think of it as a database (or record keeping) program.

Edited by Clinton Portis: n/a

0

ok that make more sense i thought it was suppose to calculate the user input

0

ok i understand it now what it will do is record and if the input is incorect it will catch and throw data

0

ok now for number 9 i understand that it gonna be like

void PrintStudents()

but will i put this in the brackets(Student array[], int size)

0
#include <iostream>

using namespace std;


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

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);
void GetStudents(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
	S1 = StudentData(S2);
	//Display new and exciting information as specified in step #3
	display(S1);
	display(S2);	
	//Function call to change data in S2 as specified in step #4
	ChangeData(S2);
	//Displays ChangeData
	display(S2);
	//Step #7
	GetStudents(Students, 2);	
  
	
	return 0;
}


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

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* S)
{
	cout << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->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()
{

}
0

Here is what I came up with for step #9.. maybe you came up with something better:

void PrintStudents(Student array[], int size)
{
    for(int i=0; i<size; i++)
    {
         cout << array[i].Name << ' ' << array[i].GPA << ' ' << array[i].Major << endl;
    }
}

Edited by Clinton Portis: n/a

0

i used what you just put to see if it works my didnt at all it was compile error, but yours did and i dont know y, but what is number 9 supose to do i dont see change

#include <iostream>

using namespace std;


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

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);
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
	S1 = StudentData(S2);
	//Display new and exciting information as specified in step #3
	display(S1);
	display(S2);	
	//Function call to change data in S2 as specified in step #4
	ChangeData(S2);
	//Displays ChangeData
	display(S2);
	//Step #7
	GetStudents(Students, 2);	
  
	
	return 0;
}


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

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* S)
{
	cout << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->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;
    }
}
0

Enter name: a
Enter GPA: 3
Enter major: 2

Name: a
GPA: 3
Major: 2


Name: a
GPA: 3
Major: 2


Enter name: b
Enter GPA: 4
Enter Major: 2

Name: b
GPA: 4
Major: 2


Enter name: c
Enter GPA: 2
please enter major: 1

Enter name: d
Enter GPA: 4
please enter major: 3

this is what i get

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.