Student 1
7 quiz scores 9 9.33 8 10 5.5 8 10 ==> the 5.5 score should be dropped, returned value: 90.55
6 project scores 20 47.5 47 45 47.5 48 ==> returned value: 94.44
2 exam scores 83 87 ==> returned value: 85.00
14 lab scores 100 98 96 100 98 92 88 96 92 86 92 94 100 96 ==> returned value 94.86
heres what I got:
Expand|Select|Wrap|Line Numbers
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- using namespace std;
- //Structure for holding all the grades
- struct MyGrades
- {
- string student;
- float quizzes[7];
- float projects[6];
- float exams[2];
- float labs[14];
- };
- const int tot_quiz = 7;
- const int tot_proj = 6;
- const int tot_exam = 2;
- const int tot_labs = 14;
- const int tot_quiz_pts = 70;
- const int tot_proj_pts = 300;
- const int tot_exam_pts = 200;
- const int tot_lab_pts = 150;
- double ret_avg(float scores, int num_scores, int tot_pts);
- int main()
- {
- // outputting the correct format for all the averages to go
- cout << "No. -Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade"
- << endl;
- cout << "--- ----------- -------- ---------- ------ ----- ------- -----"
- << endl;
- cout << endl;
- int student_number = 1; //counter for number of students
- ifstream in_file;
- MyGrades Grades; //declare an instance of a Grades struct
- in_file.open("grades.txt"); //opening the grades.txt file
- if(in_file.fail()) //if function to make sure the file opened
- {
- cout << "Input file failed to open.\n";
- exit(1);
- }
- while (in_file >> Grades.student) // reads in a string into a variable
- {
- //reads in all the grades into each seperate array
- in_file >> Grades.quizzes[0] >> Grades.quizzes[1] >>
- Grades.quizzes[2] >> Grades.quizzes[3] >> Grades.quizzes[4] >>
- Grades.quizzes[5] >> Grades.quizzes[6] >> Grades.projects[0] >>
- Grades.projects[1] >> Grades.projects[2] >> Grades.projects[3] >>
- Grades.projects[4] >> Grades.projects[5] >> Grades.exams[0] >>
- Grades.exams[1] >> Grades.labs[0] >> Grades.labs[1] >>
- Grades.labs[2] >> Grades.labs[3] >> Grades.labs[4] >>
- Grades.labs[5] >> Grades.labs[6] >> Grades.labs[7] >>
- Grades.labs[8] >> Grades.labs[9] >> Grades.labs[10] >>
- Grades.labs[11] >> Grades.labs[12] >> Grades.labs[13];
- cout << " " << student_number << ". " << Grades.student << " "<<\
- ret_avg(Grades.quizzes, tot_quiz, tot_quiz_pts) << endl;
- student_number++;
- }
- }
- double ret_avg(float* scores, int num_scores, int tot_pts)
- {
- double sum = 0;
- double avg = 0;
- for (int i = 0; i < num_scores; i++)
- {
- scores[i] += sum;
- }
- avg = sum / tot_pts;
- return (avg * 100);
- }
In function `int main()':
grader.cpp:71: error: cannot convert `float*' to `float' for argument `1' to `double ret_avg(float, int, int)'
and heres the output when run without calling the function in the cout
Expand|Select|Wrap|Line Numbers
- No. -Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade
- --- ----------- -------- ---------- ------ ----- ------- -----
- 1. Smith
- 2. Jones