// This program demonstrates a function that uses a // pointer to a structure variable as a parameter. #include #include #include using namespace std; struct Student { string name; // Student's name int idNum; // Student ID number int crdHrs; // Credit hours enrolled double gpa; // Current GPA }; void getData(Student *); // Function prototype int main() { Student freshman; // Get the student's data cout << "Enter the following student data:\n"; getData(&freshman); // Print the student's data cout << "\nHere is the student data you entered:\n"; cout << setprecision(4); cout << "Name: " << freshman.name << endl; cout << "ID number: " << freshman.idNum << endl; cout << "Credit hours: " << freshman.crdHrs << 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) { cout << "Student name: "; getline(cin, s->name); cout << "Student ID number: "; cin >> s->idNum; cout << "Credit hours enrolled: "; cin >> s->crdHrs; cout << "Current GPA: "; cin >> s->gpa; }