COS1511
EXAM PACK
2023
QUESTIONS WITH ANSWERS
EMAIL: musyokah11@gmail.com
,COS1511
EXAM
PACK 2023
LATEST QUESTIONS
AND ANSWERS
For queries or any assignment help
Email: musyokah11@gmail.com
,SECTION A 20 MARKS (10 MULTIPLE CHOICE QUESTIONS, 2 marks each)
Please answer this section on the mark-reading sheet that you received (not in your answer book).
Choose one option for every question.
QUESTION 1
Suppose the following declarations appear in a C++ program:
float amount, forWaiter;
char service;
If the following function header is given:
float tip(float amountP, char serviceP)
which of the options below is a correct calling statement of the functiontip?
1. forWaiter = tip(float amount, char service);
2. tip(amountP, serviceP);
3. forWaiter = tip(123.66, 'A');
4. forWaiter = tip(amountP, serviceP);
5. None of the above options is a correct calling statement.
QUESTION 2
Suppose the following declarations appear in a C++ program:
float afford, amount;
int number;
string name;
If the following function header is given:
void supplyInfo(float affordP, int nrP, string & nameP, float & amountP)
which of the options below is a correct calling statement of the functionsupplyInfo?
1. supplyInfo(800, 4, "Beach Hotel", 789);
2. supplyInfo(800, 4, name, amount);
3. supplyInfo(affordP, nrP, nameP, amountP);
4. supplyInfo(afford, number, "Beach Hotel", 789);
5. None of the above options is a correct calling statement.
, 2 COS111U
May 2009
QUESTION 3
Suppose the following declarations appear in a C++ program:
int age, days;
char grade;
float salary;
Suppose the following calling statement appears in the program:
inputInfo(35, 'B', salary, days);
Which of the options below is a correct function header of the functioninputInfo?
1. void inputInfo(int ageP, char gradeP, float & salaryP, int & daysP)
2. void inputInfo(35, 'B', float salaryP, int daysP)
3. void inputInfo(int & age, char & grade, float & salary, int & days)
4. void inputInfo(35, 'B', salary, days)
5. All of the above options are correct function headers.
Questions 4 and 5 are based on the following C++ program.
#include <iostream>
#include <string>
using namespace std;
int main( )
{
string favour;
int tvHours, favourHours;
cout << "How many hours per week do you watch sport on TV, " << endl
<< "what is your favourite sport, how many hours for that? ";
cin >> tvHours >> favour >> favourHours;
if (tvHours > 10)
if (favour == "soccer")
{
if (favourHours > tvHours / 2)
cout << "Group A" << endl;
}
else
if (favourHours > tvHours / 4)
cout << "Group B" << endl;
else
cout << "Group C" << endl;
else
if (favour != "rugby")
cout << "Group D" << endl;
return 0;
[TURN OVER]