// This program demonstrates a function that uses a // pointer to a structure variable as a parameter. #include #include using namespace std; const int NAME_LENGTH = 35; // Array size struct Student { char name[NAME_LENGTH]; // Student's name int idNum; // Student ID number int creditHours; // Credit hours enrolled double gpa; // Current GPA }; void getData(Student *); // Function prototype int main() { Student freshman; // Get the student data. cout << "Enter the following student data:\n"; getData(&freshman); // Pass the address of freshman. cout << "\nHere is the student data you entered:\n"; // Now display the data stored in freshman cout << setprecision(2); cout << "Name: " << freshman.name << endl; cout << "ID Number: " << freshman.idNum << endl; cout << "Credit Hours: " << freshman.creditHours << endl; cout << "GPA: " << freshman.gpa << endl; return 0; } //******************************************************* // Definition of function getData. Uses a pointer to a * // Student structure variable. The user enters student * // information, which is stored in the variable. * //******************************************************* void getData(Student *s) { // Get the student name. cout << "Student name: "; cin.getline(s->name, NAME_LENGTH); // Get the student ID number. cout << "Student ID Number: "; cin >> s->idNum; // Get the credit hours enrolled. cout << "Credit Hours Enrolled: "; cin >> s->creditHours; // Get the GPA. cout << "Current GPA: "; cin >> s->gpa; }