100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Solutions to study guide questions R99,00   Add to cart

Exam (elaborations)

Solutions to study guide questions

 3 views  0 purchase

this document contain solutions to questions that are present in the study guide provided by the university.

Preview 4 out of 63  pages

  • October 11, 2022
  • 63
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (83)
avatar-seller
lindelanitshikalange0
Solutions to Exercises in Study Guide


LESSON 1

Exercise 1.1

We repeat the program here:
#include <iostream>
using namespace std;
int main( )
{ cout << "Hello world"; return 0; }

Descriptive Comment:

There is no descriptive comment.
StandardHeaderFile:
iostream

StatementSequence:
cout << "Hello world"; return 0;

Exercise 1.2

//A poem
#include <iostream>
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;
}

LESSON 2

Exercise 2.1

(i) (() + ())

| |

16 + 11
|

27



(ii) ((-5 + -4) - -3)

|

-9 - -3
|
-6

,(iii) (((6 * 7) / 8) * 9)

|

42 / 8 * 9
|

5 * 9

|
45



(iv) ((1 - 2) + (() * 5))

| |

-1 + 0 * 5
|
-1 + 0

|
-1



(v) ((-1 + (23 / -4)) + 56)

|

-1 + -5 + 56

|

-6 + 56
|

50

Exercise 2.2

//Lesson 2 Exercise 2.2
//display number of seconds in a minute, hour, day and year
#include <iostream>
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;
}

Exercise 2.3

//Lesson 2 Exercise 2.3
#include <iostream>
using namespace std;

int main( )
{
2

, cout << "The remainder of 234 divided by 13 is ";
cout << 234 - () * 13 << endl;
return 0;
}

The round brackets are not necessary but their use makes the program more readable.

LESSON 3

Exercise 3.1

//Inputs three numbers and displays them in reverse order
#include <iostream>
using namespace std;

int main( )
{
int i, j, k;
cout << "Enter three numbers: ";
cin >> i >> j >> k;
cout << "In reverse: " << k << " " << j << " " << i << endl;

return 0;
}

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

Exercise 3.3

//Fahrenheit to Celsius conversion
#include <iostream>
using namespace std;

int main( )
{
int fahrenheit;
cout << "Enter the temperature in Fahrenheit: ";
cin >> fahrenheit;
cout << "Celsius = " << 5 *(fahrenheit - 32) / 9 << endl;

return 0;
}

, LESSON 4

Exercise 4.1

//Fahrenheit to Celsius conversion (version for lesson 4)
#include <iostream>
using namespace std;

int main( )
{
int fahrenheit, celsius;
cout << "Enter the temperature in Fahrenheit: ";
cin >> fahrenheit;
celsius = 5 * (fahrenheit - 32) / 9;
cout << "Celsius = " << celsius << endl;

return 0;
}

Exercise 4.2

//How many boxes?
#include <iostream>
using namespace std;

int main( )
{
int items, itemsPerBox, boxes, remainder;
cout << "How many items to be packed? ";
cin >> items;
cout << "How many items fit in a box? ";
cin >> itemsPerBox;
boxes = items / itemsPerBox;
remainder = items % itemsPerBox;
cout << "You will need " << boxes << " boxes." << endl;
cout << "There will be " << remainder << " items left over." << endl;

return 0;
}

Exercise 4.3

int n = 10; // 10
n += 3; // 13
n /= 2; // 6
n++; // 7
n %= 4; // 3
n -= 5; // -2

The final value of n is -2.

LESSON 5

Exercise 5.1

j k m n

Line 7: ? ? ? ?

j k m n

Line 8: 3 ? ? ?




14

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 lindelanitshikalange0. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79202 documents were sold in the last 30 days

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

Start selling
R99,00
  • (0)
  Buy now