Section 2.1

2. Enter a decimal fraction=> 0.25

Enter an integer=> -3

Sum of 0.25

and -3 is -2.75

Section 2.2

2. 8 is less than 12

Section 2.3

2. cout < "Enter temperature (kelvin) => ";

cin > temp;

cout < "Enter volume (liters) => ";

cin > vol;

Section 2.4

2. cancellation error

4. 35 int

'-2' not a legal int, char, or double constant

'\n' char

not a legal int, char, or double constant

+13.2 double

9E-4 double

false bool

'Q' char

.16 double

1456 int


Section 2.5

2. x y n m

10.1 5.0 8 2

z = x - n / m;

4

6.1 z = 6.1

b = x * y + m / n * 2;

50.5

0

0

50.5 b = 50.5

i = int ( x + 0.5 );

10.6

10 i = 10

j = x * m - n % m;

20.2

0

20.2 j = 20

k = m / -n;

-8

0 k = 0

4. q = k * A * (T1 - T2) / L;

V = Pi * r * r * h;

e = (x - a) / x;

Section 2.6

2. e = 100 * (1 - (1 / pow( R, 0.4 ) ));

2.120784

0.471524

0.528476

52.8476 e = 52.8476

Quiz 2.1–2.3

// This program computes the time it takes to reach a

// destination, given the speed of a vehicle in miles per hour

// and the distance traveled in miles.

#include

using namespace std

int main ()

{

double distance; // distance traveled

double time; // hours to reach destination

double rate; // speed of the vehicle

cout < "Enter the distance traveled in miles => ";

cin < distance;

cout < endl;

cout < "Enter the speed of the vehicle (mph) => ";

cin < speed;

time = distance / rate

cout < endl;

cout < "The time it takes to reach the destination is ";

cout < endl < time < " hours.;

cout < endl;

return 0;

}

This program contains seven syntax errors. Find and correct the errors.

Assuming you made the corrections, what would be the output of the program given the following input data?

300

60


Quiz 2.4–2.8

// This program determines the percentage grade on

// an exam, given the number of questions missed,

// how many points each question was worth,

// and the total points possible.

#include <iostream

using namespace std;

int main()

{

int pointsPerQuestion;

int numberMissed;

double percentageGrade;

double pointsPossible;

cout < "Enter the total points possible on the exam => ";

cin > pointsPossible;

cout < endl;

cout < "Enter the number of points per question => ";

cin > pointsPerQuestion;

cout < endl

cout <"Enter the number of questions missed => ";

cin > numberMissed;

percentageGrade = pointsPossible - numberMissed * pointsPerQuestion / pointsPossible * 100;

cout < endl < "The percentage grade is ";

cout < percentageGrade < "%";

return 0;

}

  1. Are parentheses needed in the percentage grade formula? If so, rewrite the assignment to percentageGrade, adding parentheses where necessary.
  1. What will happen if the data type of pointsPossible is changed from double to int?
  1. Add an if-else statement displaying a message indicating whether or not the exam was passed. Assume that 60% is the minimum passing grade.

4. Name three categories of errors that may be found in a computer program. Which category is detected by the compiler?