Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. // Total number of items
  5. int numItems(int totalItems[]) {
  6. int sum = 0;
  7. for (int i = 0; i < 4; i++) {
  8. sum += totalItems[i];
  9. }
  10. return sum;
  11. }
  12. //Average Profit / Total Profit
  13. double Avgprofit(int item_id[], double buying_price[], double selling_price[], double storage_fee[]) {
  14. double Total_profit = 0.0;
  15. int itemsTotal = 0;
  16. for (int i = 0; i < 4; i++) {
  17. Total_profit += item_id[i] * (selling_price[i] - (buying_price[i] + storage_fee[i]));
  18. itemsTotal += item_id[i];
  19.  
  20. }
  21. return Total_profit / itemsTotal;
  22. }
  23.  
  24. double Totalprofit(int num_items[], double buying_price[], double selling_price[], double storage_fee[], int item_id[]) {
  25. double profitTotal = 0.0;
  26. for (int i = 0; i < 4; i++) {
  27. profitTotal += num_items[i] * (selling_price[i] - (buying_price[i] + storage_fee[i]));
  28.  
  29. }
  30. return profitTotal;
  31. }
  32. //Average Buying Price / Sum Buying Price
  33. double avgBuy(double buying_price[], int item_id[]) {
  34. double buyTotal = 0.0;
  35. int itemTotal = 0;
  36. for (int i = 0; i < 4; i++) {
  37. buyTotal += buying_price[i] * item_id[i];
  38. itemTotal += item_id[i];
  39. }
  40. return buyTotal / itemTotal;
  41. }
  42. //Average Selling Price / Sum Selling Price
  43. double avgSell(double selling_price[], int item_id[]) {
  44. double dollarsTotal = 0.0;
  45. double itemsTotal = 0.0;
  46.  
  47. for (int i = 0; i < 4; i++) {
  48. dollarsTotal += selling_price[i] * item_id[i];
  49. itemsTotal += item_id[i];
  50. }
  51.  
  52. return dollarsTotal / itemsTotal;
  53. }
  54.  
  55.  
  56.  
  57.  
  58. int main() {
  59. int item_id[4];
  60. int num_items[4];
  61. double buying_price[4];
  62. double selling_price[4];
  63. double storage_fee[4];
  64. char option = 'd';
  65. for (int i = 0; i < 4; i++) {
  66. cout << "Please enter Item ID, Number of Items, Buying Price, Selling price, and Storage fees for Item: " << i + 1 << endl;
  67. cin >> item_id[i] >> num_items[i] >> buying_price[i] >> selling_price[i] >> storage_fee[i];
  68. }
  69. while (option != 'c') {
  70. cout << "Please choose one of the following options:" << endl;
  71. cout << "Option a: Print stock information" << endl;
  72. cout << "Option b: Print general information" << endl;
  73. cout << "Option c: Exit" << endl;
  74. cout << "Option: ";
  75. cin >> option;
  76. if (option == 'a') {
  77. for (int i = 0; i < 4; i++) {
  78. cout << "* Item Id: " << item_id[i] << endl;
  79. if (num_items[i] < 25) {
  80. cout << "* Number of Items: " << num_items[i] << " (Need more)" << endl;
  81. }
  82. else if (num_items[i] >= 25) {
  83. cout << "* Number of Items: " << num_items[i] << endl;
  84. }
  85. cout << "* Buying Price: " << setprecision(4) << "$" << buying_price[i] << endl;
  86. cout << "* Selling Price: " << setprecision(4) << "$" << selling_price[i] << endl;
  87. cout << "* Storage Fees: " << setprecision(4) << "$" << storage_fee[i] << endl;
  88. cout << "* Profit: " << setprecision(4) << "$" << num_items[i] * (selling_price[i] - (buying_price[i] + storage_fee[i])) << endl;
  89. }
  90. }
  91. if (option == 'b') {
  92. cout << "* Total Number of Items: " << numItems(num_items) << endl;
  93. cout << "* Total Profit: " << setprecision(4) << "$" << Totalprofit(num_items, buying_price, selling_price, storage_fee, item_id) << endl;
  94. cout << "* Average Profit: " << setprecision(4) << "$" << Avgprofit(item_id, buying_price, selling_price, storage_fee) << endl;
  95. cout << "* Average Buying Price: " << setprecision(4) << "$" << avgBuy(buying_price, item_id) << endl;
  96. cout << "* Average Selling Price: " << setprecision(4) << "$" << avgSell(selling_price, item_id) << endl;
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement