?

Log in

No account? Create an account

Previous Entry | Next Entry

Group meeting and... C++ stuff

Gak! Can't they talk about anything other than guys, clothes, drinking .. aiye... I was like :: leaf through books nonchalantly, calmly ignoring them, only looking up to throw a glare if they get too loud::

Dang C++, majorly stuck in a couple of places...the more I think about it logically, it makes sense, but then I forget to include an essential element of the program and it all goes boom... :: rip hair out::

#include < stdio.h >
#include < stdlib.h >
#include < iostream.h >
#include < fstream.h >
#include < string.h >

//------------------------ Global data definitions -----------------------------
struct studentInfo{
char* studentId;
char* answers;
int score;
int wrongAnswers;
int correctAnswers;
char grade;
};

studentInfo* data;
int noOfStudents;
int noOfQuestions;
char* examAnswers;
//---------------------------------------------------------------------------
void initilizeAllVariables(){
data = new studentInfo[noOfStudents];
for (int i=0; i< noOfStudents;i++){
data[i].studentId = new char[8];
data[i].answers = new char[noOfQuestions];
data[i].score = 0;
data[i].wrongAnswers =0;
data[i].correctAnswers =0;
}
//---------------------------------------------------------------------------
void cleanUpMemory(){
// Clean up all the memory allocated. This function is called when the
// program is done
}
//---------------------------------------------------------------------------
void readFirstLineInputFile(ifstream& ins){
ins >> noOfStudents;
ins >> noOfQuestions;
int i;
examAnswers = new char [noOfQuestions];
for (i=0; i< noOfQuestions; i++)
ins >> examAnswers[i];
}
//---------------------------------------------------------------------------
void readStudentsAnswers(ifstream& ins){
// Read the rest of the file and store the answers of each students
}
//---------------------------------------------------------------------------
void computeScores(){
// Compute the score for each student
}
//---------------------------------------------------------------------------
char computeExamGrade(int score){
// This method return the corresponding grade for each score
}
//---------------------------------------------------------------------------
void writeOutput(ofstream& outs){
// Open the output file
// Write statistics and close the file
// The file name should be result.txt and is stored in
// the current directory
}
//---------------------------------------------------------------------------

int main(int argc, char* argv[])
{
ifstream infile;
ofstream outfile;

if (argc < 2){
cout << "input file name was not specified in the command line!" << endl;
cout << "the correct way to execute the program is as follows:" << endl;
cout << "\t\t Programname inputfilename \n";
return 1;
}else {

infile.open(argv[1]);
if(!infile)
{
cout<<"Cannot open input file. Program terminates!"<<endl; return 1; } readFirstLineInputFile(infile); initilizeAllVariables(); readStudentsAnswers(infile); computeScores(); writeOutput(outfile); cleanUpMemory(); } } I suck at programming.... :: grumble ::

Latest Month

October 2007
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
28293031   
Powered by LiveJournal.com
Designed by Gilbert Rizo