#include<iostream>
#include<iomanip>
#include<cstdlib>
using namespace std;
struct STUDENT_STRUCT
{
char last_name[31];
char first_name[31];
char soc_sec_no[10];
char ph_no[11];
int quiz_1;
int quiz_2;
int quiz_3;
int quiz_4;
int quiz_5;
int quiz_avg;
int final_exam;
int final_grade;
};
int Load_Student_Table(STUDENT_STRUCT[], int);
void Display_Student_Table(STUDENT_STRUCT[], int);
int Calc_Quiz_avg(STUDENT_STRUCT[], int);
int Calc_Final_Grade(STUDENT_STRUCT[], int);
const int TABLE_SIZE = 25;
int main()
{
STUDENT_STRUCT student_table[TABLE_SIZE];
cout << setprecision(2)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
int num_students;
num_students=Load_Student_Table(student_table, TABLE_SIZE);
// Display the table
cout << endl << endl;
cout << "This is the table you entered. ";
Display_Student_Table(student_table, num_students);
cout << endl << endl;
cout << "Last Name"
<< "First Name"
<< "Social Security Number"
<< "Phone Number"
<< "Quiz 1"
<< "Quiz 2"
<< "Quiz 3"
<< "Quiz 4"
<< "Quiz 5"
<< "Final Exam"
<< "Quiz Average"
<< "Final Grade" << endl;
return 0;
}
int Load_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
int row=0;
int response=1;
cout << endl;
cout << "Enter the table values as you are prompted:"
<< endl << endl;
while(response==1)
{
cout << endl;
cout << "For row #" << row+1 << " enter:" << endl;
cout << "Last Name: ";
cin.get();
cin.getline(student_table[row].last_name, 31);
cout << "First Name: ";
cin.getline(student_table[row].first_name, 31);
cout << "Social Security Number: ";
cin.getline(student_table[row].soc_sec_no, 10);
cout << "Phone Number: ";
cin.getline(student_table[row].ph_no, 11);
cout << "Quiz 1: ";
cin >> student_table[row].quiz_1;
cout << "Quiz 2: ";
cin >> student_table[row].quiz_2;
cout << "Quiz 3: ";
cin >> student_table[row].quiz_3;
cout << "Quiz 4: ";
cin >> student_table[row].quiz_4;
cout << "Quiz 5: ";
cin >> student_table[row].quiz_5;
cout << "Final Exam: ";
cin >> student_table[row].final_exam;
row++;
cout<<"Do you wish to enter another student? Enter 1 for yes or 0 for no: "<<endl;
cin>>response;
}
return row;
}
int Calc_Quiz_Avg(STUDENT_STRUCT student_table[])
{
const int num_quizzes=5;
int quiz_1=0;
int quiz_2=0;
int quiz_3=0;
int quiz_4=0;
int quiz_5=0;
int quiz_avg=(quiz_1+quiz_2+quiz_3+quiz_4+quiz_5)/5;
return quiz_avg;
}
int Calc_Final_Grade(STUDENT_STRUCT student_table[])
{
int final_exam=0;
int quiz_avg=0;
const double QUIZ_AVG_WEIGHT=0.75;
const double FINAL_EXAM_WEIGHT=0.25;
int final_grade;
final_grade=QUIZ_AVG_WEIGHT*quiz_avg + FINAL_EXAM_WEIGHT*final_exam;
return final_grade;
}
void Display_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
int row;
cout << endl << endl;
cout << "Last Name"
<< "First Name"
<< "Social Security Number"
<< "Phone Number"
<< "Quiz 1"
<< "Quiz 2"
<< "Quiz 3"
<< "Quiz 4"
<< "Quiz 5"
<< "Final Exam"
<< "Quiz Average"
<< "Final Grade" << endl;
for(row=0; row<num_students; ++row)
{
cout << endl;
cout << student_table[row].last_name
<< student_table[row].first_name
<< student_table[row].soc_sec_no
<< student_table[row].ph_no
<< student_table[row].quiz_1
<< student_table[row].quiz_2
<< student_table[row].quiz_3
<< student_table[row].quiz_4
<< student_table[row].quiz_5
<< student_table[row].final_exam
<< student_table[row].quiz_avg
<< student_table[row].final_grade << endl;
}
}
EDIT:Added code tags
This post has been edited by Dark_Nexus: 26 August 2006 - 09:54 AM

New Topic/Question
Reply



MultiQuote

|