Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include "time.h"
  5. #include <string>
  6. #include <iomanip>
  7. using namespace std;
  8. struct specs {
  9. string manufacturer;
  10. char *color;
  11. int section;
  12. int freezerSize;
  13. int coolingchamberSize;
  14. int height;
  15. int numofshelves;
  16. float freezerT;
  17. float coolingchamberT;
  18. };
  19. struct contents {
  20. bool apples;
  21. bool cheese;
  22. bool milk;
  23. bool eggs;
  24. bool cmeat;
  25. bool beef;
  26. bool pork;
  27. bool carrot;
  28. bool ketchup;
  29. bool mayonnaise;
  30. };
  31. struct refrig {
  32. specs specs;
  33. contents contents;
  34. };
  35. float randFL(float a, float b) {
  36. float y;
  37. int x;
  38. x = rand();
  39. y = a + (x * (b - a)) / RAND_MAX;
  40. return y;
  41. }
  42. refrig FRIDGE;
  43. void fill() {
  44. srand(time(0));
  45. const string man[6] = { "LG", "Beko", "Samsung", "Siemens", "Vestfrost", "Liebherr" };
  46. FRIDGE.specs.manufacturer = man[rand() % 6];
  47. FRIDGE.specs.color = rand() % 2 ? "White" : "Silver";
  48. FRIDGE.specs.section = 1 + rand() % 2;
  49. vector <int> ccSize = { 500, 600, 700, 800 };
  50. FRIDGE.specs.coolingchamberSize = ccSize[rand() % ccSize.size()];
  51. switch (FRIDGE.specs.coolingchamberSize) {
  52. case 500: {
  53. FRIDGE.specs.freezerSize = 400;
  54. FRIDGE.specs.height = 1500 + rand() % 101;
  55. break;
  56. }
  57. case 600: {
  58. FRIDGE.specs.freezerSize = 500;
  59. FRIDGE.specs.height = 1600 + rand() % 151;
  60. break;
  61. }
  62. case 700: {
  63. FRIDGE.specs.freezerSize = 600;
  64. FRIDGE.specs.height = 1750 + rand() % 151;
  65. break;
  66. }
  67. case 800: {
  68. FRIDGE.specs.freezerSize = 700;
  69. FRIDGE.specs.height = 1900 + rand() % 101;
  70. break;
  71. }
  72. }
  73. FRIDGE.specs.numofshelves = 5 + rand() % 6;
  74. FRIDGE.specs.freezerT = randFL(10, 20);
  75. FRIDGE.specs.coolingchamberT = randFL(2, 6);
  76. FRIDGE.contents.apples = rand() % 2;
  77. FRIDGE.contents.cheese = rand() % 2;
  78. FRIDGE.contents.milk = rand() % 2;
  79. FRIDGE.contents.eggs = rand() % 2;
  80. FRIDGE.contents.cmeat = rand() % 2;
  81. FRIDGE.contents.beef = rand() % 2;
  82. FRIDGE.contents.pork = rand() % 2;
  83. FRIDGE.contents.carrot = rand() % 2;
  84. FRIDGE.contents.ketchup = rand() % 2;
  85. FRIDGE.contents.mayonnaise = rand() % 2;
  86. }
  87. void print() {
  88. cout << "=== Specification ===" << endl;
  89. cout << "Manufacturer: " << FRIDGE.specs.manufacturer << endl;
  90. cout << "Color: " << FRIDGE.specs.color << endl;
  91. cout << "Section: " << FRIDGE.specs.section << endl;
  92. cout << "Coolingc hamber size: " << FRIDGE.specs.coolingchamberSize << endl;
  93. cout << "Freezer size: " << FRIDGE.specs.freezerSize << endl;
  94. cout << "Height: " << FRIDGE.specs.height << endl;
  95. cout << "Number of shelves " << FRIDGE.specs.numofshelves << endl;
  96. cout << "Coolingc hamber temp: +" << fixed << setprecision(1) << FRIDGE.specs.coolingchamberT << endl;
  97. cout << "Freezer temp: -" << fixed << setprecision(1) << FRIDGE.specs.freezerT << endl;
  98. cout << "\n===== Contents =====" << endl;
  99. vector<string> c;
  100. if (FRIDGE.contents.apples)
  101. c.push_back("Apples");
  102. if (FRIDGE.contents.cheese)
  103. c.push_back("Cheese");
  104. if (FRIDGE.contents.milk)
  105. c.push_back("Milk");
  106. if (FRIDGE.contents.eggs)
  107. c.push_back("Eggs");
  108. if (FRIDGE.contents.cmeat)
  109. c.push_back("Chicken meat");
  110. if (FRIDGE.contents.beef)
  111. c.push_back("Beef");
  112. if (FRIDGE.contents.pork)
  113. c.push_back("Pork");
  114. if (FRIDGE.contents.carrot)
  115. c.push_back("Carrot");
  116. if (FRIDGE.contents.ketchup)
  117. c.push_back("Ketchup");
  118. if (FRIDGE.contents.mayonnaise)
  119. c.push_back("Mayonnaise");
  120. for (int i = 0; i < c.size(); i++) {
  121. cout << c[i];
  122. if (i < c.size() - 1) {
  123. cout << ", ";
  124. }
  125. else {
  126. cout << "."<< endl;
  127. }
  128. }
  129. }
  130. int main() {
  131. fill();
  132. print();
  133. system("pause");
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement