Write a C++ statement or a set of C++ statements to accomplish each of the following:

a) Sum the odd integers between 1 and 99 using a for statement. Assume the integer variables sum and count have been declared.
b) Print the value 333.546372 in a 15-character field with precisions of 1, 2 and 3. Print each number on the same line. Left-justify each number in its field. What three values print?
c) Calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions. What prints?
d) Print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: When x % 5 is 0, print a newline character; otherwise, print a tab character.]
e) Repeat Exercise 4.2(d) using a for statement.


a) ```
sum = 0;
for ( count = 1; count <= 99; count += 2 )
sum += count;
```
b)
```
cout << fixed << left
<< setprecision( 1 ) << setw( 15 ) << 333.546372
<< setprecision( 2 ) << setw( 15 ) << 333.546372
<< setprecision( 3 ) << setw( 15 ) << 333.546372
<< endl;
Output is:
333.5 333.55 333.546
```
c) ```
cout << fixed << setprecision( 2 )
<< setw( 10 ) << pow( 2.5, 3 )
<< endl;
Output is:
15.63
```
d) ```
x = 1;
while ( x <= 20 )
{
if ( x % 5 == 0 )
cout << x << endl;
else
cout << x << '\t';
x++;
}
```
e) ```
for ( x = 1; x <= 20; x++ )
{
if ( x % 5 == 0 )
cout << x << endl;
else
cout << x << '\t';
}
```

Computer Science & Information Technology

You might also like to view...

A thread enters the _________ state, after waiting, if it is ready to run but the resources are not available.

A) ?Terminated ? B) ?Standby ? C) ?Transition ? D) ?Waiting

Computer Science & Information Technology

When using a set of radio buttons, which attribute must be the same for all buttons in the set

a. name b. value c. id d. selected

Computer Science & Information Technology

Match the following terms to their meanings:

I. Style II. Theme III. Template IV. Formatting V. Fill A. The inside color of an object B. The process of establishing the overall appearance of text, graphics, pages, etc. C. A group of commands that can be applied to a paragraph with one command D. A preformatted document that you can use as a starting point and change as needed E. A predesigned combination of colors, fonts, and effects that looks good together

Computer Science & Information Technology

You have been asked to participate in developing the requirements for an RFID-based identification card for students, faculty, and affiliates at a university. First, list 5 to 10 different uses of the card. Second, from that list of uses, detail what data the card needs to broadcast to receivers that will accomplish those uses. Third, identify uses that could be made of that data by rogue

receivers surreptitiously planted around the university campus. Which rogue accesses threaten personal privacy? In what ways? What is the degree of harm? What will be an ideal response?

Computer Science & Information Technology