wxns

clothing-customisation-program-cpp

Dec 28th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.89 KB | None | 0 0
  1. // MAIN CLASS OF MY PROGRAM
  2.  
  3. #include "program_libraries.h"
  4. #include <iostream>
  5.  
  6. int ConvertToInt(std::string a);
  7. int CheckValidIntInput(int a, std::string b);
  8.  
  9. int main()
  10. {
  11.     srand(time(0)); // random values as per current system time
  12.     std::string userClothingCategories;
  13.     int userNoClothingCategories;
  14.     std::cout << "How many clothing categories do you want? (2-10, default 3) " << std::endl;
  15.  
  16.     bool validInput = false;
  17.     do {
  18.  
  19.         userNoClothingCategories = ConvertToInt(userClothingCategories);
  20.  
  21.         if (userNoClothingCategories == -1) {
  22.             std::cout << "Sorry, that is not valid input. Please try again" << std::endl;
  23.             validInput = false;
  24.  
  25.         } else if (userNoClothingCategories == 0){
  26.             userNoClothingCategories = 3;
  27.             validInput = true;
  28.         } else {
  29.             validInput = true;
  30.         }
  31.     } while (!validInput);
  32.  
  33.     std::cout << "You have chosen "<< userNoClothingCategories << " clothing categories."<< std::endl;
  34.  
  35.     std::vector<std::vector<std::string>> myVector;
  36.     for (int i = 0; i < userNoClothingCategories; i++){ // add "first columns" to data
  37.         myVector.push_back(std::vector<std::string>());
  38.     }
  39.     std::cout << myVector.size() << std::endl;
  40.     // switch statement to choose what to modify?
  41.     myVector[0].push_back("Top: ");
  42.     UserTop top1; // apply brackets only when intend to modify default value
  43.     UserTop top2;
  44.     UserTop top3;
  45.     UserTop top4;
  46.     UserTop * pTop4 = &top4; // create pointer to class
  47.     std::string userGarmentChoice;
  48.     int IUserGarmentChoice;
  49.     std::cout << "Choose the sleeves you would like for your garment: " << std::endl;
  50.  
  51.     std::cout << pTop4 -> sleevesMap[CheckValidIntInput(IUserGarmentChoice, userGarmentChoice)] << std::endl; // access class variable using pointers
  52.  
  53.     myVector[0].push_back(top1.GetUserTopName() + " " + top1.RCut + " " + top1.RSleeve + " " + top1.RCollar + " " + top1.RZipButton);
  54.  
  55.  
  56.  
  57.     for (int i = 0; i < myVector[0].size(); i++){
  58.         std::cout << myVector[0].at(i) << std::endl;
  59.     }
  60.  
  61.     // std::cout << myVector[0].at(0) << std::endl;
  62.     return 0;
  63. }
  64. int ConvertToInt(std::string a){
  65.     int x = 0;
  66.     std::getline(std::cin, a);
  67.     std::istringstream inputStream(a);
  68.     inputStream >> x;
  69.     if (inputStream.eof() == true || std::cin.fail()){
  70.         return x;
  71.     } else {
  72.         return -1;
  73.     }
  74. }
  75. int CheckValidIntInput(int a, std::string b){
  76.     bool validInput = false;
  77.     do {
  78.         a = ConvertToInt(b);
  79.         if (a == -1){
  80.             std::cout << "Sorry, invalid input, please try again" << std::endl;
  81.             validInput = false;
  82.         } else {
  83.             validInput = true;
  84.         }
  85.     } while(!validInput);
  86.     return a;
  87. }
  88.  
  89. // PROGRAM LIBRARIES
  90. #ifndef PROGRAM_LIBRARIES_H_INCLUDED
  91. #define PROGRAM_LIBRARIES_H_INCLUDED
  92.  
  93. #include <iostream>
  94. #include <string>
  95. #include <sstream>
  96. #include <vector>
  97. #include <cstdlib>
  98. #include <ctime>
  99. #include <map>
  100. #include "UserTop.h"
  101.  
  102.  
  103. #endif // PROGRAM_LIBRARIES_H_INCLUDED
  104. // HEADER FILE FOR USERTOP CLASS
  105. #ifndef USERTOP_H
  106. #define USERTOP_H
  107. // header file contains variables and declarations for methods
  108. #include <iostream>
  109. #include <string>
  110. #include <map>
  111. static int instanceNo = 0;
  112.  
  113. class UserTop
  114. {
  115.     public:
  116.  
  117.     int condRandZipBut();
  118.     std::string GetUserTopName();
  119.     void SetUserTopName(std::string a);
  120.  
  121.     UserTop(std::string ab = "userTop"); // declare default constructor arguments only here
  122.  
  123.     virtual ~UserTop();
  124.  
  125.  
  126.     std::map<int, std::string> sleevesMap = {
  127.         { 0, "sleeveless" },
  128.         { 1, "cap sleeved" },
  129.         { 2, "short sleeved" },
  130.         { 3, "3/4 length sleeved" },
  131.         { 4, "long sleeved" },
  132.  
  133.     };
  134.  
  135.     std::map <int, std::string> topCut = {
  136.         { 0, "regular" },
  137.         { 1, "halter top" },
  138.         { 2, "V-neck" },
  139.         { 3, "A-shirt" },
  140.         { 4, "baseball shirt" },
  141.     };
  142.  
  143.     std::map<int, std::string> collarMap = {
  144.         { 0, "none" },
  145.         { 1, "hood" },
  146.         { 2, "rounded small collar" },
  147.         { 3, "rounded large flat collar" },
  148.         { 4, "rectangular small collar" },
  149.         { 5, "rectangular large collar" },
  150.     };
  151.     std::map<int, std::string> zipbutMap = {
  152.         { 0, "none" },
  153.         { 1, "symmetric zip down top" },
  154.         { 2, "symmetric buttons down top" },
  155.         { 3, "asymmetric zip down top" },
  156.         { 4, "asymmetric button down top" },
  157.         { 5, "zip, for detachable hood" },
  158.         { 6, "buttons, for detachable hood" },
  159.         { 7, "zip, for detachable sleeves" },
  160.         { 8, "buttons, for detachable sleeves" },
  161.     };
  162.  
  163.  
  164.         std::string topName;
  165.         int IRSleeve = 0+rand()%sleevesMap.size();
  166.         int IRCollar = 0+rand()%collarMap.size();
  167.         std::string RCut;
  168.         std::string RSleeve = "Sleeves:\t" + sleevesMap[IRSleeve]; // random sleeve
  169.         std::string RCollar = "Collar: \t" + collarMap[IRCollar];// random collar
  170.         std::string RZipButton = "Zip/button:\t" + zipbutMap[condRandZipBut()]; // random zip/button, functional and decorative
  171.         std::string RPockets; // random number and position of pockets including inside of garment
  172.         std::string ROther; // decorations, such as badges, patches stickers etc.
  173.         std::string RWear; // tucked in/out of bottoms, outer/middle/inner layer
  174.         std::string RMaterial; // random clothing material (can apply to whole item of clothing or specific parts
  175.         // std::string topCut; // include?
  176.  
  177.         std::string SInstanceNo = std::to_string(instanceNo);
  178.         private:
  179.         protected:
  180. };
  181.  
  182.  
  183. #endif // USERTOP_H
  184. // SOURCE FILE FOR USERTOP
  185. #include "UserTop.h"
  186. #include <iostream>
  187. #include <string>
  188. // definition of methods here, including constructor and destructor
  189.  
  190. UserTop::UserTop(std::string ab)
  191. {
  192.     std::cout << "\nObject is being created.. " << std::endl;
  193.     instanceNo++;
  194.     SetUserTopName(ab);
  195.  
  196.     std::cout << GetUserTopName() << std::endl;
  197.  
  198.     std::cout << RSleeve << std::endl;
  199.     std::cout << RCollar << std::endl;
  200.     std::cout << RZipButton << std::endl;
  201.     //ctor
  202. }
  203. int UserTop::condRandZipBut() {
  204.     int mapSize = zipbutMap.size();
  205.     int finalResult;
  206.     int x = 0 + rand() %mapSize;
  207.     if (IRSleeve == 0) {
  208.         x = 0 + rand() % mapSize - 2;
  209.         finalResult = x;
  210.     } else if (IRCollar == 0 || IRCollar > 1) { // strictly if no hood
  211.         do {
  212.             x = 0 + rand()%mapSize;
  213.         } while (x == 5 || x == 6); // regenerate another zipper type
  214.         finalResult = x;
  215.     } else {
  216.         finalResult = x;
  217.     }
  218.     return finalResult;
  219. }
  220.  
  221. std::string UserTop::GetUserTopName() { // or UserTop::getUserName( void )
  222.     return topName;
  223. }
  224. void UserTop::SetUserTopName(std::string a){
  225.     topName = a + SInstanceNo;
  226. }
  227.  
  228. UserTop::~UserTop()
  229. {
  230.     // std::cout << "Class destroyed" << std::endl;
  231.     //dtor
  232. }
Advertisement
Add Comment
Please, Sign In to add comment