Euros and dollars dollars endl endl
8.8 Assignment 2: 2nd semester
ASSIGNMENT 2 - WRITTEN (PRACTICAL) ASSIGNMENT |
|
---|---|
|
|
|
|
|
|
|
A vending machine displays a hot beverage menu and prompts the user to make a choice of beverage as well as the number of cups required. It then displays the total cost of the order. The menu options and cost per unit is as follows:
1 | : |
|
|
---|---|---|---|
2 | : | ||
3 | : | ||
4 | : | Cappuccino |
|
0 | : |
|
cout << “Please enter the choice of dink “
<< “(a number from 1 to 4 or 0 to quit) “ << endl; cout << "Hot Beverage Menu" << endl << endl;
cout << "1: Coffee " << endl;
cout << "2: Tea " << endl;
cout << "3: Hot Chocolate " << endl;
cout << "4: Cappuccino " << endl;
cout << "0: QUIT " << endl <<endl << endl;cin >> beverage ;
cout << “You have selected option number “ << beverage; cout << "How many cups would you like?" << endl;
// Fill in the code to read in number
Question 2a
Include the for loop below in a small program named question2a.cpp and complete the program. The loop should be executed 10 times. Do not change the for loop below. Compile and run your program to see for yourself that it works. You do not have to submit this program and output.
int next = 2, product = 1;
while (next <= 5)
{
next++;
product = product * next;
}
cout << "The product of 2 through 5 is " << product << endl;Submit: Program question2a.cpp
#include <iostream>
using namespace std;int main()
{
for( student = 1; student <= numStudents; student++)
{
total = 0;
for(day = 1; day <= 3; day++)
{
cout << "Please enter the number of hours worked by student" << student <<" on day " << day << "." << endl;
cin >> numHours;
} |
|
---|
A sample run:
This program will find the average number of hours a day that a student spent programming over a long weekend;
13
The average number of hours per day spent programming by student 2 is 11
A function named printTabs (with no parameters) produces a table of the numbers 1 to 10, their squares and their cubes as shown below.
QUESTION 4a
Write the function printTabs. Include the function in a working program named question4.cpp
COS1511/101
A sample run:
NUMBER | SQUARE | |
---|---|---|
6 | ||
8 |
|
|
10 | ||
12 | ||
14 |
|
|
• Age: Younger people pay more than older citizens as follows: o 18 – 28: pays R50.00 extra.
o 29 – 45: pays R30.00 extra.
o Available pays R40.00 extra.
Write the following functions:
a) |
---|
d) |
---|
for married, and „L‟ or „l‟ for living with a partner.
|
---|
Question 6a
COS1511/101
Question 6c
string variable and a float value for the rate. It must then prompt the user for hours worked for
each day of the week, i.e. Monday – Friday and calculates the weekly pay. Employees who
Program question6c.cpp
1. #include <iostream>
2. #include <iomanip>
7.
8. const double EUROEXCHANGE = 0.1206;
13. void convertMulti(float rands, float& euros, float& dollars)
14. {
19. // This function takes a dollar value and converts it to euros dollars
20. // and pounds
25. dollars = rands * DOLLAREXCHANGE;
26. pounds = rands * POUNDEXCHANGE;
31. return rands * POUNDEXCHANGE;
73
36. return rands * EUROEXCHANGE;
37. }
45. }
46.
51. float dollars;
52. float pounds;
57. << endl;
58. cout << "to euros and dollars" << endl;
63. << " euros and " << dollars << " dollars." << endl << endl;
64.
69. convertMulti(rands, euros, dollars, pounds);
70. cout << "R" << rands << " is converted to " << euros
75. cout << "to pounds" <<endl;
76. cin >> rands;
81.
82. cout << "Please input the Rand amount you want to convert \n";
87. cout << "R" << rands << " is converted to " << euros << " euros "
88. << endl << endl;
93.
74
94. | ||
---|---|---|
95. | ||
96. |
|
|
97. |
|
|
98. | ||
99. |
string customer = "Customer1";
float balance;
float amount = 72.56;
char type = S;getBalance(customer, balance, type, 200.53);
char & typeC, float amtC);
8 n1 -= n;
9 return 2 + n + n1 * C;
10 }
11 void func2(int n, int & n1)
12 {
13 n = C * n1;
14 n1 = n – n1;
15 }
16 void func3(int & n, int & n1)
17 {
18 int k;
19 k = n1 + 3;
20 n = k * 30;
21 n1 = n + 2 * k;
22 }
23 int main( )
24 {
25 int n, m, j;
26 n = 5;
27 m = 10;
28 j = func1(n, m);
29 n = 15;
30 m = 20;
31 func2(n, m);
32 n = 25;
33 m = 30;
34 func3(n, m);
35
36 return 0;
37 }
End of Assignment 2
8.9 Assignment 3: 1st and 2nd semester