100% de satisfacción garantizada Inmediatamente disponible después del pago Leer en línea o como PDF No estas atado a nada 4,6 TrustPilot
logo-home
Examen

Solutions to study guide questions

Puntuación
-
Vendido
-
Páginas
63
Grado
A
Subido en
11-10-2022
Escrito en
2022/2023

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

Institución
Grado

Vista previa del contenido

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

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
11 de octubre de 2022
Número de páginas
63
Escrito en
2022/2023
Tipo
Examen
Contiene
Preguntas y respuestas

Temas

$6.04
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Leer en línea o como PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
lindelanitshikalange0

Documento también disponible en un lote

Conoce al vendedor

Seller avatar
lindelanitshikalange0 University of South Africa (Unisa)
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
5
Miembro desde
3 año
Número de seguidores
4
Documentos
14
Última venta
3 año hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes