excerpt from program
Code:
#define TABLE_SIZE 25
struct STUDENT_STRUCT
{
char last_name [21];
char first_name [21];
char social [12];
char phone [9];
int quiz [5];
int final;
int final_grade;
};
STUDENT_STRUCT user_prompt (STUDENT_STRUCT*);
int grade_computer (STUDENT_STRUCT*);
int quiz_computer (STUDENT_STRUCT*);
int main ()
{
STUDENT_STRUCT main_struct[TABLE_SIZE];
int row = 0;
int count = 1;
char response[8];
cout << "Welcome, Dr. Jacobs, to the marketing 101 grade "
<< "computation program. (hit any key when ready)\n";
cin.get();
cin.ignore(80, '\n');
cout << "\nWould you like to enter your first student's "
<< "information now? Enter Y or N\n";
cin.getline (response, 11);
cin.ignore(80, '\n');
while (toupper(*response) == 'Y')
{
while (row < TABLE_SIZE)
{
user_prompt(&main_struct[row]);
++row;
++count;
cout << "Enter another student? Enter Y or N";
cin.getline (response, 11);
cin.ignore(80, '\n');
}
}
cout << "Final student class averages are as follows: \n\n";
row = 0;
for (row=0;row<count;++row)
{
main_struct[row].final_grade = grade_computer(main_struct[row]);
main_struct[row].quiz = quiz_computer(main_struct[row]);
}
return 0;
}
STUDENT_STRUCT user_prompt (STUDENT_STRUCT* stud_ptr)
{
int x;
cout << "\nEnter student's last name: ";
cin.getline (stud_ptr.last_name, 21);
cin.ignore (80, '\n');
cout << "\nEnter student's first name: ";
cin.getline (stud_ptr.first_name, 21);
cin.ignore (80, '\n');
cout << "\nEnter student's social security number: ";
cin.getline (stud_ptr.social, 12);
cin.ignore (80, '\n');
cout << "\nEnter student's phone number: ";
cin.getline (stud_ptr.phone, 9);
cin.ignore (80, '\n');
for (x=0;x<5;++x)
{
cout << "\nEnter student's grade for quiz " << x+1 << ": ";
cin >> stud_ptr.quiz[x];
}
cout << "\nEnter the student's final exam grade: ";
cin >> stud_ptr.final;
return stud_ptr;
}
in the called function, i move the address of main_struct into the student function and then take it in as a pointer called stud_ptr...
am i going about this the wrong way? Does it make sense, in main to just send over one row at a time and then increment the counters?