Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include "time.h"
- #include <string>
- #include <iomanip>
- using namespace std;
- struct specs {
- string manufacturer;
- char *color;
- int section;
- int freezerSize;
- int coolingchamberSize;
- int height;
- int numofshelves;
- float freezerT;
- float coolingchamberT;
- };
- struct contents {
- bool apples;
- bool cheese;
- bool milk;
- bool eggs;
- bool cmeat;
- bool beef;
- bool pork;
- bool carrot;
- bool ketchup;
- bool mayonnaise;
- };
- struct refrig {
- specs specs;
- contents contents;
- };
- float randFL(float a, float b) {
- float y;
- int x;
- x = rand();
- y = a + (x * (b - a)) / RAND_MAX;
- return y;
- }
- refrig FRIDGE;
- void fill() {
- srand(time(0));
- const string man[6] = { "LG", "Beko", "Samsung", "Siemens", "Vestfrost", "Liebherr" };
- FRIDGE.specs.manufacturer = man[rand() % 6];
- FRIDGE.specs.color = rand() % 2 ? "White" : "Silver";
- FRIDGE.specs.section = 1 + rand() % 2;
- vector <int> ccSize = { 500, 600, 700, 800 };
- FRIDGE.specs.coolingchamberSize = ccSize[rand() % ccSize.size()];
- switch (FRIDGE.specs.coolingchamberSize) {
- case 500: {
- FRIDGE.specs.freezerSize = 400;
- FRIDGE.specs.height = 1500 + rand() % 101;
- break;
- }
- case 600: {
- FRIDGE.specs.freezerSize = 500;
- FRIDGE.specs.height = 1600 + rand() % 151;
- break;
- }
- case 700: {
- FRIDGE.specs.freezerSize = 600;
- FRIDGE.specs.height = 1750 + rand() % 151;
- break;
- }
- case 800: {
- FRIDGE.specs.freezerSize = 700;
- FRIDGE.specs.height = 1900 + rand() % 101;
- break;
- }
- }
- FRIDGE.specs.numofshelves = 5 + rand() % 6;
- FRIDGE.specs.freezerT = randFL(10, 20);
- FRIDGE.specs.coolingchamberT = randFL(2, 6);
- FRIDGE.contents.apples = rand() % 2;
- FRIDGE.contents.cheese = rand() % 2;
- FRIDGE.contents.milk = rand() % 2;
- FRIDGE.contents.eggs = rand() % 2;
- FRIDGE.contents.cmeat = rand() % 2;
- FRIDGE.contents.beef = rand() % 2;
- FRIDGE.contents.pork = rand() % 2;
- FRIDGE.contents.carrot = rand() % 2;
- FRIDGE.contents.ketchup = rand() % 2;
- FRIDGE.contents.mayonnaise = rand() % 2;
- }
- void print() {
- cout << "=== Specification ===" << endl;
- cout << "Manufacturer: " << FRIDGE.specs.manufacturer << endl;
- cout << "Color: " << FRIDGE.specs.color << endl;
- cout << "Section: " << FRIDGE.specs.section << endl;
- cout << "Coolingc hamber size: " << FRIDGE.specs.coolingchamberSize << endl;
- cout << "Freezer size: " << FRIDGE.specs.freezerSize << endl;
- cout << "Height: " << FRIDGE.specs.height << endl;
- cout << "Number of shelves " << FRIDGE.specs.numofshelves << endl;
- cout << "Coolingc hamber temp: +" << fixed << setprecision(1) << FRIDGE.specs.coolingchamberT << endl;
- cout << "Freezer temp: -" << fixed << setprecision(1) << FRIDGE.specs.freezerT << endl;
- cout << "\n===== Contents =====" << endl;
- vector<string> c;
- if (FRIDGE.contents.apples)
- c.push_back("Apples");
- if (FRIDGE.contents.cheese)
- c.push_back("Cheese");
- if (FRIDGE.contents.milk)
- c.push_back("Milk");
- if (FRIDGE.contents.eggs)
- c.push_back("Eggs");
- if (FRIDGE.contents.cmeat)
- c.push_back("Chicken meat");
- if (FRIDGE.contents.beef)
- c.push_back("Beef");
- if (FRIDGE.contents.pork)
- c.push_back("Pork");
- if (FRIDGE.contents.carrot)
- c.push_back("Carrot");
- if (FRIDGE.contents.ketchup)
- c.push_back("Ketchup");
- if (FRIDGE.contents.mayonnaise)
- c.push_back("Mayonnaise");
- for (int i = 0; i < c.size(); i++) {
- cout << c[i];
- if (i < c.size() - 1) {
- cout << ", ";
- }
- else {
- cout << "."<< endl;
- }
- }
- }
- int main() {
- fill();
- print();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement