Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAIN CLASS OF MY PROGRAM
- #include "program_libraries.h"
- #include <iostream>
- int ConvertToInt(std::string a);
- int CheckValidIntInput(int a, std::string b);
- int main()
- {
- srand(time(0)); // random values as per current system time
- std::string userClothingCategories;
- int userNoClothingCategories;
- std::cout << "How many clothing categories do you want? (2-10, default 3) " << std::endl;
- bool validInput = false;
- do {
- userNoClothingCategories = ConvertToInt(userClothingCategories);
- if (userNoClothingCategories == -1) {
- std::cout << "Sorry, that is not valid input. Please try again" << std::endl;
- validInput = false;
- } else if (userNoClothingCategories == 0){
- userNoClothingCategories = 3;
- validInput = true;
- } else {
- validInput = true;
- }
- } while (!validInput);
- std::cout << "You have chosen "<< userNoClothingCategories << " clothing categories."<< std::endl;
- std::vector<std::vector<std::string>> myVector;
- for (int i = 0; i < userNoClothingCategories; i++){ // add "first columns" to data
- myVector.push_back(std::vector<std::string>());
- }
- std::cout << myVector.size() << std::endl;
- // switch statement to choose what to modify?
- myVector[0].push_back("Top: ");
- UserTop top1; // apply brackets only when intend to modify default value
- UserTop top2;
- UserTop top3;
- UserTop top4;
- UserTop * pTop4 = &top4; // create pointer to class
- std::string userGarmentChoice;
- int IUserGarmentChoice;
- std::cout << "Choose the sleeves you would like for your garment: " << std::endl;
- std::cout << pTop4 -> sleevesMap[CheckValidIntInput(IUserGarmentChoice, userGarmentChoice)] << std::endl; // access class variable using pointers
- myVector[0].push_back(top1.GetUserTopName() + " " + top1.RCut + " " + top1.RSleeve + " " + top1.RCollar + " " + top1.RZipButton);
- for (int i = 0; i < myVector[0].size(); i++){
- std::cout << myVector[0].at(i) << std::endl;
- }
- // std::cout << myVector[0].at(0) << std::endl;
- return 0;
- }
- int ConvertToInt(std::string a){
- int x = 0;
- std::getline(std::cin, a);
- std::istringstream inputStream(a);
- inputStream >> x;
- if (inputStream.eof() == true || std::cin.fail()){
- return x;
- } else {
- return -1;
- }
- }
- int CheckValidIntInput(int a, std::string b){
- bool validInput = false;
- do {
- a = ConvertToInt(b);
- if (a == -1){
- std::cout << "Sorry, invalid input, please try again" << std::endl;
- validInput = false;
- } else {
- validInput = true;
- }
- } while(!validInput);
- return a;
- }
- // PROGRAM LIBRARIES
- #ifndef PROGRAM_LIBRARIES_H_INCLUDED
- #define PROGRAM_LIBRARIES_H_INCLUDED
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <vector>
- #include <cstdlib>
- #include <ctime>
- #include <map>
- #include "UserTop.h"
- #endif // PROGRAM_LIBRARIES_H_INCLUDED
- // HEADER FILE FOR USERTOP CLASS
- #ifndef USERTOP_H
- #define USERTOP_H
- // header file contains variables and declarations for methods
- #include <iostream>
- #include <string>
- #include <map>
- static int instanceNo = 0;
- class UserTop
- {
- public:
- int condRandZipBut();
- std::string GetUserTopName();
- void SetUserTopName(std::string a);
- UserTop(std::string ab = "userTop"); // declare default constructor arguments only here
- virtual ~UserTop();
- std::map<int, std::string> sleevesMap = {
- { 0, "sleeveless" },
- { 1, "cap sleeved" },
- { 2, "short sleeved" },
- { 3, "3/4 length sleeved" },
- { 4, "long sleeved" },
- };
- std::map <int, std::string> topCut = {
- { 0, "regular" },
- { 1, "halter top" },
- { 2, "V-neck" },
- { 3, "A-shirt" },
- { 4, "baseball shirt" },
- };
- std::map<int, std::string> collarMap = {
- { 0, "none" },
- { 1, "hood" },
- { 2, "rounded small collar" },
- { 3, "rounded large flat collar" },
- { 4, "rectangular small collar" },
- { 5, "rectangular large collar" },
- };
- std::map<int, std::string> zipbutMap = {
- { 0, "none" },
- { 1, "symmetric zip down top" },
- { 2, "symmetric buttons down top" },
- { 3, "asymmetric zip down top" },
- { 4, "asymmetric button down top" },
- { 5, "zip, for detachable hood" },
- { 6, "buttons, for detachable hood" },
- { 7, "zip, for detachable sleeves" },
- { 8, "buttons, for detachable sleeves" },
- };
- std::string topName;
- int IRSleeve = 0+rand()%sleevesMap.size();
- int IRCollar = 0+rand()%collarMap.size();
- std::string RCut;
- std::string RSleeve = "Sleeves:\t" + sleevesMap[IRSleeve]; // random sleeve
- std::string RCollar = "Collar: \t" + collarMap[IRCollar];// random collar
- std::string RZipButton = "Zip/button:\t" + zipbutMap[condRandZipBut()]; // random zip/button, functional and decorative
- std::string RPockets; // random number and position of pockets including inside of garment
- std::string ROther; // decorations, such as badges, patches stickers etc.
- std::string RWear; // tucked in/out of bottoms, outer/middle/inner layer
- std::string RMaterial; // random clothing material (can apply to whole item of clothing or specific parts
- // std::string topCut; // include?
- std::string SInstanceNo = std::to_string(instanceNo);
- private:
- protected:
- };
- #endif // USERTOP_H
- // SOURCE FILE FOR USERTOP
- #include "UserTop.h"
- #include <iostream>
- #include <string>
- // definition of methods here, including constructor and destructor
- UserTop::UserTop(std::string ab)
- {
- std::cout << "\nObject is being created.. " << std::endl;
- instanceNo++;
- SetUserTopName(ab);
- std::cout << GetUserTopName() << std::endl;
- std::cout << RSleeve << std::endl;
- std::cout << RCollar << std::endl;
- std::cout << RZipButton << std::endl;
- //ctor
- }
- int UserTop::condRandZipBut() {
- int mapSize = zipbutMap.size();
- int finalResult;
- int x = 0 + rand() %mapSize;
- if (IRSleeve == 0) {
- x = 0 + rand() % mapSize - 2;
- finalResult = x;
- } else if (IRCollar == 0 || IRCollar > 1) { // strictly if no hood
- do {
- x = 0 + rand()%mapSize;
- } while (x == 5 || x == 6); // regenerate another zipper type
- finalResult = x;
- } else {
- finalResult = x;
- }
- return finalResult;
- }
- std::string UserTop::GetUserTopName() { // or UserTop::getUserName( void )
- return topName;
- }
- void UserTop::SetUserTopName(std::string a){
- topName = a + SInstanceNo;
- }
- UserTop::~UserTop()
- {
- // std::cout << "Class destroyed" << std::endl;
- //dtor
- }
Advertisement
Add Comment
Please, Sign In to add comment