#include<iostream>

using namespace std;

 

 

struct Student

{

     char Name[30];

     float GPA;

     int Major;

};

 

//Function prototypes

Student* StudentData(Student* S);

void display(Student* S);

 

int main()

{

     //Declare two objects of type 'Student'

     Student* S1 = new Student;

     Student* S2 = new Student;

 

     //Pass this object into our function so it can be filled up with useful information

     S1 = StudentData(S2);

     //Display new and exciting information to the DOS console

     display(S1);

     display(S2);

 

 

 

return 0;

}

 

 

//Function Definitions

Student* StudentData(Student* S)

{

     cout << "Enter name: ";

     cin >> S->Name;

 

     cout << "Enter GPA: ";

     cin >> S->GPA;

 

     cout << "please enter major" ;

     cin >> S->Major;

 

     return S;

}

 

void display(Student* S)

{

    cout << S->Name  << endl;

    cout << S->GPA   << endl;

    cout << S->Major << endl;

}

Student* ChangeData(Student* S)

{

     cout << "Enter name: ";

     cin >> S->Name;

 

     cout << "Enter GPA: ";

     cin >> S->GPA;

 

     cout << "please enter major" ;

     cin >> S->Major;

 

     return S;

}

do i have to change the Student* ChangeData(Student* S2) or just keep it S

Excellent, we have completed step #4. Here is our good working code that compiles based on steps 1 thru 4:

#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);


//main driver
int main()
{
     //Declare two objects of type 'Student'; step #1
     Student* S1 = new Student;
     Student* S2 = new Student;

     //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);

return 0;
}


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

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

     cout << "please 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 << "\nEnter name: ";
     cin >> S->Name;

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

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

Now this brings us up to step #5:

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

THIS IS EASY.... just make a simple function call inside of main()..

We already have the function available to us.. all you have to do is make the function call as per step #5 requirement.

I'm sure you know what function to use....

Just supply the right argument to the function, and make the function call......

as soon as you are done with this, we can move onto step #6.

Hint: the function has been called twice aleady..

we would use the display function but we already called the s1 and s2 data in that function

#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);

 

 

//main driver

int main()

{

     //Declare two objects of type 'Student'; step #1

     Student* S1 = new Student;

     Student* S2 = new Student;

 

     //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);

 

return 0;

}

 

 

//Function Definitions

Student* StudentData(Student* S)

{

     cout << "Enter name: ";

     cin >> S->Name;

 

     cout << "Enter GPA: ";

     cin >> S->GPA;

 

     cout << "please 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 << "\nEnter name: ";

     cin >> S->Name;

 

     cout << "Enter GPA: ";

     cin >> S->GPA;

 

     cout << "please enter major" ;

     cin >> S->Major;

}

void display(ChangeData* S)

{

    cout << S->Name  << endl;

    cout << S->GPA   << endl;

    cout << S->Major << endl;

}

or is it simple as to changing the s to s2

#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);

//main driver

int main()

{

//Declare two objects of type 'Student'; step #1

Student* S1 = new Student;

Student* S2 = new Student;

//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);

return 0;

}

//Function Definitions

Student* StudentData(Student* S)

{

cout << "Enter name: ";

cin >> S->Name;

cout << "Enter GPA: ";

cin >> S->GPA;

cout << "please 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 << "\nEnter name: ";

cin >> S->Name;

cout << "Enter GPA: ";

cin >> S->GPA;

cout << "please enter major" ;

cin >> S->Major;

}

void display(Student* S2)

{

cout << S->Name << endl;

cout << S->GPA << endl;

cout << S->Major << endl;

}

You still haven't made any attempt to display the contents of the S2 object since it was affected at the ChangeData() function call.

I am not going to help you any further until you do so.

i have a question why does it output two answers for the first input

#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);


//main driver
int main()
{
	//Declare two objects of type 'Student'; step #1
	Student* S1 = new Student;
	Student* S2 = new Student;
	
	//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);
		
	//Function call to change data in S2 as per step #4 requirement
	ChangeData(S2);
	//Dispaly S2
	display(S2);	
	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 << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}

ok i moved the display(s2) from (S1) and now it displays both of them after input is that the right way

Because your assignment requires you to.....

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

this is with just making the second adding one more to the last

#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);


//main driver
int main()
{
	//Declare two objects of type 'Student'; step #1
	Student* S1 = new Student;
	Student* S2 = new Student;
	
	//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);
	//Dispaly S2
	display(S2);	
	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 << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}

this last one does both

if im right this one should display what number 5 wants

Yess... you got it.

You made an additional display() call after the S2 object was affected at ChangeData().

So, here is our good working code that compiles and adheres to the assignment requirements:

#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);


//main driver
int main()
{
     //Declare two objects of type 'Student'
     Student* S1 = new Student;
     Student* S2 = new Student;

     //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);


return 0;
}


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

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

     cout << "please 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;
}

This brings us to step #6:

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

Easy enough, simply declare an array of two students[2] in the main function. As soon as you can do this, we can move onto step #7.

im not sure if im understanding right but it sound like number 3 wants you to create the code so the s1 and s2 prints but changedata should print s2 and studentdata s1 because it doesnt make sense to want studentdata to print the same info twice since change data is s2

If you are not sure what your professor is trying to teach you..... I'll tell you.

In the beginning, S1 and S2 are the same.

You show your mastery of c++ by changing the S2 object

Now you can show the world that S1 no longer is the same as S2

But all this is stuff you don't even have to worry about.

Your professor is the customer.

Whatever he wants, he gets.

Even if it doesn't make sense.

Keep your mind on the assignment requirements.

Everything else is B.S.

Your project is correct thus far.

Please in (insert devine figure name here)'s name, just complete step #6 sometime before midnight.

how about this it displays the s2

#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 show(Student* S);

//main driver
int main()
{
	//Declare two objects of type 'Student'; step #1
	Student* S1 = new Student;
	Student* S2 = new Student;
	
	//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);
	//Display
	show(S2);
	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 << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}
void show(Student* S)
{
	cout << S->Name << endl;
	cout << S->GPA << endl;
	cout << S->Major << endl:
}

You are re-inventing the wheel by creating another function (show)...... that does the same thing as an existing function that we worked so hard to create (display)...

Why do you insist on doing extra work? Isn't the point of OOP code re-use..?

i did send the code where i used the same concept and you told me to re do it it was like this

#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);

//main driver
int main()
{
	//Declare two objects of type 'Student'; step #1
	Student* S1 = new Student;
	Student* S2 = new Student;
	
	//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);
	//Display
	diplay(S2);
	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 << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}

what i did is just put another display(s2) under the change data and it displays that data

What you have up there is good stuff....

Now let's move on to bigger and better things.. like creating an array of two student objects inside of main() (step #6)

would it be like

int students[Num_Student] = {"Student 1", "Student 2"};

Here is the requirement:

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

Here is your code:

int students[Num_Student] = {"Student 1", "Student 2"};

You've successfully managed to declare an array of integers.

Q: How do you think you'd declare an array of 'Student' objects?

students student[2] = {"student 1", "student 2"}
StuName Students[2];

the first I wrote defined the array of the object which was student 1 and student 2 but i dont think I need that

if i put this in the code do I have to use #include "Students.h"

or #include "StuName.h

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

StuName Students[2];

Very good. Incorrect, but very close:

//Step #6
Student Students[2];

This brings us to step #7

7. Create a function, GetStudents, which will receive the array and an int representing the number of elements(2).

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;          
     }
}

Please make the appropriate addition of this function to your code as per step #7 requirement. Include function prototype, function call, and function definition.

As soon as you are done, we can move on to step #8.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.