Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. Chapter 2
  2.  
  3. 1. How do you output a newline character from your program?
  4.  
  5.     endl;
  6.     \n
  7.  
  8. Chapter 3
  9.  
  10. 1. Write a C++ statement that displays the value of floating-point variable rate in a field 8 characters wide with
  11.  
  12. exactly one digit to the right of the decimal.
  13.  
  14.     cout << setprecision(1) << setw(8) << thefloat;
  15.  
  16. 2. How do you enter a newline character from the keyboard?
  17.  
  18.     enter???
  19.  
  20. Chapter 4
  21.  
  22. 1. A company pays its sales people $200 per week plus 9 percent of their gross sales for the week. Write declarations
  23.  
  24. for variables to hold a salesperson's gross weekly sales and weekly pay. Write a statement to calculate the weekly pay
  25.  
  26. and store it in your variable.
  27.  
  28.     float weeklyGross;
  29.     float weeklyPay;
  30.  
  31.     weeklyPay = .9*weeklyGross;
  32.  
  33. 2. Given float variables predictedHigh and actualHigh, write a C++ statement or statements that print:
  34.  
  35. "Bullseye" if the difference between predictedHigh and actualHigh is less than 3,
  36. "Close" if the difference between predictedHigh and actualHigh is from 3 to 6,
  37. and "Oops" if the difference is larger than 6.
  38.  
  39.     is it possible to make this a switch?
  40.     if (predictedHigh - actualHigh >= -3 || predictedHigh - actualHigh <= 3)
  41.     {
  42.         cout << "Bullseye";
  43.     }
  44.     if (predictedHigh - actualHigh >= -6 || predictedHigh - actualHigh <= 6)
  45.     {
  46.         cout << "Close";
  47.     }
  48.     if (predictedHigh - actualHigh < -6 || predictedHigh - actualHigh > 6)
  49.     {
  50.         cout << "Oops";
  51.     }
  52.  
  53.  
  54. 3. Write a C++ statement that means the same thing as this math expression:
  55.  
  56. 0 < length < 10
  57.  
  58.     (0 < length) && (length < 10)
  59.  
  60. Chapter 5
  61.  
  62. 1. The following loop is supposed to print the odd integers from 1 through 5.
  63.  
  64. count = 1;
  65. while (count != 6)
  66. {
  67.   count++;
  68.   cout << count << ' ';
  69. }
  70. a. What is printed by the loop?
  71.     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
  72.  
  73. 3 and goes up to whatever the int cap is
  74. b. Rewrite the loop so that it works correctly.
  75.     no
  76.  
  77. 3. Write C++ code to read 20 integers and count how many times the integer 100 appears in the input. You must use a
  78.  
  79. loop.
  80.     oh god
  81.  
  82. 4. Write a loop that sums the integers from 1 through 10.
  83.  
  84.     okay
  85.    
  86.     int sum = 0;
  87.     int counter = 0;
  88.  
  89.     while (counter != 9)
  90.     {
  91.         counter += 1;
  92.         sum = sum+counter;
  93.     }
  94.  
  95. 5. Write a loop that reads a list of integers from the keyboard and counts how many negative integers are input and how
  96.  
  97. many positive integers are input. The loop should stop when zero is input. Then print the count of negative numbers and
  98.  
  99. the count of positive numbers with appropriate labels.
  100.  
  101.     int negativeCounter = 0;
  102.     int positiveCounter = 0;
  103.     bool isZero = false;
  104.     int temp = 0;
  105.  
  106.     while (isZero = false)
  107.     {
  108.         cout << "enter an integer nyo: ";
  109.         cin >> temp;
  110.         if (temp = 0)
  111.         {
  112.             isZero = true;
  113.         }
  114.         if (temp > 0)
  115.         {
  116.             positiveCounter += 1;
  117.         }
  118.         if (temp < 0)
  119.         {
  120.             negativeCounter += 1;
  121.         }
  122.     }
  123.     cout << "youre done nyo. number of positive numbers entered: " << positiveCounter;
  124.     cout << " number of negative numbers entered: " << negativeCounter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement