//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
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
√ Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, Bancontact of creditcard voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper lindelanitshikalange0. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €5,25. Je zit daarna nergens aan vast.