Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Chapter 2
- 1. How do you output a newline character from your program?
- endl;
- \n
- Chapter 3
- 1. Write a C++ statement that displays the value of floating-point variable rate in a field 8 characters wide with
- exactly one digit to the right of the decimal.
- cout << setprecision(1) << setw(8) << thefloat;
- 2. How do you enter a newline character from the keyboard?
- enter???
- Chapter 4
- 1. A company pays its sales people $200 per week plus 9 percent of their gross sales for the week. Write declarations
- for variables to hold a salesperson's gross weekly sales and weekly pay. Write a statement to calculate the weekly pay
- and store it in your variable.
- float weeklyGross;
- float weeklyPay;
- weeklyPay = .9*weeklyGross;
- 2. Given float variables predictedHigh and actualHigh, write a C++ statement or statements that print:
- "Bullseye" if the difference between predictedHigh and actualHigh is less than 3,
- "Close" if the difference between predictedHigh and actualHigh is from 3 to 6,
- and "Oops" if the difference is larger than 6.
- is it possible to make this a switch?
- if (predictedHigh - actualHigh >= -3 || predictedHigh - actualHigh <= 3)
- {
- cout << "Bullseye";
- }
- if (predictedHigh - actualHigh >= -6 || predictedHigh - actualHigh <= 6)
- {
- cout << "Close";
- }
- if (predictedHigh - actualHigh < -6 || predictedHigh - actualHigh > 6)
- {
- cout << "Oops";
- }
- 3. Write a C++ statement that means the same thing as this math expression:
- 0 < length < 10
- (0 < length) && (length < 10)
- Chapter 5
- 1. The following loop is supposed to print the odd integers from 1 through 5.
- count = 1;
- while (count != 6)
- {
- count++;
- cout << count << ' ';
- }
- a. What is printed by the loop?
- i'm guessing it starts at 2 and then goes up to 6 in increments of 1, unless count++ adds 2. then it starts at
- 3 and goes up to whatever the int cap is
- b. Rewrite the loop so that it works correctly.
- no
- 3. Write C++ code to read 20 integers and count how many times the integer 100 appears in the input. You must use a
- loop.
- oh god
- 4. Write a loop that sums the integers from 1 through 10.
- okay
- int sum = 0;
- int counter = 0;
- while (counter != 9)
- {
- counter += 1;
- sum = sum+counter;
- }
- 5. Write a loop that reads a list of integers from the keyboard and counts how many negative integers are input and how
- many positive integers are input. The loop should stop when zero is input. Then print the count of negative numbers and
- the count of positive numbers with appropriate labels.
- int negativeCounter = 0;
- int positiveCounter = 0;
- bool isZero = false;
- int temp = 0;
- while (isZero = false)
- {
- cout << "enter an integer nyo: ";
- cin >> temp;
- if (temp = 0)
- {
- isZero = true;
- }
- if (temp > 0)
- {
- positiveCounter += 1;
- }
- if (temp < 0)
- {
- negativeCounter += 1;
- }
- }
- cout << "youre done nyo. number of positive numbers entered: " << positiveCounter;
- cout << " number of negative numbers entered: " << negativeCounter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement