Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
Assignment 1, Semester 2, Q3 July 15, 2009 05:32PM |
Registered: 14 years ago Posts: 2 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 16, 2009 08:43AM |
Registered: 16 years ago Posts: 2,075 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 16, 2009 12:45PM |
Registered: 14 years ago Posts: 2 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 16, 2009 01:09PM |
Registered: 16 years ago Posts: 2,075 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 21, 2009 12:45PM |
Registered: 14 years ago Posts: 2 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 23, 2009 12:33PM |
Registered: 16 years ago Posts: 68 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 23, 2009 01:15PM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 24, 2009 12:53PM |
Registered: 16 years ago Posts: 68 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 27, 2009 10:34AM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 29, 2009 10:10AM |
Registered: 16 years ago Posts: 68 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 30, 2009 01:19PM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 30, 2009 04:49PM |
Registered: 14 years ago Posts: 8 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 30, 2009 04:51PM |
Registered: 14 years ago Posts: 8 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 31, 2009 10:50AM |
Registered: 16 years ago Posts: 68 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 July 31, 2009 04:23PM |
Registered: 14 years ago Posts: 8 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 02, 2009 11:26AM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Open answer file. Extract all the answers into an array. close answer file. for each student open student answers for each student answer compare each answer with the answer array and count those correct. close student file.
Re: Assignment 1, Semester 2, Q3 August 03, 2009 11:25AM |
Registered: 16 years ago Posts: 68 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 04, 2009 02:58PM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 04, 2009 02:59PM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 04, 2009 03:02PM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 04, 2009 04:10PM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 05, 2009 02:37PM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 05, 2009 07:55PM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Language: C++#include <iostream> #include <fstream> #include <string> using namespace std; int main(){ ifstream fin1; ifstream fin2; ofstream fout; fin1.open("booklet.dat"); if(fin1.fail()){ cout << "Input file1 opening failed.\n"; exit(1); } fin2.open("answer.dat"); if(fin1.fail()){ cout << "Input file2 opening failed.\n"; exit(1); } fout.open("studentAnswer.dat"; if(fin1.fail()){ cout << "Input file opening failed.\n"; exit(1); } char studAnswer; string name; int count = 1, answerCounter = 0, studCard; const int ARRAY_SIZE = 50; char arrayAnswer[ARRAY_SIZE]; for(int i = 0; i < ARRAY_SIZE; i++) fin2 >> arrayAnswer[i]; fin2.close(); while(!fin1.eof()){ fin1 >> studAnswer; if(studAnswer == arrayAnswer[count - 1]) answerCounter++; if(count == ARRAY_SIZE){ fin1 >> studCard >> name; fout << studCard << " " << name << " " << answerCounter << endl; answerCounter = 0; count = 0; } count++; } fin1.close(); fout.close(); return 0; }
Re: Assignment 1, Semester 2, Q3 August 05, 2009 09:11PM |
Registered: 18 years ago Posts: 1,424 Rating: 0 |
Language: C++#include <iostream> #include <fstream> #include <string> using namespace std; int main(){ // read in all the model answers const int ARRAY_SIZE = 50; char arrayModelAnswers[ARRAY_SIZE]; ifstream modelAnswerFile; modelAnswerFile.open("answer.dat"); if(modelAnswerFile.fail()){ cout << "Failed to open the model answer file.\n"; return -1; // error opening file, abort program } for(int i = 0; i < ARRAY_SIZE; i++) modelAnswerFile >> arrayModelAnswers[i]; modelAnswerFile.close(); ifstream studentAnswerFile; studentAnswerFile.open("booklet.dat"); if(studentAnswerFile.fail()){ cout << "Failed to open the student answer file.\n"; return -1; // error opening file, abort program } ofstream studentResultsFile; studentResultsFile.open("studentAnswer.dat"); if(studentResultsFile.fail()){ cout << "Failed to open the results file.\n"; return -1; // error opening file, abort program } // Compare the student';s answers to the model int count = 0, answerCounter = 0; while(!studentAnswerFile.eof()){ char studAnswer; studentAnswerFile >> studAnswer; if(studAnswer == arrayAnswer[count++]) answerCounter++; if(count == ARRAY_SIZE){ // all answers have been read. store the results string name; int studCard; studentAnswerFile >> studCard >> name; studentResultsFile << studCard << " " << name << " " << answerCounter << endl; answerCounter = 0; count = 0; } } studentAnswerFile.close(); studentResultsFile.close(); return 0; }
Re: Assignment 1, Semester 2, Q3 August 07, 2009 01:36PM |
Registered: 15 years ago Posts: 152 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 21, 2009 09:33AM |
Registered: 14 years ago Posts: 2 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 August 21, 2009 03:26PM |
Registered: 15 years ago Posts: 34 Rating: 0 |
Language: C++// Assignment 1 // Question 3 #include <fstream> #include <iostream> #include <cstdlib> #include <string> using namespace std; const int numQuestion = 50; // to calculate mark void markTotal ( char stud_answP[], char answP[], int & totalP) { for (int i = 0; i < numQuestion; i++) { if ( answP == stud_answP) { totalP ++; } } } int main() { int total = 0; char stud_answ [numQuestion]; char answ[numQuestion]; int stud_nr; string name; ifstream fromFile, fromFile2; ofstream toFile; fromFile.open("booklet.dat"winking smiley; if (fromFile.fail()) { cout <<"Input file opening failed." << endl; exit (1); } fromFile2.open("answer.dat"winking smiley; if (fromFile2.fail()) { cout <<"Input file opening failed." << endl; exit (1); } toFile.open( "total.dat", ios::app); if (toFile.fail()) { cout <<"Input file opening failed." << endl; exit (1); } cout <<"Files opened successful." << endl; cout << endl; for (int i = 0; i < numQuestion; i++) { fromFile >> answ; } cout <<"Data transfered." << endl; cout <<"Data Printed to file: " << endl; cout <<"================================================" << endl; while (!fromFile2.eof()) { for (int i = 0; i < numQuestion; i++) { fromFile2 >> stud_answ; } fromFile2 >> stud_nr >> name; markTotal (stud_answ, answ, total); // Output toFile << total << " " << stud_nr << " " << name << endl; cout << total << " " << stud_nr << " " << name << endl; } cout <<"================================================" << endl; cout << endl; cout <<"Total outputed to file." << endl; fromFile.close(); fromFile2.close(); toFile.close(); cout <<"File Created." << endl; return 0; }
Re: Assignment 1, Semester 2, Q3 August 21, 2009 04:44PM |
Registered: 15 years ago Posts: 34 Rating: 0 |
Language: C++// Assignment 1 // Question 3 #include <fstream> #include <iostream> #include <string> using namespace std; const int numQuestion = 50; // to calculate mark void markTotal ( char stud_answP[], char answP[], int & totalP) { totalP = 0; for (int i = 0; i < numQuestion; i++) { if ( answP[i] == stud_answP[i]) //Added i counter variable to move along the arrays totalP ++; } } //------------------------------------------------------ int main() { int total = 0; char stud_answ [numQuestion]; char answ[numQuestion]; int stud_nr; string name; ifstream fromFile, fromFile2; ofstream toFile; fromFile.open("booklet.dat"); if (fromFile.fail()) { cout <<"Input file opening failed." << endl; exit (1); } fromFile2.open("answer.dat"); if (fromFile2.fail()) { cout <<"Input file opening failed." << endl; exit (1); } toFile.open( "total.dat"); //removed the ios append parameter if (toFile.fail()) { cout <<"Input file opening failed." << endl; exit (1); } cout <<"Files opened successful." << endl; cout << endl; //--------------------------------------------------------- for (int i = 0; i < numQuestion; i++) fromFile >> answ[i]; //Added i counter variable to move along the arrays cout <<"Data transfered." << endl; cout <<"Data Printed to file: " << endl; //This lne is not actually true yet so should be moved cout <<"================================================" << endl; while (!fromFile2.eof()) { for (int i = 0; i < numQuestion; i++) { fromFile2 >> stud_answ[i]; //Added i counter variable to move along the arrays } fromFile2 >> stud_nr >> name; markTotal (stud_answ, answ, total); // Output toFile << total << " " << stud_nr << " " << name << endl; cout << total << " " << stud_nr << " " << name << endl; } cout <<"================================================" << endl; cout << endl; cout <<"Total outputed to file." << endl; fromFile.close(); fromFile2.close(); toFile.close(); cout <<"File Created." << endl; return 0; }
Re: Assignment 1, Semester 2, Q3 August 21, 2009 05:15PM |
Registered: 14 years ago Posts: 2 Rating: 0 |
Re: Assignment 1, Semester 2, Q3 December 04, 2009 03:26PM |
Registered: 15 years ago Posts: 13 Rating: 0 |