Advertisement
Guest User

Untitled

a guest
Nov 4th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. /*
  2. Raymond Ver
  3. Professor Pape
  4. raymond.c.ver@gmail.com
  5. CIS 22A
  6. 20 October 2015
  7. Lab 3 - Audio Visual Equipment
  8. */
  9.  
  10. #include <iostream>
  11. #include <iomanip>
  12. #include <stdlib.h>
  13. #include <string>
  14. #include <cctype>
  15.  
  16. using namespace std;
  17.  
  18. #define newreqPercent 0.9
  19. #define oldreqPercent 0.65
  20. #define newSugPercent 0.4
  21. #define oldSugPercent 0.2
  22. #define profitRatePercent 0.8
  23.  
  24. void signature()
  25. {
  26. string position, email, labNum;
  27. position = "Student :\t";
  28. email = "Email :\t";
  29. labNum = "Lab Number :\t";
  30. cout << position + "Raymond Ver\n";
  31. cout << email + "raymond.c.ver@gmail.com\n";
  32. cout << labNum + "4\n\n";
  33. }
  34.  
  35. double calcBooks(char, char, int);
  36. double calcProfit( double, int);
  37. void printOutput(string, int, double);
  38.  
  39. int main()
  40. {
  41. //Declaration of Variables
  42. string isbn;
  43. double pricePerCopy;
  44. double profit;
  45. int classNumber;
  46. int copiesNeeded;
  47. char reqOrSug;
  48. char newOrOld;
  49.  
  50.  
  51. //Asking user for input
  52. cout << "Enter book number (10 digits): ";
  53. cin >> isbn;
  54. cout << "Enter price per copy: ";
  55. cin >> pricePerCopy;
  56. cout << "Enter expected class enrollment:";
  57. cin >> classNumber;
  58. cout << "Enter 'R' if required or 'S' if suggested:";
  59. cin >> reqOrSug;
  60. reqOrSug = toupper(reqOrSug);
  61. cout << "Enter 'N' if new or 'O' if not a new text:";
  62. cin >> newOrOld;
  63. newOrOld = toupper(newOrOld);
  64.  
  65. //Print the number of books to be ordered
  66. copiesNeeded = static_cast<int>(calcBooks(reqOrSug, newOrOld, classNumber) + .5);
  67.  
  68. //Print out the profit of the store after paying 80%
  69. profit = calcProfit(pricePerCopy, copiesNeeded);
  70.  
  71. //Print out the 3 outputs
  72. printOutput(isbn, copiesNeeded, profit);
  73.  
  74.  
  75. cout << endl;
  76. signature();
  77. system("pause");
  78. return 0;
  79. }
  80. //end main
  81. ////////////////////////////////////////////
  82.  
  83. double calcBooks(char reqOrSug, char newOrOld, int classNumber)
  84. {
  85.  
  86. double copiesNeeded;
  87. if (reqOrSug == 'R')
  88. {
  89. if (newOrOld == 'N')
  90. {
  91. copiesNeeded = newreqPercent * classNumber +.5;
  92. }
  93. else if (newOrOld == 'O')
  94. {
  95. copiesNeeded = oldreqPercent * classNumber;
  96. }
  97. else
  98. {
  99. cout << "\n\nError\n\n";
  100. system("pause");
  101. exit(42);
  102. }
  103. }
  104. else if (reqOrSug == 'S')
  105. {
  106. if (newOrOld == 'N')
  107. {
  108. copiesNeeded = newSugPercent * classNumber;
  109. }
  110. else if (newOrOld == 'O')
  111. {
  112. copiesNeeded = oldSugPercent * classNumber;
  113. }
  114. else
  115. {
  116. cout << "\n\nError\n\n";
  117. system("pause");
  118. exit(42);
  119. }
  120. }
  121. else
  122. {
  123. cout << "\n\nError\n\n";
  124. system("pause");
  125. exit (42);
  126. }
  127.  
  128. return copiesNeeded;
  129. }
  130.  
  131.  
  132. double calcProfit(double pricePerCopy, int copiesNeeded)
  133. {
  134. double profit;
  135. profit = (pricePerCopy * copiesNeeded) - ((pricePerCopy * copiesNeeded) * profitRatePercent);
  136.  
  137. return profit;
  138. }
  139.  
  140.  
  141. void printOutput(string isbn, int copiesNeeded, double profit)
  142. {
  143. cout << setprecision(2) << fixed;
  144. cout << endl;
  145. cout << endl;
  146. cout << "ISBN :\t" << isbn << endl;
  147. cout << "Copies Needed :\t" << copiesNeeded << endl;
  148. cout << "Profit :\t" << "$" << profit << endl;
  149.  
  150. return;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement