100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1511 EXAM PACK 2023 R49,61   Add to cart

Exam (elaborations)

COS1511 EXAM PACK 2023

 4 views  0 purchase

COS1511 EXAM PACK 2023

Preview 4 out of 91  pages

  • October 1, 2023
  • 91
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (10)
avatar-seller
examexpert01
COS1511
EXAM
PACK 2023

, Page 1 of 90
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 function tip?

1. forWaiter = tip(float amount, char service);
2. tip(amountP, serviceP);




za
3. forWaiter = tip(123.66, 'A');
4. forWaiter = tip(amountP, serviceP);


ls s
o.
5. None of the above options is a correct calling statement.
ria al
.c
to ori
QUESTION 2
rtu ut


Suppose the following declarations appear in a C++ program:
.g T



float afford, amount;
w R




int number;
string name;
G




If the following function header is given:

void supplyInfo(float affordP, int nrP, string & nameP, float & amountP)
w




which of the options below is a correct calling statement of the function supplyInfo?
w




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.




Tel: 0127704001/0127704239
web: www.grtutorials.co.za email: accounts@grtutorials.co.za cell: 0710354903

, Page 2 of 90
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 function inputInfo?

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)




za
5. All of the above options are correct function headers.



ls s
o.
ria al
Questions 4 and 5 are based on the following C++ program.

.c
to ori
#include <iostream>
rtu ut

#include <string>
using namespace std;
.g T



int main( )
w R




{
G




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;
w
w




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]
Tel: 0127704001/0127704239
web: www.grtutorials.co.za email: accounts@grtutorials.co.za cell: 0710354903

, Page 3 of 90
3 COS111U
May 2009

}

QUESTION 4

Suppose the program above is executed with the following input:

11 soccer 5

Which of the options below gives the output of the program?

1. Group A
2. Group B
3. Group C
4. Group D
5. No output


QUESTION 5




za
Suppose the following input is given to the program above:


ls s
o.
6 soccer 6
ria al
.c
to ori
Which of the options below gives the output of the program?
rtu ut


1. Group A
.g T



2. Group B
3. Group C
w R




4. Group D
5. No output
G




QUESTION 6

Suppose in a C++ program values are assigned to a string variable name and to a float variable amount.
w




Then a while loop is entered. The loop has to be executed as long as
w




• name is not equal to "NOBODY" and
• amount is not less than 10.00.
Which of the options below gives a correct condition for the loop?

1. ((name != "NOBODY") && (amount >= 10.00))
2. ((name != "NOBODY") || (amount >= 10.00))
3. (!(name == "NOBODY") && (amount < 10.00))
4. (!((name != "NOBODY") && (amount >= 10.00)))
5. None of the options above is a correct condition.


QUESTION 7

Suppose we want to assign the value true to a bool variable success if
• the value of the int variable grade is 10 or higher and

[TURN OVER]
Tel: 0127704001/0127704239
web: www.grtutorials.co.za email: accounts@grtutorials.co.za cell: 0710354903

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller examexpert01. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R49,61. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

71498 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R49,61
  • (0)
  Buy now