Programming Languages Homework Cout Ltlt Endl Firstnum Firstnum Secondnum Secondnum Cout Ltlt Both Numbers Must

subject Type Homework Help
subject Pages 14
subject Words 1070
subject Authors D. S. Malik

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
cout << endl;
if (firstNum == 0 || firstNum < 0 || secondNum == 0 || secondNum < 0)
cout << "Both numbers must be positive." << endl;
}
33.
switch (classStanding)
{
case 'f':
dues = 150.00;
break;
}
34. Suppose that we have the following variables:
double billingAmount;
2. Input the billing amount into the variable billingAmount.
4. Input the payment into the variable payment.
5. Determine the unpaid balance using the formula:
page-pf2
6. Determine the percent of the billing amount made by the customer:
if (billingAmount != 0.0)
7. Determine the credit or the penalty, and the unpaid balance including penalty, if any, using the
following if/else statement.
if (paymentPercent == 1.0)
{
credit = billingAmount * 0.01;
page-pf3
Chapter 5
2. i = 5 and temp = 48
4. 1 3 5 7
6. Sum = 90
8. Sum = 190
10.
int count = 0;
}
11. a. 20 *
12. 0 1 -1 1 -1 -3 6 5
13. Replace the while loop statement with the following:
while (response == 'Y' || response == 'y')
Replace the cout statement:
with the following:
page-pf4
24
19. Loop control variable: j
The initialization statement: j = 1;
22. a. ii
23. a. *
b. infinite loop
24.
sum = 0;
}
27.
0 - 24
25 - 49
29. a. both
page-pf5
25
d. while
30. There is more than one answer. One solution is:
#include <iostream>
using namespace std;
31. In a pretest loop, the loop condition is evaluated before executing the body of the loop. In a posttest
32. a. The loop is executed 5 times; Output: 55 50
b. The loop is executed 4 times; Output: 80 80
33. int num;
do
{
34. int i, value = 0;
page-pf6
26
value = value + i * i;
else if (i % 2 == 0 && i > 10)
value = value + i;
else
value = value - i;
}
cout << "value = " << value << endl;
The output is: value = 200
35. int i = 0, value = 0;
do
{
if (i % 2 == 0 && i <= 10)
value = value + i * i;
36. There is more than one answer to this problem. One solution is:
do
{
cin >> number;
37. cin >> number;
while (number != -1)
{
38. cin >> number;
while (number != -1)
{
page-pf7
39. a.
number = 1;
while (number <= 10)
{
40. a.
int value = 3;
int i = 1;
while (i < 5)
{
41. a. 36 94 260
b. 4 20
page-pf8
42.
a.
1 1 1 1 1
b.
2 3 4 5
3 4 5
4 5
5
c.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
d.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
e.
1
121
12321
1234321
44. 12
46. The execution of a break statement in a loop terminates the loop.
page-pf9
29
Chapter 6
1. a. false; b. true; c. true; d. true; e. false; f. false; g. true; h. false; i. true; j. true; k. false; l. false;
m. false; n. true
3. a. 18 b. 20.50 c. 87.20 d. 16.00 e. 1717.82 f. 2.80 g. 14.00 h. 11.16 i. 27.00
j. 20.00 k. 19.00 l. -5.00 m. 2.25 n. 4096.00 o. 0.01 p. 3.03
6. a. 10.00
8. a. 5
9. a. 2; double
10. In a C++ program, typically the function main appears before any other user-defined function. The
page-pfa
11. bool isWhitespace (char ch)
{
12. a. 4.00
13. a. (i) 72 (ii) -200
14. bool funcEx14(double x, double y, double z)
{
if (floor(x * y) == floor(z))
}
15. a. 385
16. 7
-17
17. double funcEx17(double x, double y)
}
18. a. -120
19. a. In a void function, a return statement is used without any value such as return;
20. a.
Function prototype: void func(int, int, double&, char&); //Line 6
page-pfb
31
(function func): starts at Line 19 and ends at Line 26
b.
Function call: Statements in Lines 13 and 15
func(s, t, d, ch); //Line 13
func(75, 8, d, ch); //Line 15
Formal parameters (function func): speed, time, distance, c
Actual parameters: s, t, d, ch (in Line 13)
75, 8, d, ch (in Line 15)
c.
Value parameters (function func): speed, time
Reference parameters (function func): distance, c
d.
Local variables (function main): s, t, d, ch
(function func): num
Global variable: temp
e. Named constant: RATE, STAR
21. a. A variable declared in the heading of a function definition is called a formal parameter. A variable
or expression used in a function call is called an actual parameter.
22. a. Take Programming I.
23. void funcEx23(int num)
{
if (num % 2 == 0)
}
24. void sumAvg(double x, double y, double z, double& sum,
double & avg, string& result)
{
}
25. void initialize(int& x, double& y, string& str)
{
x = 0;
page-pfc
32
26. void sumAvgResult(int n, int m, int& sum, double& avg)
{
int count = 0;
sum = 0;
}
27. 7, 0, 0
28. 6 10 20
29. #include <iostream>
using namespace std;
int secret(int, int);
void func(int x, int& y);
int main()
{
_17__ return 0;
}
int secret(int a, int b)
page-pfd
33
{
int d;
__5__ d = a + b;
30. a. The user input is shaded.
31. void trackVar(double& x, double y, double& z)
{
}
32.
page-pfe
34
Identifier
Visibility
in main
main
Y
local variables of main
Y
trackVar (function name)
Y
x (trackVar formal parameter)
N
y (trackVar formal parameter)
N
z (trackVar local variable)
N
33. 3 5
34.
Sample Run:
Line 9: In main: num1 = 10, num2 = 20
Before the statement in Line 9 executes, the variables are:
Line 9 produces the following line of output:
The statement in Line 10 calls the function funOne; control transfers to the function funOne. Before
the statement in Line 18 executes, the variables are:
After the statement in Line 18 executes, the variables are:
num1 10
num2 20
main
a
x12
funOne
z
num110
num220
main
page-pff
35
Line 19 produces the following output:
Line 19: In funOne: a = 10, x = 12, and z = 22
After the statement in Line 20 executes, the variables are:
After the statement in Line 22 executes, the variables are:
Line 23 produces the following output:
After the statement in Line 23 executes, control goes back to the function main at Line 11. Before the
statement in Line 11 executes, the variables are:
a
x17
funOne
z
22
num110
num220
main
a
x17
funOne
z
22
num118
num220
main
num1 18
main
a
x12
funOne
z
22
num110
num220
main
page-pf10
36
35. stVar = 3, u = 3, x = 2
38. a. 69, 71.50
b. 51, 53.50
page-pf11
Chapter 7
1. a. true; b. false; c. true; d. false; e. false; f. true; g. true; h. true; i. false; j. false; \
2. a. enum flowerType {ROSE, DAISY, CARNATION, FREESIA, GARDENIA,
ALLIUM,TULIP, IRIS, SUNFLOWER, LILAC, ORCHID};
b. flowerType flower;
c. flower = TULIP;
d. flower = static_cast<flowerType>(flower + 1);
break;
case FREESIA:
cout << "Freesia";
break;
case GARDENIA:
case SUNFLOWER:
cout << "Sunflower";
break;
case LILAC:
cout << "Lilac";
page-pf12
38
else if (str == "Carnation")
flower == CARNATION;
else if (str == "Freesia")
flower = FREESIA;
else if (str == "Gardenia")
4. a. 4
b. GRAPE
5.
flowerType readIn()
{
string str;
flowerType flower = 0;
cin >> str;
else if (str == "Allium")
flower = ALLIUM;
else if (str == "Tulip")
flower = TULIP;
page-pf13
39
else if (str == "Iris")
flower = IRIS;
else if (str == "sunflower")
flower = SUNFLOWER;
else if (str == "Lilac")
bir flower d == LILAC;
else if (str == "Orchid")
flower = ORCHID;
else
cout << "Invalid flower name." << endl;
return flower;
}
6.
void printflowerName(flowerType flower)
{
switch(flower)
{
case ROSE:
cout << "Rose";
case GARDENIA:
cout << "Gardenia";
break;
case ALLIUM:
cout << "Allium";
cout << "Lilac";
break;
case ORCHID:
cout << "Orchid";
}//end switch
7. Because there is no name for an anonymous type, you cannot pass an anonymous type as a parameter
to a function and a function cannot return an anonymous type value. Also, values used in one
page-pf14
8. enum quadrilateralType {SQUARE, RECTANGLE, RHOMBUS, TRAPEZIOD,
9. The statement in Line1 1 and 2 should be:
10. The program does not use the statement: using namespace std;
There are several errors in this code. The correct code is:
#include <iostream> //Line 1
11. The statement in Line 2 should be:
using namespace std; //Line 2
12. Replace the statement in Line 2 with the following:
using namespace mySpace //Line 2
Replace the statement in Line 12 with the following:
<< num << endl; //Line 14
13. Either include the statement:
14. The statement in Line 2 should be: #include <cmath>
15. a. Sammer Vucation
16. a. Temporary > Storage

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.