100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Samenvatting

Summary COS1511 Exam pack

Beoordeling
-
Verkocht
-
Pagina's
90
Geüpload op
29-11-2021
Geschreven in
2021/2022

Summary of 90 pages for the course COS1511 - Introduction To Programming 1 at Unisa (exam pack)

Instelling
Vak











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
29 november 2021
Aantal pagina's
90
Geschreven in
2021/2022
Type
Samenvatting

Onderwerpen

Voorbeeld van de inhoud

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);
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 function supplyInfo?

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 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)
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]

, 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

Suppose the following input is given to the program above:

6 soccer 6

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 6

Suppose in a C++ program values are assigned to a string variable name and to a float variable amount.
Then a while loop is entered. The loop has to be executed as long as
• 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]

, 4 COS111U
May 2009

• the value of the char variable sym is 'A' or 'B' or 'C'.
Which of the options below gives a correct assignment statement?

1. success = (grade >= 10) || sym == 'A' || sym == 'B' || sym == 'C';
2. success = (grade >= 10) || (sym == 'A' || 'B' || 'C');
3. success = (grade >= 10) && (sym == 'A' || sym == 'B' || sym == 'C');
4. success = (grade >= 10) && sym == 'A' && sym == 'B' && sym == 'C';
5. None of the options above is a correct assignment statement.


Questions 8, 9 and 10 are based on the following C++ program. Note that the conventions as explained
in the Study Guide are used in the variable diagrams.

1 #include <iostream>
2 #include <string>
3 using namespace std;

4 void supplyInfo(string destP, float & feeP, string & timeP)
5 {
6 if (destP != "Cape Town" && feeP != 40)
7 feeP *= 3;
8 else if (destP != "Johannesburg")
9 {
10 destP = "Funny";
11 feeP = 1;
12 }

13 timeP = "17:15";
14 if (destP != "Funny")
15 timeP = "10:23";
16 else
17 timeP = "Fun";
18 }

19 float amountDue(int nrA, int nrC, float feeP)
20 {
21 float total;

22 total = nrA * feeP;
23 feeP *= 0.80;
24 total += nrC * feeP;

25 return total;
26 }

27 int main( )
28 {
29 string destination, time;
30 int nrAdult, nrChild;
31 float fee, amount;

32 destination = "P.E.";

[TURN OVER]
$3.36
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten


Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
tnash1722
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
18
Lid sinds
4 jaar
Aantal volgers
18
Documenten
8
Laatst verkocht
1 jaar geleden

5.0

1 beoordelingen

5
1
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen