Programming Languages Homework True False False True False True True True False False True

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

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 1
5. In linking, an object program is combined with other programs in the library, used in the program, to
create the executable code.
7. #
9. Programming is a process of problem solving.
11. (1) Analyze and outline the problem and its solution requirements, and design an algorithm to solve the
12. (1) Thoroughly understand the problem. (2) Understand the problem requirements. (3) If the problem is
complex, divide the problem into subproblems and repeat Steps 1 and 2.
13. To find the weighted average of the four test scores, first you need to know each test score and its
2. Get testScore2, weightTestScore2
4. Get testScore4, weightTestScore4
5. weightedAverage = testScore1 * weightTestScore1 +
14. a. Get quarters
b. Get dimes
15. To find the price per square inch, first we need to find the area of the pizza. Then we divide the price
of the pizza by the area of the pizza. Let radius denote the radius and area denote the area of the
circle, and price denote the price of pizza. Also, let pricePerSquareInch denote the price per
page-pf2
16. To determine the least selling price of a car, we need to know the listing price of the car. The algorithm
is as follows:
17. Suppose that radius denotes radius of the sphere, volume denotes volume of the sphere, and
surfaceArea denotes the surface area of the sphere. The following algorithm computes the volume
and surface area of the sphere.
Algorithm
C++ Instruction (Code)
1 1. Get the radius.
cin >> radius;
2. Calculate the volume.
volume = (4.0 / 3.0) * 3.1416 * radius * radius * radius;
3 3. Calculate the surface
area.
surfaceArea = 4.0 * 3.1416 * radius * radius;
18. Suppose that billingAmount denotes the total billing amount, movingCost denotes moving cost,
area denotes the area of the yard that needs to be moved, numOfAppl denotes the number of
fertilizing applications, and numOfTrees denotes the number of trees to be planted. The following
algorithm computes and outputs the billing amount.
page-pf3
3
billingAmount = (area / 5000) * 35.00 + numOfAppl * 30.00
+ numOfTrees * 50.00
19. Suppose that billingAmount denotes the total billing amount, numOfItemsOrdered denotes the
number of items ordered, shippingAndHandlingFee denotes the shipping and handling fee, and
price denotes the price of an item. The following algorithm computes and outputs the billing
amount.
20. Suppose amountWithdrawn denotes the amount to be withdrawn, serviceCharge denotes the
service charges, if any, and accountBalance denotes the total money in the account.
You can now write the algorithm as follows:
a. Get amountWithdrawn.
b. if amountWithdrawn > 500
page-pf4
4
}
21. Suppose x1 and x2 are the real roots of the quadratic equation.
a. Get a
b. Get b
}
22. Suppose that tuition denotes the tuition per semester, semesterUnits denotes the average
semester units, courseUnits denotes the number of course units, semesterWeeks denotes the
number of weeks in a semester, classDaysPerWeek denotes the number of days a class meets in a
week, classDaysPerSemester denotes the total number of days a class meets in a semester,
costPerUnit denotes the cost of one unit of a course, and costPerClass denotes the cost of one
class.
a. Get tuition
b. Get semesterUnits
page-pf5
5
classDaysPerSemester = classDaysPerWeek * semesterWeeks;
h. Compute costPerClass using the following formula.
costPerClass = (costPerUnit * courseUnits) / classDaysPerSemester;
23. Suppose averageTestScore denotes the average test score, highestScore denotes the highest
test score, testScore denotes a test score, sum denotes the sum of all the test scores, count
denotes the number of students in class, and studentName denotes the name of a student.
2. Increment count and update the value of sum by adding the current test score to sum.
iii. Use the following formula to find the average test score.
if (count is 0)
averageTestScore = 0;
1. Get testScore
2. if (testScore is greater than highestTestScore)
highestTestScore = testScore;
d. To print the names of all the students whose test score is the same as the highest test score,
page-pf6
6
2. Use the algorithm in part b to print the names of all the students whose score is below the average
test score.
page-pf7
Chapter 2
4. A keyword is a reserved word and is defined by the system. A keyword cannot be redefined in a
5. The identifiers quizNo1 and quizno1 are not the same. C++ is case sensitive. The fifth letter of
6 . a. 22
7. a. 7
8. a, b, c, e, i, j, and k are valid;
10. Variable declarations in Lines 1, 6, and 7 are correct.
page-pf8
8
11. a and c are valid
12. a. int x, y;
b. int temp = 10;
13. a. 9.0 / 5 * C + 32
page-pf9
14. x = 1
15. x = 101
16. a. x = 18, y = 5, z = 4
17. a. 1000
18. a. cout << endl; or cout << "\n"; or cout << '\n';
19. a and c are correct
20.
a. char grade = '*';
page-pfa
10
21. a. int num1;
int num2;
22. A correct answer is:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int height, weight;
double discount;
height = 6;
weight = 156;
}
23. A correct answer is:
#include <iostream>
using namespace std;
page-pfb
11
x = 25.67; // x = 25.67;
newNum = count * 1 + 2; //newNum = count * ONE + 2;
}
24. A correct answer is:
#include <iostream>
#include <string>
using namespace std;
}
27. a. x += 5;
page-pfc
12
28. a. x = x + 5 z;
29.
a b c
30.
a b c sum
31. (The user input is shaded.)
firstNum = 62
32. (The user input is shaded.)
Enter last name: Miller
33.
#include <iostream>
page-pfd
13
int main()
{
string employeeID;
string department;
int num;
double salary;
cout << "Enter department: ";
cin >> department;
cout << endl;
cout << "Enter a positive integer less than 80: ";
cin >> num;
cout << endl;
return 0;
}
34. The program requires four inputs in the following order:
page-pfe
Chapter 3
2. a. x = 78, y = 86, z = 18, ch = '#'
3. a. int1 = 67, int2 = 48, dec1 = 56.5, dec2 = 62.72
4. a. x = 38, y = 26, symbol = '2'
5. a. Samantha 168.5 46
6. a. int1 = 13, int2 = 4, dec = 16.2, ch = '2'
10. iostream
page-pff
15
static_cast<int>(sqrt(pow(y, 4))) = 10
Length of str = 47
14. a. num = 34, discard = '#'
17. a. name = " Christy Miller", height = 5.4
18. a. name = "Christy Miller", height = 5.4
19.
#include <iostream>
#include <fstream>
using namespace std;
}
20. Invalid data may cause the input stream to enter the fail state. When an input stream enters the fail
page-pf10
16
24. infile >> acctNumber;
25. a. outfile.open("sales.dat ");
b. outfile >> fixed >> showpoint >> setprecision(2);
page-pf11
17
Chapter 4
2. a. 0 (false) b. 0 (false) c. 1 (true) d. 1 (true)
e. 1 (true) f. 0 (false)
4. a. false; b. true; c. true; d. false; e. false
5. a. x == z: 0
b. y != z - 9: 0
6. c and e.
7. a. +--+
9. a. ?%!!
10. The value of done is: 1
12. 28 25
31
13. Omit the semicolon after else. The correct statement is:
if (score >= 60)
page-pf12
18
14. a.
if (standing == 'F')
cout << << "First Year" << endl;
else if ((standing == 'S')
15. The correct code is:
if (numOfItemsBought > 10)
16. 27 12 39 -15
18. a. -10 -20
b. 5 15
19. if (sale > 20000)
bonus = 0.10
20. if (0 < overSpeed && overSpeed <= 5)
fine = 20.00;
21. a. The output is: Discount = 10%. The semicolon at the end of the if statement terminates the if
statement. So the cout statement is not part of the if statement. The cout statement will execute
22. a. (i) The output is: Grade is C. The value of score after the if statement executes is 70.
(ii) The output is: Grade is C. The value of score after the if statement executes is 70.
page-pf13
19
b. (i) No output. The value of score after the if statement executes is 80.
(ii) The output is: Grade is C. The value of score after the if statement executes is 70.
23. a. (x == y) ? z = x + y : (x + y) / 2;
b. (hours >= 40.0) ? wages = 40 * 7.50 + 1.5 * 7.5 * (hours 40)
24. a. if (overSpeed > 10)
fine = 200;
else
tip = 0.10;
b. 40.00
26. a, c, and d are valid. b is invalid; a case value cannot appear more than once and there should be a
colon after a case value.
28. a. 2 b. 22 c. -1 d. 9
30. A correct code is:
#include <iostream>
using namespace std;
{
case 0:
case 1:
page-pf14
num1 = num2 / 2;
break;
31.
#include <iostream>
using namespace std;
const int SECRET = 5;
}
32.
#include <iostream>
#include <cmath>

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.