Okay, so I was talking with my friend who's in a similar class, and he typed out almost the entire program, but he used classes and arrays, which we haven't learned yet. I was wondering if someone could clue me in if there was another way to write out parts of the program without using classes and arrays. I would use the program my friend half-wrote, but my professor would obviously know that I didn't do it myself. Here's part of the code he wrote...
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#define NDEBUG
#include <cassert>
#include <string>
using namespace std;
class Student {
public:
void setId(string num){ id_num = num; }
void setAnswers(string ans){ answer = ans; }
void setPercentage(float z){ percentage = z; }
void setGrade(string earned){ grade = earned; }
string queryAnswer(){ return answer; }
string queryGrade(){ return grade; }
string queryId(){ return id_num; }
float queryPercentage(){ return percentage; }
private:
string id_num;
string answer;
string grade;
float percentage;
};
void calculate_percentage(string, int, Student []);
int read_curve_file(ifstream &, int curve []);
void calculate_letter_grade(int [], int, Student []);
string index_to_grade(int);
void write_output_file(ofstream &, int, Student []);
int main()
{
// Declare variables
char inputfile[30]; // input file
string id, answers, key; // storage strings
do{
ifstream inData; // Input file of answers
ifstream grData; // Input file of grade curve
ofstream outData; // Output file of readings
Student data[100]; // Student class data
int array[5]; // Array for index
int i=0;
cout << "Enter the name of the file (or type 'exit' to quit): " << endl;
cin >> inputfile;
if(!strcmp(inputfile, "exit")) return 0;
inData.open(inputfile, ios::in);
if(!inData){ cout << "Error opening file." << endl; continue; }
inData >> key;
while (!inData.eof()){
inData >> id >> answers;
data[i].setId(id);
data[i].setAnswers(answers);
i++;
}
inData.close();
calculate_percentage(key, i, data);
read_curve_file(grData, array);
grData.close();
calculate_letter_grade(array, i, data);
write_output_file(outData, i, data);
outData.close();
} while(inputfile != "exit");
}