Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//structures passing to functions by reference // create a Student structure tha

ID: 3778486 • Letter: #

Question

//structures passing to functions by reference
// create a Student structure that contains an ID number (integer), student name (string class), number of courses taken (integer) and GPA (double).
//Use a function getStudent to enter data for a student. Use a function showStudent to show the data.
//Pass the Student structure to the functions by REFERENCE, not by value.
/*
Enter the student number (integer): 1234
Enter the student name: Ernst Bekkering
Enter the number of courses taken: 16
Enter the GPA: 3.75
Student number: 1234
Name: Ernst Bekkering
Course taken: 16
GPA: 3.75
Press any key to continue . . .
*/

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct Student
{
int studentID;
string studentName;
int coursesTaken;
double GPA;
};

void getStudent (????????????);
void showStudent (????????????);

int main()
{
Student nsuStudent;

getStudent(???????????);
showStudent(?????????????);

return 0;
}

//**********************
//definition of getStudent (by reference)
//*************************
void getStudent(????????????)
{
cout << "Enter the student number (integer): ";
cin >> ??????????;
cout << "Enter the student name: ";
cin.ignore();
getline(cin, ?????????????);
cout << "Enter the number of courses taken: ";
cin >> ????????????????;
cout << "Enter the GPA: ";
cin >> ????????????????;
}

//**************************************
// definition of showStudent (by reference)
//**************************************

void showStudent(????????????????)
{
cout << fixed << showpoint << setprecision(2);
cout << "Student number: " <<????????????? << endl;
cout << "Name: " << ???????????? << endl;
cout << "Course taken: " << ??????????? << endl;
cout << "GPA: " << ??????????? << endl;

}

Explanation / Answer

Please find the required program along with its output. Please see the comments against each line to understand the step.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Student
{
int studentID;
string studentName;
int coursesTaken;
double GPA;
};
void getStudent (Student *s);
void showStudent (Student *s);
int main()
{
Student nsuStudent;
getStudent(&nsuStudent); //passing reference only(by passing the address location of the struct)
showStudent(&nsuStudent); //passing reference only(by passing the address location of the struct
return 0;
}
//**********************
//definition of getStudent (by reference)
//*************************
void getStudent(Student *s) //receiving the address location through pointer s
{
cout << "Enter the student number (integer): ";
cin >> s->studentID; //accesing studentID of student
cout << "Enter the student name: ";
cin.ignore();
getline(cin, s->studentName); //accesing studentName of student
cout << "Enter the number of courses taken: ";
cin >> s->coursesTaken; //accesing coursesTaken of student
cout << "Enter the GPA: ";
cin >> s->GPA; //accesing GPA of student
}
//**************************************
// definition of showStudent (by reference)
//**************************************
void showStudent(Student *s)
{
cout << fixed << showpoint << setprecision(2);
cout << "Student number: " <<s->studentID << endl; //accesing studentID of student
cout << "Name: " << s->studentName << endl; //accesing studentName of student
cout << "Course taken: " << s->coursesTaken << endl; //accesing coursesTaken of student
cout << "GPA: " << s->GPA << endl; //accesing GPA of student
}

-------------------------------------------------------------------

OUTPUT:

Enter the student number (integer): 9044
Enter the student name: rishi
Enter the number of courses taken: 12
Enter the GPA: 97.5
Student number: 9044
Name: rishi
Course taken: 12
GPA: 97.50