Welcome! Log In Create A New Profile

Advanced

Assignment 1 Question 2 & 3

Posted by core2000 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 1 Question 2 & 3
August 30, 2009 07:02AM
I have had some problems posting on the my.unisa boards so decided to transfer the discussion here.

The OP asked the following questions

K LUMAMBA

Please guys any one who has an idea about question 3, which code to compare the two input and mark, and question 4, how to number the lines.

Please assist.

(2009-08-18 12:01)

Chris Botha

=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt
Re: Assignment 1 Question 2 & 3
August 30, 2009 07:04AM
Question 3

Basically what I did was read the whole memorandum into an array and then use the array to compare the characters to the individual characters read one by one from the answer file intil I got to the last answer.

Something like this:

Language: C++
// Read in all the correct answers into an array.   for(int i = 0; i < ARRAY_SIZE; i++)   correctAnswerFile >> correctAnswerArray[i];

I then used a while loop to test for the end of file and compare and record the correct answers.

Finally, I used an if loop to test for the end of the answers using the ARRAY_SIZE constant for the test. In this cast the size is 50. If true, the program then reads the student ID and Name into two seperate variables and everything is then sent to the output file report.dat

The answer counter andd array counter is then zero'd and ready for the next student's info.

Something like this:

Language: C++
// Begin comparing the student answers to the memorandum answers in booklet.dat   while(!studentAnswerFile.eof())   {   char studentAnswer;   studentAnswerFile>> studentAnswer; //read the character into the variable   if(studentAnswer == correctAnswerArray[studentAnswerCounter++]) //compare answers   numberCorrectAnswers++; //add a mark   if(studentAnswerCounter == ARRAY_SIZE) //check for end of one student';s answers.   {

That's about it. the rest of the function does a straighforward output to the report.dat file and that's it. Remember to zero the studentAnswerCounter and numberCorrectAnswers variables.

Hope this helps.

Chris Botha

=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt
Re: Assignment 1 Question 2 & 3
August 30, 2009 07:16AM
Question 4

numbering the lines is pretty easy.

Language: C++
//Add the leading text and line number to the file and screen fOut<<count<<": "; cout<<count<<": ";


will work fine, just don't add an endl at the end and the line will be ready for the text.
Remember to number each line just before adding the text to the file or screen.
Do not try to add all the numbers first and then tthe text, it should all be done line by line.

Here are the test for the loops I used in my function
Language: C++
fIn.get(next);   while(! fIn.eof()) //Test for the end of the file   while(isspace(next)) //Remove the leading spaces     while(next != ';\n';) //Test for end of the line   if (fIn.eof()) //Tests for end of the file break; //Break the while loop if eof true

Chris Botha

=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt
Sorry, only registered users may post in this forum.

Click here to login