0% found this document useful (0 votes)
3 views5 pages

Cos 1511 May 2011 Memo

Uploaded by

j.prokopes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Cos 1511 May 2011 Memo

Uploaded by

j.prokopes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

1 COS1511/COS111U memorandum May 2011

COS1511/COS111U MEMORANDUM MAY 2011

NB: Please make a tick for each mark – it is required by the new assessment
procedure, i.e. if the student obtains 7/10 for a question, there should be 7 √’s

These answers are guidelines. Please give marks for correct logic, even if
answered different to the solutions. If needed, write a note to the moderator of
how marks were given in this case.

Do not subtract marks for the same error twice in the same question. (especially
question 3)

SECTION A 20 marks

Question 1: 5
Question 2: 4
Question 3: 3
Question 4: 1 Each question 2 marks
Question 5: 3
Question 6: 2
Question 7: 2
Question 8: 1
Question 9: 2
Question 10: 2

SECTION B 70 marks

QUESTION 1 4 marks

(a) Swaps b and c’s values. 2


If student gives a line by line explanation, e.g. “assigns b’s value to a, c’s
value to b, etc”, only 1 mark.
(b) Calculate the average of the elements in array a 2
If student gives a line by line explanation, only 1 mark.

QUESTION 2 6 marks

Note to markers: For questions 2(a) and (b) the mark is given for the highlighted field.
For questions 2(c) – (e), if the student left out the single and double quotes, but the value
is correct, please give the mark.

(a)
'n
line 20 "PROGRAMMING" "PROGRAMMING" "COS1512" 'n' ' 800

'n
line 21 "PROGRAMMING" "PROGRAMMING 2" "COS1512" 'n' ' 800
[2]
(b)
'y
line 28 "PROGRAMMING" "PROGRAMMING 2" "COS1512" 'n' ' 800
[1]
2 COS1511/COS111U memorandum May 2011

(c) “PROGRAMMING” [1]


(d) “COS1512” [1]
(e) ‘n’ [1]
QUESTION 3 13 marks

Note to markers: Student must use a nested if loop, as it is stated in the question.

Students may have put the cout statement within each if or else in which case
they will have 5 cout statements for the colour and one for the error message.
Make sure { } pairs have been used in this case. If no { } pairs have been used,
subtract 1 mark for incorrect logic. Only one mark for cout for fee and one
mark for error message cout.
if (number > 10 && number < 21) is also correct. Same for other
if’s

if (number >= 11 && number <= 20) [1]


colour = "green"; [1]
else if (number >= 21 && number <= 30) [1]
colour = "red"; [1]
else if (number >= 31 && number <= 40) [1]
if (gender == 'm') [1]
colour = "blue"; [1]
else if (gender == 'f') [1]
colour = "pink"; [1]
else colour = "white"; [1]
if (number < 11 || number > 40) [1]
cout << "Class will not participate" << endl; [1]
else
cout << "The colour is " << colour << endl; [1]

QUESTION 4: 8 MARKS

Give marks for any correct cout statement asking the user to guess a number.
The student could also have tested userCorrect inside the while loop instead
of testing it as one of the conditions – give marks if logic is correct.
(Many students answered this question without using userCorrect. We gave
marks for correct logic).

#include <iostream>
using namespace std;

int main()
{
int num1, num2;
int sum; //sum of num1 and num2;
int userGuess; // the number guessed by the user
const int MAXGUESSES = 5;//maximum number of guesses allowed
int noOfGuesses ; // the number of guesses by the user
bool userCorrect; //user has guessed correctly or not
3 COS1511/COS111U memorandum May 2011

noOfGuesses = 0;
userCorrect = false;
cout << "Enter two large integer values:" << endl;
cin >> num1 >> num2;
sum = num1 + num2;

while (!userCorrect && noOfGuesses < MAXGUESSES) 2


(OR while (!userCorrect && noOfGuesses < 5)
{
cout << "Guess the sum of " << num1 <<" + " << num2 <<
" = ?" << endl;  1
cin >> userGuess;  1
if(userGuess == sum) { 1
cout<<"You Guessed Correctly" << endl;  1
userCorrect=true;  1
}
noOfGuesses++; 1
}

if (!userCorrect)
{
cout<<"Sorry better luck next time!" <<endl;
cout<<"The sum was "<<sum;
}
return 0;
}

QUESTION 5: 12 MARKS

Note to markers: The first two parameters must be const variables – deduct ½ mark
for each one that does not have the const.
const string monthP[12] and const float rainfallP[12] is also
correct.

void findLowest (const string monthP[], const float


rainfallP[], float & lowestP, int & countP) [4]
{
lowestP = 1000.00; //(or any high value) [1]
//(or lowest = rainfall[0];)
//We gave marks here for any initialisation
for (int i = 0; i < NUM; i++) [1]
{
if (rainfallP[i] < lowestP) [1]
lowestP = rainfallP[i]; [1]
if (rainfallP[i] == 0.00) [1]
countP ++; [1]

cout << "Month: " << monthP[i] <<


"Rainfall: " << rainfallP[i] << endl; [2]
}

}
4 COS1511/COS111U memorandum May 2011

QUESTION 6 15 marks
14]

Note to markers: Give 1 marks for int inStaff[4][3].


We did not specify whether the array had to read row-wise or column-wise. Give marks
for both.

(a)

int inStaff[DEPARTMENT][STORE];  2

(b)

int lowest = inStaff[0][0];  //or any high value 1


int highest = inStaff[0][0];  //or any low value 1
//we gave marks here for any initialisation of lowest and highest
int range; 1
for(int i = 0; i < DEPARTMENT;i++){ 2
for (int j = 0; j < STORE; j++) 2
//we gave marks here if 4 and 3 were used i.s.o. DEPARTMENT and STORE
{
if (inStaff[i][j] > highest)  1
{
highest = inStaff[i][j];  1
}
if (inStaff[i][j] < lowest)  1
{
lowest=inStaff[i][j];  1
}
}
}

range = highest - lowest;  1


cout<<" The range of employee is " << range;  1

QUESTION 7 6 marks

Note to markers: Do not deduct marks if “...” is not included in the cout statement

(a)
struct MenuItemType 1
{
string menuItem;  1
float menuPrice;  1
};

(b)
for ( int i = 0; i < 3; i++)
{
cout <<customerOrder[i].menuItem 1
<<" ... R "<<customerOrder[i].menuPrice<<endl; 1
amountDue = amountDue + customerOrder[i].menuPrice;  1

}
cout<<"Amount Due .....R " << amountDue <<endl;
5 COS1511/COS111U memorandum May 2011

QUESTION 8 6 marks

string removeChar(string inStringP)


{
int pos; 1

// Find 'p' and erase it from the string


pos = inStringP.find("p"); 1
while (pos > -1) 1
{
inStringP.erase(pos, 1); 1
pos = inStringP.find("p", pos); //NOT pos+1 1
}
return inString; 1
}

You might also like