ok im banging my head against the wall on this one....
here's the problem:
say I'm a professor and i keep a record of all my students, here is the info i keep:
first name
last name
ssn
phone numb
grades for 5 quizzes
grade for final exam
final grade average
1st thing I need to do is to make a structure with this info and here it is:
Code:
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;
};
Next, I need to write a function that prompts the user for all info for one student except the final grade. The problem is, that the function's only argument has to be a pointer to the structure of the type above.
I know this is probably wrong but here is the prototype, the call to the function from main, and the actual function...
Code:
STUDENT_STRUCT user_prompt(STUDENT_STRUCT*);
---------------------------------------------------------------------------------
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(&structure);
++row;
++count;
cout << "Enter another student? Enter Y or N";
cin.getline (response, 11);
cin.ignore(80, '\n');
}
else
break;
}
------------------------------------------------------------------------------------
void user_prompt (STUDENT_STRUCT* stud_ptr)
{
int x;
cout << "\nEnter student's last name: ";
cin.getline (stud_info.last_name, 21);
cin.ignore (80, '\n');
cout << "\nEnter student's first name: ";
cin.getline (stud_info.first_name, 21);
cin.ignore (80, '\n');
cout << "\nEnter student's social security number: ";
cin.getline (stud_info.social, 12);
cin.ignore (80, '\n');
cout << "\nEnter student's phone number: ";
cin.getline (stud_info.phone, 9);
cin.ignore (80, '\n');
for (x=0;x<5;++x)
{
cout << "\nEnter student's grade for quiz " << x+1 << ": ";
cin >> stud_info.quiz[x];
}
cout << "\nEnter the student's final exam grade: ";
cin >> stud_info.final;
}
as you can see I'm already hitting brick walls thus far....
next, i ned to write a function whose only argument, once again, is a pointer to the same arguement type above(STUDENT_STRUCT), and computes the final grade of the student as follows: the final grade is 75 percent of the quiz average plus 25 percent of the final exam
finally, the program i write prompts the user to input data on as many as 25 students, which should be stored in a table. the program uses the 2 functions to load and manipulate the grades and finally spit out a report that lists the students in alphabetical order and display the quiz average, the final exam grade, and the final quiz average. Also, the program must include the option to read/write to a text file.
The problem I am having is that I don't know how to go back and forth between the functions. Since I am regulated to pointers, Im not sure i can figure out how to pass tables or parts of tables back and forth.
Anyone who can help me would be my own personal saviour. I included what i have so far in its entirety just in case you wondered how i put it together so far. Yes, this program is far from finished and it's very f*^%$ed up .
Code:
/*this program computes a final average for marketing students
using structures, pointers, and functions.*/
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <ctype.h>
#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 structure;
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(&structure);
++row;
++count;
cout << "Enter another student? Enter Y or N";
cin.getline (response, 11);
cin.ignore(80, '\n');
}
else
break;
}
cout << "Final student class averages are as follows: \n\n";
row = 0;
for (row=0;row<count;++row)
{
stud_table[row].final_grade = grade_computer(stud_table[row]);
stud_table[row].quiz = quiz_computer(stud_table[row]);
}
return 0;
}
void user_prompt (STUDENT_STRUCT* stud_ptr)
{
int x;
cout << "\nEnter student's last name: ";
cin.getline (stud_info.last_name, 21);
cin.ignore (80, '\n');
cout << "\nEnter student's first name: ";
cin.getline (stud_info.first_name, 21);
cin.ignore (80, '\n');
cout << "\nEnter student's social security number: ";
cin.getline (stud_info.social, 12);
cin.ignore (80, '\n');
cout << "\nEnter student's phone number: ";
cin.getline (stud_info.phone, 9);
cin.ignore (80, '\n');
for (x=0;x<5;++x)
{
cout << "\nEnter student's grade for quiz " << x+1 << ": ";
cin >> stud_info.quiz[x];
}
cout << "\nEnter the student's final exam grade: ";
cin >> stud_info.final;
}
int grade_computer (STUDENT_STRUCT* stud_ptr)
{
int quiz_ave,
quiz_total,
q,
final_ave;
for (q=0,q<5,++q)
{
quiz_total += stud_table.quiz[q];
}
quiz_ave = quiz_total/(q+1);
final_ave = ((.75)*(quiz_ave)) + ((.25)*(stud_table.final));
return final_ave;
}
int quiz_computer (STUDENT_STRUCT* stud_ptr)
{
int qquiz_ave,
qquiz_total,
row,
qq;
for (row=0,row<25,row
for (qq=0,q<5,++qq)
{
qquiz_total += stud_table[row].quiz[qq];
}
quiz_ave = qquiz_total/(q+1);
return quiz_ave;
}