You are to write a program that will do the following:
Part 1 (30 pts)

Grade a 30 multiple-choice question exam and print each student’s name
followed by the score (number of correct answers), the appropriate calculated
percentage score (number of correct answers divided by 30), and letter grade
for the exam. (Use the following percentage ranges for letter grades:
<60=F, 60-69=D, 70-79=C, 80-89=B, 90-100=A.)

I can't figure this out at all. I have started it though any suggestions to lead me in the right direction?

//Izabella Pearson
//CIS 150
//Program 7

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{

ifstream inFile;
ofstream outFile;

//Open input file

inFile.open ("p7.input.txt");    
outFile.open ("p7.output.txt");
if(!inFile)
    {
        cout << "Cannot open input file. "<<endl; // incase the file is not found
        cout << "Error: File can not open "<<endl;
        return 1;
    }

//Declare any variables
string student;
char key[31];
int grade;
int correct;
char answers[31];
char next;
int i=0;


while(!inFile.eof())
    {

    inFile.get(key, 31);
    inFile.get(answers, 31);
    inFile.get(next);
    outFile << next << endl;    

    if(answers!=key, i++)
    {

    }

    }

}

Hey,

Little confused, do you have to ask exam questions and the user answer OR are you given a .txt file with all their grades?

I'm given a txt file that looks like this

AACBEADDCEEBABECCDABECDAEBADCB
AABBEADDCEBBABECCDABECDAEBADCBHUDSON
ABBBBADDDEBBBBECCDABBCDAEBADCBWALLACE
AACBEADDCEEBABECCDABEDDDBEAAAAPOLLACK
AACBEADDCEEBABECCDABECDAEBADCBWILLIAMSON
BACBEADDCEEBABCCCDABCCDACBCCCCSCHMIDT
AACBEADDCEEBABECCDABECDAEBAAAALITTLE
AACBEADDDDDDABECCDABECDAEBADCBCARPENTER
AACAEADDCEEAAAECCDAAECDAEAADCAAHMED
AACBEADDCEEBABECCDABECDAEBADCBTURNER
ABCBBABBCBEBABBBBBABBCBABBADBBGEARHART
CCCBEADCCEEBCBECCDABECDAEBADCBASHTON
ABBBEADBCBEBBBEBCBABEDDEEEADCBWANG
AACBEADDCEEBABECCDABECDEEBACCBTRAINER
ACCCCADCCEBBCBBCCDABECDAEBADCBCARTER
ACAEBDADCEBEBACECDBACEDABEACDBBURROWS
AACBABDBCEBBABECBDCBCDDAEBADCBBROWNING
ACCBEBDDCECBABCCCDABECDAEBADCBMOPPET
AACBBBBDCEBBABECDDAAECDAEBADCBLAWSON
DACBEDDDCECCABECADAAECDABBCDCBBUMBAUGH
AACBEAABBDEBABDCBDABBCDDEBADCBLULLY
AACBAADBCEEBCBEBCDBBEADAABCBCBAPPLESON
DBCBDADDCBEBCBEACDCBEDDBEBADCBMULSOM

Hey, so what you need to do is parse in the different "Grades" store these inside an array (or a map, depending on whether you have been through these). You can then iterate through the array and check.. E.g.

#include <iostream>

using namespace std;

int returnGrade(char theGrade)
{
    switch(theGrade)
    {
        case 'A':
          return 90;
        break;

        default: return 0;

    }

}

int main(int argc, char *argv[]) {

    char grades[] = {'A', 'B', 'B', 'B', 'A', 'D'};
    int *grades_numeric = new int;
    int size = sizeof(grades)/sizeof(grades[0]);

    for(int i=0; (i < size); i++)
    {
        grades_numeric[i] = returnGrade(grades[i]);
    }

    cout << grades_numeric[0];

}

Hope this helps a bit :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.