Join 149,856 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,348 people online right now. Registration is fast and FREE... Join Now!
Hello, I would like help in making this gradebook that teachers can use. I have most of it done. It's just not compiling right. I think I'm missing something but I can't figure it out. Basically, the instructions are as follows
The program has to process as many students as the file holds up to a predetermined maximum number (mine being 10), The system has to compute the average for each student, error check the grades for validity (A grade is considered invalid if it is negative), and write out the data to a text file.
I have to interact with the system through a simple command-based user interface.
The command include: S O and E.
- S: Sets up a new semester - system will take grades of assignments, quizzes, and the final. and calculate the average for each student. then print out the letter grade.
- O: Output grade data to a text file - The student number, and grade book data must be printed out to a file GRADEOUT. Format the data nicely, with appropriate labels.
- E: Exit system - Save all the student record data to the GRADEDAT file, and terminate the program.
CODE
#include <iostream> #include <iomanip> using namespace std;
//void computeStudAver(const int grade[][numQuiz], double stAve[]); //void computeQuizAver(const int grade[][numQuiz], double quizAve[]); //void printall(const int grade[][numQuiz],
int menu();
int main() { const int numStudents = 5, numQuiz = 10, numAssign = 10, numFinal = 1; const int totalGrades = 21; int grade[numStudents][numQuiz]; double stAve[numStudents]; double quizAve[numQuiz];
int choice = menu(); while(choice != 3) { choice = menu(); switch(choice) { case 1: cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue." inputgrades(); break;
case 2: printall(grade[][numQuiz], stAve[], quizAve[]); break;
int menu() { int choice; cout << "S. Start a new semester."<<endl; cout << "O. Output Data."<<endl; cout << "E. Exit"<<endl; cin >> choice; cout << endl << endl;; return choice; }
int calcgrade(double average, char& grade) { if (average <= 59) grade = 'F'; if (average <= 69 && average >= 60) grade = 'D'; if (average <= 79 && average >= 70) grade = 'C'; if (average <= 89 && average >= 80) grade = 'B'; if (average >= 90 && average <= 100) grade = 'A'; return 0; }
void inputgrades(const int grade[][totalGrades], int g[]) { cout << "How many grades will you add per student?"; cin >> quizN; for (g = 1; g <= quizN; g++;) cout << "Enter the students' grade: " << endl; cin >> g; }
void computeStudAver(const int grade[][numQuiz], double stAve[]) { for (int stN = 1; stN <= numStudents; stNum++) { double sum = 0; for (int quizNum = 1; quizNum <= numQuiz; quizNum++) sum = sum + grade[stNum-1][quizNum-1]; stAve[stNum-1] = sum/numQuiz; } }
void computeQuizAver(const int grade[][quizNum], double quizAve[]) { for (int quizNum = 1; quizNum <= numQuiz; quizNum++) { double sum = 0; for (int stN = 1; stN <= numStudents; stN++) sum = sum + grade[stN-1][quizNum-1] quizAve[quizNum-1] = sum/numStudents; } }
simplify the problems by moving main() to the end of the code (you had missing function prototypes) - you should then be able to figure out the remaining errors, e.g.
CODE
#include <iostream> #include <iomanip> using namespace std;
//void computeStudAver(const int grade[][numQuiz], double stAve[]); //void computeQuizAver(const int grade[][numQuiz], double quizAve[]); //void printall(const int grade[][numQuiz],
int menu();
int menu() { int choice; cout << "S. Start a new semester."<<endl; cout << "O. Output Data."<<endl; cout << "E. Exit"<<endl; cin >> choice; cout << endl << endl;; return choice; }
int calcgrade(double average, char& grade) { if (average <= 59) grade = 'F'; if (average <= 69 && average >= 60) grade = 'D'; if (average <= 79 && average >= 70) grade = 'C'; if (average <= 89 && average >= 80) grade = 'B'; if (average >= 90 && average <= 100) grade = 'A'; return 0; }
void inputgrades(const int grade[][totalGrades], int g[]) { cout << "How many grades will you add per student?"; cin >> quizN; for (g = 1; g <= quizN; g++;) cout << "Enter the students' grade: " << endl; cin >> g; }
void computeStudAver(const int grade[][numQuiz], double stAve[]) { for (int stN = 1; stN <= numStudents; stNum++) { double sum = 0; for (int quizNum = 1; quizNum <= numQuiz; quizNum++) sum = sum + grade[stNum-1][quizNum-1]; stAve[stNum-1] = sum/numQuiz; } }
void computeQuizAver(const int grade[][quizNum], double quizAve[]) { for (int quizNum = 1; quizNum <= numQuiz; quizNum++) { double sum = 0; for (int stN = 1; stN <= numStudents; stN++) sum = sum + grade[stN-1][quizNum-1] quizAve[quizNum-1] = sum/numStudents; } }
int main() { const int numStudents = 5, numQuiz = 10, numAssign = 10, numFinal = 1; const int totalGrades = 21; int grade[numStudents][numQuiz]; double stAve[numStudents]; double quizAve[numQuiz];
int choice = menu(); while(choice != 3) { choice = menu(); switch(choice) { case 1: cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue."; // ** added; inputgrades(); break;
case 2: printall(grade[][numQuiz], stAve[], quizAve[]); break;
OK, I did that and this is what I have fixed so far.
CODE
#include <iostream> #include <iomanip> using namespace std;
const int numStudents = 5, numQuiz = 10, numAssign = 10, numFinal = 1; const int totalGrades = 21; //void computeStudAver(const int grade[][numQuiz], double stAve[]); //void computeQuizAver(const int grade[][numQuiz], double quizAve[]); //void printall(const int grade[][numQuiz],
int menu(); int menu() { int choice; cout << "S. Start a new semester."<<endl; cout << "O. Output Data."<<endl; cout << "E. Exit"<<endl; cin >> choice; cout << endl << endl;; return choice; }
int calcgrade(double average, char& grade) { if (average <= 59) grade = 'F'; if (average <= 69 && average >= 60) grade = 'D'; if (average <= 79 && average >= 70) grade = 'C'; if (average <= 89 && average >= 80) grade = 'B'; if (average >= 90 && average <= 100) grade = 'A'; return 0; }
void inputgrades(const int grade[][totalGrades], double g[]) { int quizN; cout << "How many grades will you add per student?"; cin >> quizN; for (int i = 0; i <= quizN; i++) { cout << "Enter the students' grade: " << endl; cin >> g[i]; } }
void computeStudAver(const int grade[][numQuiz], double stAve[]) { int stNum; for (int stN = 1; stN <= numStudents; stNum++) { double sum = 0; for (int quizNum = 1; quizNum <= numQuiz; quizNum++) sum = sum + grade[stNum-1][quizNum-1]; stAve[stNum-1] = sum/numQuiz; } }
void computeQuizAver(const int grade[][numQuiz], double quizAve[]) { for (int quizNum = 1; quizNum <= numQuiz; quizNum++) { double sum = 0; for (int stN = 1; stN <= numStudents; stN++) sum = sum + grade[stN-1][quizNum-1]; quizAve[quizNum-1] = sum/numStudents; } }
int main() { int grade[numStudents][numQuiz]; double stAve[numStudents]; double quizAve[numQuiz];
int choice = menu(); while(choice != 3) { choice = menu(); switch(choice) { case 1: cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue."; // ** added; inputgrades(); break;
case 2: printall(grade[][numQuiz], stAve[], quizAve[]); break;
These are the errors I got in compiling. In function `void printall(const int (*)[10], const double*, const double*)': 84: error: aggregate `std::ofstream outFile' has incomplete type and cannot be defined
In function `int main()': 50: error: too few arguments to function `void inputgrades(const int (*)[21], double*)' 114: error: at this point in file 118: error: expected primary-expression before ']' token 118: error: expected primary-expression before ']' token 118: error: expected primary-expression before ']' token
I don't know what's wrong up to this point.
This post has been edited by pngrafxx126: 23 Feb, 2007 - 05:41 AM
In function `void printall(const int (*)[10], const double*, const double*)': 84: error: aggregate `std::ofstream outFile' has incomplete type and cannot be defined
1. You need to include <fstream>
CODE
#include <fstream>
2. It's not necessary, but I would suggest giving ofstream a value.
CODE
ofstream outFile ("data.txt");
That way, it calls the .open() function as a part of the constructor.
This post has been edited by qdoom: 23 Feb, 2007 - 06:38 AM
fix the fstream as indicated by qdoom - in addition you define inputgrades() with parameters
CODE
void inputgrades(const int grade[][totalGrades], double g[]) {
but call it without parameters
CODE
case 1: cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue."; // ** added; inputgrades(); <<<<<< ?????? break;
int main() { int grade[numStudents][numQuiz]; double stAve[numStudents]; double quizAve[numQuiz];
//choice = menu(); //while(choice != 3) //{ char choice; switch(choice) { case "S": // line 104 case "s": // line 105 cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue."; // ** added; inputgrades(); break;
case "O": // line 110 case "o": // line 111 printall(grade, stAve, quizAve); break;
(104) : error C2051: case expression not constant (105) : error C2051: case expression not constant (110) : error C2051: case expression not constant (111) : error C2051: case expression not constant (118) : warning C4065: switch statement contains 'default' but no 'case' labels Error executing cl.exe.
gradebook.obj - 4 error(s), 1 warning(s)
This post has been edited by pngrafxx126: 23 Feb, 2007 - 09:31 AM
this is an simple/hard to catch mistake. your code:
CODE
switch(choice) { case "S": // line 104 case "s": // line 105 cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue."; // ** added; inputgrades(); break;
case "O": // line 110 case "o": // line 111 printall(grade, stAve, quizAve); break;
what needs to change is the " you have in the case statement they should be '
like this:
CODE
switch(choice) { case 'S': // line 104 case 's': // line 105 cout << "Welcome. You have started a new semester! To start the grading process, press any key to continue."; // ** added; inputgrades(); break;
case 'O': // line 110 case 'o': // line 111 printall(grade, stAve, quizAve); break;
Yeh, I realized that lol. I fixed it before you posted, thanks anyway.
The problem I'm having now is inputting the grades into memory.
That's 5 grades for each of the 10 students. My program isn't working the way I want it to. I don't know what's wrong. If anyone can discuss this with me. Please AIM me @ pinoyngraphix.
This program is giving me a really hard time now.
This post has been edited by pngrafxx126: 23 Feb, 2007 - 10:15 AM
Well when you run my program. It gives you the right choices and everything. It's just that when you choose S it doesn't do the desired behavior.
The behavior is as follows: - Choosing S should start a new semester. - The cmd then asks the user for how many quizzes. Given the amount it loops right, but I can't get each grade to stay in memory for the output and add each score to the previous quiz grade for a quiz total. The quiz grade taken is then averaged and then weighted to the grading scales.
The scales is Final = 35% grade, Assignments = 40%, and Quiz Grades = 25% to equal 100%.
After the quiz grades are taken, it should then ask for how many assignments there are. The loop works, but again the problem here is I can't get the score to stay in memory for the output and also add each assignment grade to the previous. The total assignment grades is again, averaged and then put into the scales.
The Final is the same. It asks for the grade and then scales it.
The ending result should be a data.txt file in an array format (which I'm sure I formatted right). It is supposed to show a data array of each student (1-10) with their corresponding grades from left to right in chronological order, and at the bottom would be their quiz averages. Their real letter grade and the average of each student would be at the bottom of the table, and the student average should be at the end of each row of student grades.
-----> My code consists of all the necessary functions, the problem with my program is it doesn't flow and the program terminates. If you don't get what I mean. Compile the code yourself and see what you get.
CODE
#include <iostream> #include <iomanip> #include <fstream> using namespace std;
const int numStudents = 5, numQuiz = 10, numAssign = 10, numFinal = 1; const int totalGrades = 21; //void computeStudAver(const int grade[][numQuiz], double stAve[]); //void computeQuizAver(const int grade[][numQuiz], double quizAve[]); //void printall(const int grade[][numQuiz],
I'm a little surprised that the code compiles. You have two main functions declared. another are of concern is that you seem to be using a variable name qsum in your inputgrades() function, but the variable is not set in the function scope, nor is it declared at a global level. you are also calling your main function from your menu function, which is not a good idea - the main function should be the single program entry point.