Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
We have to create a coursework system where the student uploads an assignment to be graded. Once the professor grades it the student can look at what they got and also see comments made by the professor... kind of like how my school has us submit our assignments online to be graded... so from that I have some code. But I got so confused mainly because iI'm in software engineering(400 level course) but just now taking c++. How can I convert this into a form would that be easier?? well here is the code


C++
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

const int numStudents = 25, numQuiz = 30, numAssign = 30, numFinal = 1, nummidterm = 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 main();

int menu()
{
    char choice;
    cout << "N. New Semester."<<endl;
    cout << "O. Output Data."<<endl;
    cout << "E. Exit"<< endl << endl;
    cin >> choice;
    cout << endl << endl;
    return choice = main();
}

int calcgrade(double average, char& grade)
{
    if (average <= 59)
    grade = 'F';
    else if (average <= 69 && average >= 60)
    grade = 'D';
    else if (average <= 79 && average >= 70)
    grade = 'C';
    else if (average <= 89 && average >= 80)
    grade = 'B';
    else if (average >= 90 && average <= 100)
    grade = 'A';
    return 0;
}

//void scales() { // midterm= 25%; Final = 25%; Quizzes = 25%; Assignments = 25%
//    int quiz = .25 * qgrade = double q


void inputgrades() {
    char fanswer;
    int quizN, assignG, final,midterm,;
    double qgrade[4], agrade[4], fgrade[1],mgrade[1]qsum;

    cout << "How many quiz grades will you add per student?";
    cin >> quizN;
    for (int i = 1; i <= quizN; i++) {
         cout << "Enter quiz grade: " << endl;
         cin >> ++qgrade[i];
    qsum =+qgrade[i];
    }

    cout << "How many assignment grades will you add per student?";
    cin >> assignG;
    for (int i = 1; i <= assignG; i++) {
         cout << "Enter assignment grade: " << endl;
         cin >> agrade[i];
    }
   cout << "Is there a midterm?";
    cin >> manswer;
    if (manswer == 'y' || manswer == 'Y') {
         cout << "Enter midterm grade: " << endl;
         cin >> mgrade[1];
    }
    cout << "Is there a final?";
    cin >> fanswer;
    if (fanswer == 'y' || fanswer == 'Y') {
         cout << "Enter final grade: " << endl;
         cin >> fgrade[1];
    }

    //scales();
}

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;
     }
}

void printall(const int grade[][numQuiz], const double stAve[], const double quizAve[]) {
     cout.setf(ios::fixed);
     cout.setf(ios::showpoint);
     cout.precision(1);

     ofstream outFile ("GRADEDATA.txt");

     outFile.open("C:\\Documents and Settings\\USER\\Desktop\\output1.txt");
     outFile << setw(10) << "Student" << setw(5) << "Average" << setw(15) << "Quizzes\n";
     for (int stN = 1; stN <= numStudents; stN++) {
              cout << setw(10) << stN << setw(5) << stAve[stN-1] << " ";
         for (int quizNum = 1; quizNum <= numQuiz; quizNum++)
             cout << setw(5) << grade[stN-1][quizNum-1];
         cout << endl;
         }

     cout << "Quiz averages = ";
     for (int quizNum = 1; quizNum <= numQuiz; quizNum ++)
         cout << setw(5) << quizAve[quizNum-1];
     cout << endl;
}

int main()
{
    int grade[numStudents][numQuiz];
    double stAve[numStudents];
    double quizAve[numQuiz];

    char choice;
    cout << "N.New semester."<<endl;
    cout << "O. Output Data."<<endl;
    cout << "E. Exit"<< endl << endl;
    cin >> choice;
    cout << endl << endl;

        switch(choice)
        {
        case 'N':
        case 'n':
            cout << "Welcome. You have begun a new semester!\n";
            inputgrades();
            break;

        case 'O':
        case 'o':
            printall(grade, stAve, quizAve);
            break;

        case 'E':
        case 'e':
            cout << "Quitting..." << endl;
            break;

        default:
            cout << "You must pick one to continue!" << endl;
            break;
        }

    computeStudAver(grade, stAve);
    computeQuizAver(grade, quizAve);
    printall(grade, stAve, quizAve);
    getche();
    return 0;
}


[modified: removed an extra pre tag...also fixed some spelling errors, dangling modifiers, and run-on sentences.]

[MOVED FROM OP ANSWER]
A coursework submission system
This system should manage the electronic submission of assignments from students to instructors. It should keep track of which students have submitted assignments and should allow instructors to manage the grading of assignments. It should provide summaries of student grades and facilities for electronically returning information to students. You might consider some kind of annotation system where instructors could comment on electronic versions of students' work. If you cover security in your courses, you could include encryption facilities in the system.
Posted
Updated 15-Feb-11 9:27am
v3
Comments
William Winner 15-Feb-11 14:45pm    
Is this supposed to be an online submission system? Or are you creating an application that everyone will have to install on their computer and it uploads to and accesses a SQL database somewhere?
Yusuf 15-Feb-11 15:28pm    
Moved your description from Answer to the bottom of your question

1 solution

It is not related to your actual question, but it is a problem none the less.
Double numbers can have decimal places, hence the following code will not work correctly
int calcgrade(double average, char& grade)
{
    if (average <= 59)
    grade = 'F';
    else if (average <= 69 && average >= 60)
    grade = 'D';
    else if (average <= 79 && average >= 70)
    grade = 'C';
    else if (average <= 89 && average >= 80)
    grade = 'B';
    else if (average >= 90 && average <= 100)
    grade = 'A';
    return 0;
}


If the students score was 89.5 for example, the student would not be graded.
Your code should read:
int calcgrade(double average, char& grade)
{
    if (average < 60)
        grade = 'F';
    else if (average < 70) //If we get to here, then the score is >=60 so no need to check it again
        grade = 'D';
    else if (average < 80) //If we get to here, then the score is >=70 so no need to check it again
        grade = 'C';
    else if (average < 90) //If we get to here, then the score is >=80 so no need to check it again
        grade = 'B';
    else 
        grade = 'A'; //If we get to here, then the score is >=90. A score of more than 100, if allowed should also be graded A.
    return 0; //Why are you returning anything? It never changes.
}


Note that the above code is still vulnerable to epsilon errors[^].
In short, a computer cant store numbers to infinite accuracy, and hence the number 90.0 may be stored as 89.999999999999999999 and hence would be graded as a B, although when printed to 2 or 3 decimal places it is 90.00.
There are macros FLT_EPSILON and DLB_EPSILON which should be added to each test.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900