Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

COS 1511 Solutions to exercises in the Guide

Beoordeling
-
Verkocht
-
Pagina's
58
Cijfer
A+
Geüpload op
06-11-2021
Geschreven in
2021/2022

Solutions to exercises in the Guide Solutions to exercises in the Guide Part I : Starting to Program Solutions to Lesson 1 Exercise 1.1 Compare the description of the program structure that we have just given with the program we gave when describing the purpose of this lesson. #include using namespace std; int main( ) { cout "Hello world"; return 0; } What part of the program corresponds to DescriptiveComment? What parts correspond to StandardHeaderFile and StatementSequence? Solution to exercise 1.1 Descriptive Comment: There is no descriptive comment. StandardHeaderFile: iostream StatementSequence: cout "Hello world"; return 0; Exercise 1.2 Write a program to display the following poem1 on the screen. Twinkle, twinkle, little bat! How I wonder what you're at? Up above the world you fly, Like a tea-tray in the sky. Solution to Exercise 1.2 //A poem from Alice's Adventures in Wonderland by Lewis Carroll #include using namespace std; int main( ) { cout "Twinkle, twinkle, little bat!" endl; cout "How I wonder what you're at?" endl; cout "Up above the world you fly," endl; cout "Like a tea-tray in the sky." endl; return 0; } Solutions to Lesson 2 Exercise 2.1 Add round brackets to the following C++ expressions to show the order in which the operators will be evaluated: (i) 80 / 5 + 70 / 6 (ii) -5 + -4 - -3 (iii) 6 * 7 / 8 * 9 (iv) 1 - 2 + 3 / 4 * 5 (v) -1 + 23 / -4 + 56 Also give the value of each of the expressions. Solution to exercise 2.1 (i) ((80 / 5) + (70 / 6)) | | 16 + 11 | 27 (ii) ((-5 + -4) - -3) | -9 - -3 | -6 Modules: Print Module Page 1 of 58 (iii) (((6 * 7) / 8) * 9) | 42 / 8 * 9 | 5 *9 | 45 (iv) ((1 - 2) + ((3 / 4) * 5)) | -1 + 0 * 5 | -1 +* 0 | -1 (v) ((-1 + (23 / -4)) + 56) | -1 + -5 + 56 | -6 + 56 | 50 Exercise 2.2 Write a program that produces the following output: There are 60 seconds in a minute. There are XXX seconds in an hour. There are YYY seconds in a day. There are ZZZ seconds in a year. In place of XXX, YYY and ZZZ, the program should calculate and display the appropriate number of seconds. Solution to exercise 2.2 // Lesson 2 Exercise 2.2 // Display number of seconds in a minute, hour, day and year #include using namespace std; int main() { cout "The are 60 seconds in a minute." endl; cout "The are " 60 * 60 " seconds in an hour." endl; cout "The are " 60 * 60 * 24 " seconds in a day." endl; cout "The are " 60 * 60 * 24 * 365 " seconds in a year." endl; return 0; } Excercise 2.3 Write a program to calculate the remainder of 234 divided by 13. Remember that the / operator throws away the remainder. Hint: divide 234 by 13 and then multiply it by 13 again. The difference between 234 and the result of this will be the remainder. Solution to exercise 2.3 // Lesson 2 Exercise 2.3 #include using namespace std; int main( ) { cout "The remainder of 234 divided by 13 is "; cout 234 - (234 / 13) * 13 endl; return 0; } Solutions to Lesson 3 Exercise 3.1 Write a program that inputs three values and displays them on a single line in reverse order. Solution to exercise 3.1 // Lesson 3 Exercise 3.1 // Inputs three numbers and displays them in reverse order #include using namespace std; int main( ) { int i, j, k; Modules: Print Module Page 2 of 58 cout "Enter three numbers: "; cin i j k; cout "In reverse: " k " " j " " i endl; return 0; } Exercise 3.2 Look at the following program and then answer the questions that follow without typing in the program and testing it: #include using namespace std; int main( ) { int x, y, z; cout "Enter values for variables x, y and z:" endl; cin x y z; cout "x + y / z is " x + y / z endl; cout "x % z is " x % z endl; cout "y * z / x + 2 is " y * z / x + 2 endl; return 0; } (i) What will the output be if the user enters 2, 6 and 4? (ii) What will the output be if the user enters 5, 1, 3? (iii) If the last output statement is changed to cout "y * (z / x + 2) is " y * (z / x + 2) endl; what will the output of this statement be if the user enters the same values as specified in (i) and (ii)? Solution to exercise 3.2 (i) Enter values for variables x, y and z: 2 6 4 x + y / z is 3 x % z is 2 y * z / x + 2 is 14 (ii) Enter values for variables x, y and z: 5 1 3 x + y / z is 5 x % z is 2 y * z / x + 2 is 2 (iii) If 2 6 4 are entered: y * (z / x + 2) is 24 If 5 1 3 are entered: y * (z / x + 2) is 2

Meer zien Lees minder
Instelling
University Of South Africa
Vak
COS1511 - Introduction To Programming 1











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

Geschreven voor

Instelling
University of South Africa
Vak
COS1511 - Introduction To Programming 1

Documentinformatie

Geüpload op
6 november 2021
Aantal pagina's
58
Geschreven in
2021/2022
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

€3,53
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

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.
LOVELY01 Chamberlain College Of Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
1014
Lid sinds
4 jaar
Aantal volgers
881
Documenten
2332
Laatst verkocht
1 maand geleden
LOVELY01

100% correct questions, answers, workings, and explanations. For assistance call or W.h.a.t.s.a.p.p us on ...(.+.2.5.4.7.0.0.3.6.7.0.2.1)

3,6

127 beoordelingen

5
55
4
23
3
18
2
11
1
20

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

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen