need help as a c++ beginner; just a few questions with code and everything in here!
hello everyone
the project is to make a program that grades several multiple-choice exams. The exam has less than 80 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on several files such as exam1.dat.
A typical input exam data file (exam1.dat) looks like:
Quote:
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
in which the first line is the key, consisting of a string of n characters (0<n < 80). The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of n characters.
the program has a capability of repeatedly asking for a new data file in each while loop until users input a key word “exit”. Once “exit” is encountered, the while loop terminates and the program ends. this is one of the parts i am stuck on. where and how do i put an exit command or option? like i wanna say: if something, cin exit...i doubt that right, so ya, how do i do this? and where do i put it in my code? i know it has to be in the while loop right?
we have to apply the length( ) of string to the first line of the above data file for determining the number of questions in the problem. since we have to make several functions, i decided to make a infile/outfile function as seen, and i wanna make a length function. however, i dont know how to do the length function. i am sure its something like void size, since i call the function "length.size" but what do i put inside it besides the loop? If a student gives more answers than needed, the extra answers will be automatically cut. if a student provides less number of answers, the remaining unanswered questions are considered incorrect. i kinda get the idea behind this and i seen a few examples, but its like not able to form from my head. some guidance on this part would be appreciated as well :)
After users input an exam data file, the program asks users to input another grade-curving file name (e.g., gradeCurving.dat). This second file contains the information to convert a percentile score to a curved grade in levels of ‘A’ through ‘E’.
Quote:
A 90
B 80
C 70
D 60
E 50
the program asks users to input an output file name such as score1.dat. The output file will store the scores for each student in a format: student ID number, a space, a percentile score, and a curved grade in ‘A’ though ‘E’. which i have done as seen in the code. The program should also compute and display the following statistics for the graded answers: Average score, Maximum score, and Minimum score. i need help on this part...how do i make average max and min? i never got the idea in class and all the time i needed assistant on this part. what easy way to know how? example or project example might help
output on a data file looks like:
Quote:
1234567 90% A
9876543 85% B
5554446 95% A
4445556 75% C
5551112 80% B
Statistics:
Average Score: 85%
Minimum Score: 95%
Maximum Score: 75%
and here is my code so far
Code:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
void openfiles(ifstream& infile, ofstream& outfile);
void size();
int main()
{
int num_student = 4, count, length, score2, w[6];
ifstream infile, curvingfile; char x;
ofstream outfile; float score;
string key, answer, id;
do {
openfiles(infile, outfile); // function calling
infile >> key; // answer key
for (int i = 0; i < num_student; i++) // loop over each student
{
infile >> id;
infile >> answer;
count = 0;
length = key.size(); // length represents number of questions in exam from exam1.dat
// size is a function....
for (int j = 0; j < length; j++) // loop over each question
{
if (key[j] == answer[j])
count++;
}
score = (float) count / length;
score2 = (int)(score * 100);
outfile << id << " " << score2 << "%";
if (score2 > 90)//<-----w[0]
outfile << "A" << endl;
else if (score2 > 80)//<-----w[1]
outfile << "B" << endl;
else if (score2 > 70)//<-----w[2]
outfile << "C" << endl;
else if (score2 > 60)//<-----w[3]
outfile << "D" << endl;
}
cout << "Would you like to attempt a new trial? (y/n): ";
cin >> x;
} while (x == 'y' || x == 'Y');
return 0;
}
void openfiles(ifstream& infile, ofstream& outfile)
{
string name1, name2, name3;
cout << "Input the name for the exam file: ";
cin >> name1;
infile.open(name1.c_str());
cout << "Input the name for the curving file: ";
cin >> name2;
infile.open(name2.c_str());
cout << "Input the name for the output: ";
cin >> name3;
outfile.open(name3.c_str());
}
***i hope its right asking here. it may be a bit extra questions, but hey. its only my first 2 months introduced to programming and i am already at such advanced stuff. i wish i knew how the class will turn out to be so i would have watched tutorials at least from the summer and got some idea before hand. i didnt even know the class is gonna be c++ programming. i thought its like general computer information. so yea. i appreaciate any help in advanced! who knows, one day i am sure ill become someone who'll be helping back....***