fork download
  1. //Programmer's Name: Bolong Yu
  2. //Program: Practice
  3. //Grade:
  4. //Comments:
  5. //
  6. //-----------------------------------------------------------------------------
  7. //Programmer's Name: Bolong Yu
  8. //Program: Practice
  9. //Program Flow (IPO):
  10. //Output a header to the screen
  11. //Assign the value for the quantity on hand
  12. //Calculate the quantity to order
  13. //Output the quantity to order
  14. //Assign values for the 4 costs
  15. //Calculate the total cost and the average cost
  16. //Output the 4 costs and the total cost and
  17. // the average cost to the screen
  18. //Assign the first initial and last initial
  19. //Output the first initial and last initial to the screen.
  20. //Assign the first name and last name
  21. //Output the first name and last name to the screen
  22. //-----------------------------------------------------------------------------
  23.  
  24.  
  25.  
  26. //For input and output on the screen
  27. #include <iostream>
  28. //For using the string data type
  29. #include <string>
  30.  
  31. using namespace std;
  32.  
  33. const int QUANTITY_REQUIRED = 200;
  34. const int NUMBER_OF_ITEMS = 4;
  35.  
  36. const string COLLEGE = "SUNY Broome Community College";
  37. const string MY_NAME = "Bolong Yu";
  38.  
  39.  
  40. int main(void)
  41. {
  42. int quantityOnHand;
  43. int quantityToOrder;
  44.  
  45. double cost1;
  46. double cost2;
  47. double cost3;
  48. double cost4;
  49. double totalCost;
  50. double averageCost;
  51.  
  52. char firstInitial;
  53. char lastInitial;
  54.  
  55. string firstName;
  56. string lastName;
  57.  
  58. //Output the programmer's name and College to the screen
  59. cout << "-----------------------------------------------------------------"
  60. << endl;
  61. cout << COLLEGE << endl;
  62. cout << MY_NAME << endl;
  63. cout << "Output from the practice" << endl;
  64. cout << "-----------------------------------------------------------------"
  65. << endl;
  66.  
  67. //Assign the quantity on hand
  68. quantityOnHand = 66;
  69.  
  70. //Calculate the quantity to order
  71. quantityToOrder = QUANTITY_REQUIRED - quantityOnHand;
  72.  
  73. //Output quantity on hand and quantity to order to the screen
  74. cout << "The current quantity on hand is " << quantityOnHand << endl;
  75. cout << "The quantity to order is " << quantityToOrder << endl;
  76. cout << "-----------------------------------------------------------------"
  77. << endl;
  78.  
  79. //Set the cost of the 4 purchases
  80. cost1 = 12.50;
  81. cost2 = 200.45;
  82. cost3 = 1200.39;
  83. cost4 = 39.99;
  84.  
  85. //Calculate the total cost
  86. totalCost = cost1 + cost2 + cost3 + cost4;
  87.  
  88. //Calculate the average cost
  89. averageCost = totalCost / NUMBER_OF_ITEMS;
  90.  
  91. //Output the costs of the 4 items to the screen
  92. cout << "Cost of Item 1 is " << cost1 << endl;
  93. cout << "Cost of Item 2 is " << cost2 << endl;
  94. cout << "Cost of Item 3 is " << cost3 << endl;
  95. cout << "Cost of Item 4 is " << cost4 << endl;
  96. cout << endl;
  97.  
  98. //Output the total and average of the 4 items purchased to the screen.
  99. cout << "-----------------------------------------------------------------"
  100. << endl;
  101. cout << "Total Cost is " << totalCost << endl;
  102. cout << "Average Cost is " << averageCost << endl;
  103. cout << "-----------------------------------------------------------------"
  104. << endl;
  105.  
  106. //Assign the first and last initial
  107. firstInitial = 'C';
  108. lastInitial = 'S';
  109.  
  110. //Output the two initials to the screen
  111. cout << "The two initials are: " << firstInitial << '.'
  112. << lastInitial << '.' << endl;
  113. cout << "-----------------------------------------------------------------"
  114. << endl;
  115.  
  116. //Assign the name
  117. firstName = "Bolong";
  118. lastName = "Yu";
  119.  
  120. //Output the name to the screen
  121. cout << "The name is " << firstName << ' ' << lastName << endl;
  122. cout << "-----------------------------------------------------------------"
  123. << endl;
  124.  
  125. return 0;
  126.  
  127. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
-----------------------------------------------------------------
SUNY Broome Community College
Bolong Yu
Output from the practice
-----------------------------------------------------------------
The current quantity on hand is 66
The quantity to order is 134
-----------------------------------------------------------------
Cost of Item 1 is 12.5
Cost of Item 2 is 200.45
Cost of Item 3 is 1200.39
Cost of Item 4 is 39.99

-----------------------------------------------------------------
Total Cost is 1453.33
Average Cost is 363.333
-----------------------------------------------------------------
The two initials are: C.S.
-----------------------------------------------------------------
The name is Bolong Yu
-----------------------------------------------------------------