void prizeMenu () {
    Prize prize1;
    Prize prize2;
    CinReader reader;
    string p1Name;
    unsigned int p1Value = 0;
    string p2Name;
    unsigned int p2Value = 0;
    
    while (true) {
        system("clear");
        cout << "PRIZE TEST\n" << endl;
        cout << "Prize info -> " << prize1.getPrizeName() << ", $" << prize1.getPrizeValue() << endl;
        cout << "[1] Prize name" << endl;
        cout << "[2] Prize value" << endl;
        cout << "[3] Compare two prizes" << endl;
        cout << "[0] Back to main menu" << endl;
        cout << "Your choice: ";
        
        switch (reader.readInt(0,3)) {
            case 0:
                system("clear");
                prize1.~Prize();
                mainMenu ();
                break;
            case 1:
                system("clear");
                cout << "Prize name: " << prize1.getPrizeName() << endl;
                cout << "\nUpdate (y/n)? ";
                
                if (reader.readChar("yn") == 'y') {
                    cout << "\nEnter new prize name: ";
                        prize1.setPrizeName(reader.readString());
                    cout << "\nPrize name updated." << endl;
                }
                
                pause ();
                break;
            case 2:
                system("clear");
                cout << "Prize value: " << prize1.getPrizeValue() << endl;
                cout << "\nUpdate (y/n)? ";
                
                if (reader.readChar("yn") == 'y') {
                    cout << "\nEnter new prize value: ";
                        prize1.setPrizeValue(reader.readInt());
                    cout << "\nPrize value updated." << endl;
                }
                
                pause ();
                break;
            case 3:
                system("clear");
                cout << "First, set the Name and Value of the prizes being compared.\n" << endl;
                cout << "Prize 1 ->" << endl;
                cout << "Prize name (current = NO NAME): ";
                    p1Name = reader.readString();
                cout << "Prize value (current = 0): ";
                    p1Value = reader.readInt();
                cout << "\nPrize 2 ->" << endl;
                cout << "Prize name (current = NO NAME): ";
                    p2Name = reader.readString();
                cout << "Prize value (current = 0): ";
                    p2Value = reader.readInt();
                  
                Prize prize1(p1Name, p1Value); 
                Prize prize2(p2Name, p2Value);
                if (prize1 == prize2) {
                    cout << "Yes. The two prizes are the same." << endl;
                } else {
                    cout << "No. The two prizes are not the same." << endl;
                }
            
                pause ();
                break;
        }
    }
}
void menu() {
    
    //set up the default prize and box
    Prize prize1;
    Box box1;
    
    //set up the custom prize and box
    string pName;
    unsigned int pValue = 0;
    cout << "Please enter values for the Custom Prize\n"
         << "Name: ";
    pName = reader.readString(false);
    cout << "Value: ";
    pValue = reader.readInt(0);
    Prize prize2(pName, pValue);
    
    unsigned int bNum = 0, bPrizeCap = 0;
    string bColor;
    cout << "Please enter Stats for the Custom Box\n"
         << "Number: ";
    bNum = reader.readInt(0);
    cout << "Color: ";
    bColor = reader.readString(false);
    cout << "Prize Capacity: ";
    bPrizeCap = reader.readInt(0);
    Box box2(bNum, bColor, bPrizeCap);
    clearScreen();
    
    //variable to hold the user's choice from the menu
    char user_choice;
    
    //bool for looping the menu
    bool menu_loop = true;
    while (menu_loop == true){
        cout << "*** Which function would you like to test? ***\n"
             << "Create Custom Objects to Unlock More Functions\n"
             << "[A] Display the Stats of the Default Prize\n"
             << "[B] Display the Stats of the Custom Prize\n"
             << "[C] Change the Name of the Custom Prize\n"
             << "[D] Change the Value of the Custom Prize\n"
             << "[E] Display the Stats of the Default Box\n"
             << "[F] Display the Stats of the Custom Box\n"
             << "[G] Change the Number of the Custom Box\n"
             << "[H] Change the Color of the Custom Box\n"
             << "[I] Add the Default Prize to the Custom Box\n"
             << "[J] Add the Custom Prize to the Custom Box\n"
             << "[K] List all the Prizes in the Custom Box\n"
             << "[L] Remove a Specific Prize from the Custom Box\n"
             << "[M] Compare two Prizes from the Custom Box\n"
             << "        [Q] to Quit the Interactive Test\n"
             << " ";
        user_choice = reader.readChar("AaBbCcDdEeFfGgHhIiJjKkLlMmNnQq");
        switch (toupper(user_choice)){
            
            //Display Name and Value of prize1
            case 'A':
                clearScreen();
                cout << "Default Prize\n" 
                     << "-Name: " << prize1.getPrizeName() << "\n"
                     << "-Value: " << prize1.getPrizeValue() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Display Name and Value of prize2
            case 'B':
                clearScreen();
                cout << "Custom Prize\n" 
                     << "-Name: " << prize2.getPrizeName() << "\n"
                     << "-Value: " << prize2.getPrizeValue() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Change the name of prize2
            case 'C':
                clearScreen();
                cout << "Enter the New Name for the Custom Prize: "; 
                prize2.setPrizeName(reader.readString(false));
                clearScreen();
                cout << "Custom Prize\n" 
                     << "-Name: " << prize2.getPrizeName() << "\n"
                     << "-Value: " << prize2.getPrizeValue() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Change the value of prize2
            case 'D':
                clearScreen();
                cout << "Enter a New Value for the Custom Prize: ";
                prize2.setPrizeValue(reader.readInt(0));
                clearScreen();
                cout << "Custom Prize\n" 
                     << "-Name: " << prize2.getPrizeName() << "\n"
                     << "-Value: " << prize2.getPrizeValue() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Display the Number, Color, and Capacity of box1
            case 'E':
                clearScreen();
                cout << "Default Box\n" 
                     << "-Number: " << box1.getBoxNumber() << "\n"
                     << "-Color: " << box1.getBoxColor() << "\n"
                     << "-Prize Count: " << box1.getPrizeCount() << "\n"
                     << "-Prize Capacity: " << box1.getPrizeCapacity() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Display the Number, Color, and Capacity of box2
            case 'F':
                clearScreen();
                cout << "Custom Box\n" 
                     << "-Number: " << box2.getBoxNumber() << "\n"
                     << "-Color: " << box2.getBoxColor() << "\n"
                     << "-Prize Count: " << box2.getPrizeCount() << "\n"
                     << "-Prize Capacity: " << box2.getPrizeCapacity() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Change the number of of box2
            case 'G':
                clearScreen();
                cout << "Enter a New Number for the Custom Box: ";
                box2.setBoxNumber(reader.readInt(0));
                clearScreen();
                cout << "Custom Box\n" 
                     << "-Number: " << box2.getBoxNumber() << "\n"
                     << "-Color: " << box2.getBoxColor() << "\n"
                     << "-Prize Count: " << box2.getPrizeCount() << "\n"
                     << "-Prize Capacity: " << box2.getPrizeCapacity() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Change the color of box2
            case 'H':
                clearScreen();
                cout << "Enter a New Color for the Custom Box: ";
                box2.setBoxColor(reader.readString(false));
                clearScreen();
                cout << "Custom Box\n" 
                     << "-Number: " << box2.getBoxNumber() << "\n"
                     << "-Color: " << box2.getBoxColor() << "\n"
                     << "-Prize Count: " << box2.getPrizeCount() << "\n"
                     << "-Prize Capacity: " << box2.getPrizeCapacity() << endl;
                enterToContinue();
                clearScreen();
                break;
                
            //Add prize1 to box2 if there is room
            case 'I':
                clearScreen();
                if (box2.getPrizeCount() < box2.getPrizeCapacity()){
                    box2.addPrize(prize1);
                    cout << "***The Default Prize has been Added to the Custom Box.\n"
                         << "Custom Box\n" 
                         << "-Number: " << box2.getBoxNumber() << "\n"
                         << "-Color: " << box2.getBoxColor() << "\n"
                         << "-Prize Count: " << box2.getPrizeCount() << "\n"
                         << "-Prize Capacity: " << box2.getPrizeCapacity() << endl;
                } else {
                    cout << "The Box is full, remove a Prize to Add a new Prize.\n";
                }
                enterToContinue();
                clearScreen();
                break;
                
            //Add prize2 to box2 if there is room
            case 'J':
                clearScreen();
                if (box2.getPrizeCount() < box2.getPrizeCapacity()){
                    box2.addPrize(prize2);
                    cout << "***The Custom Prize has been Added to the Custom Box.\n"
                         << "Custom Box\n" 
                         << "-Number: " << box2.getBoxNumber() << "\n"
                         << "-Color: " << box2.getBoxColor() << "\n"
                         << "-Prize Count: " << box2.getPrizeCount() << "\n"
                         << "-Prize Capacity: " << box2.getPrizeCapacity() << endl;
                } else {
                    cout << "The Box is full, remove a Prize to Add a new Prize.\n";
                }
                enterToContinue();
                clearScreen();
                break;
                
            //Display the name and value of each prize in box2
            case 'K':
                clearScreen();
                for (unsigned int i = 0; i < box2.getPrizeCount(); i++){
                    cout << "-Name: " << box2.getPrize(i).getPrizeName() << "\n"
                         << "-Value: " << box2.getPrize(i).getPrizeValue() << "\n" << endl;
                }
                enterToContinue();
                clearScreen();
                break;
                
            //Remove a specific prize from box2, if there are prizes to remove
            case 'L':
                clearScreen();
                if (box2.getPrizeCount() > 0){
                    cout << "Which Prize would you like to Remove?\n"
                         << "(1 for first prize, 2 for second prize, etc)" << endl;
                    box2.removePrize((reader.readInt(1, box2.getPrizeCount())) - 1);
                    clearScreen();
                    cout << "***The Prize has been Removed from the Custom Box.\n"
                         << "Custom Box\n" 
                         << "-Number: " << box2.getBoxNumber() << "\n"
                         << "-Color: " << box2.getBoxColor() << "\n"
                         << "-Prize Count: " << box2.getPrizeCount() << "\n"
                         << "-Prize Capacity: " << box2.getPrizeCapacity() << endl;
                } else {
                    cout << "There are no Prizes to Remove.  Add a Prize to Remove it.\n";
                }
                enterToContinue();
                clearScreen();
                break;
                
            //Compare two prizes from box2, if there are any prizes in box2
            case 'M':
                if (box2.getPrizeCount() > 0) {
                    int choice1 = 0, choice2 = 0;
                    clearScreen();
                    cout << "Select a Prize to Compare (from Custom Box)\n"
                         << "(1 for first prize, 2 for second prize, etc)" << endl;
                    choice1 = reader.readInt(1, box2.getPrizeCount());
                    cout << "Select another Prize to Compare (from Custom Box)\n"
                         << "(1 for first prize, 2 for second prize, etc)" << endl;
                    choice2 = reader.readInt(1, box2.getPrizeCount());
                    clearScreen();
                    if (box2.getPrize(choice1 - 1) == box2.getPrize(choice2 - 1)) {
                        cout << "These Prizes are the same!!!" << endl;
                        enterToContinue();
                        clearScreen();
                    } else {
                        cout << "These Prizes are not the same." << endl;
                        enterToContinue();
                        clearScreen();
                    }
                } else {
                    clearScreen();
                    cout << "There are not enough Prizes to Compare.\n"
                         << "Add more Prizes to the Custom Box to Compare." << endl;
                    enterToContinue();
                    clearScreen();
                }
                break;
                
            //Quit the interactive test
            case 'Q':
                clearScreen();
                cout << "Thank you for running this program!\n";
                menu_loop = false;
                break;
        }
    }
}
void prizeTest(){
    CinReader prizeReader;
    Prize testPrize;
    Prize comparePrize;
    
    unsigned int prizeMenuChoice = 0;
    char updateChoice;
    
    string newPrizeName;
    unsigned int newPrizeValue;
	
    // CODE HERE -- INTERACTIVE TEST FOR PRIZE
	do {
	    updateChoice = 'a';
		clearScreen();
		//menu here
		cout << "Prize info -> " << testPrize.getPrizeName() << ", $" << testPrize.getPrizeValue() << '\n';
        cout << "[1] Prize name\n";
	    cout << "[2] Prize value\n";
	    cout << "[3] Compare two prizes\n";
	    cout << "[0] Back to main menu\n";
	    cout << "Your choice: ";
		// read in menu choice here
        prizeMenuChoice = prizeReader.readInt(true,0,3);
		clearScreen();
		
		// menu switch goes here
		switch(prizeMenuChoice){
		    case 1:
		      cout << "Prize name: " << testPrize.getPrizeName() << "\n\n";
		      cout << "update? (y/n)\n";
		      
		      updateChoice = prizeReader.readChar("YyNn");
		      
		      switch(updateChoice){
		          case 'Y': case 'y':
		           cout << "Enter a new name for the prize: ";
		           
		           newPrizeName = prizeReader.readString();
		           testPrize.setPrizeName(newPrizeName);
		           
		           cout << endl << endl << "Prize name updated.\n\n";
		           break;
		          case 'N': case 'n':
		           break;
		      }
		     break;
		    case 2:
		      cout << "Prize value: " << testPrize.getPrizeValue() << "\n\n";
		      cout << "update? (y/n)\n";
		      
		      updateChoice = prizeReader.readChar("YyNn");
		      
		      switch(updateChoice){
		          case 'Y': case 'y':
		           cout << "Enter a new value for the prize: ";
		           
		           newPrizeValue = prizeReader.readInt(true, 0, INT_MAX);
		           testPrize.setPrizeValue(newPrizeValue);
		           
		           cout << endl << endl << "Prize value updated.\n\n";
		           break;
		          case 'N': case 'n':
		           break;
		      }
		     break;
		    case 3:
		      if((testPrize.getPrizeName() == "NO NAME") && (testPrize.getPrizeValue() == 0)){
		          cout << "Please enter an initial prize to compare to.\n\n";
		          cout << "Enter a new name for the prize: ";
		           
		          newPrizeName = prizeReader.readString();
		          testPrize.setPrizeName(newPrizeName);
		           
		          cout << "Enter a new value for the prize: ";
		           
		          newPrizeValue = prizeReader.readInt(true, 0, INT_MAX);
		          testPrize.setPrizeValue(newPrizeValue);
		      }
		      
		      cout << "Please enter details for a separate prize to compare to the stored prize.\n\n";
		      cout << "Enter a new name for the prize: ";
		           
		          newPrizeName = prizeReader.readString();
		          comparePrize.setPrizeName(newPrizeName);
		           
		          cout << "Enter a new value for the prize: ";
		           
		          newPrizeValue = prizeReader.readInt(true, 0, INT_MAX);
		          comparePrize.setPrizeValue(newPrizeValue);
		          
		          bool prizes_are_same = (testPrize == comparePrize);
		          
		      cout << endl << endl << "The two prizes are ";
		      if(prizes_are_same){
		          cout << "the same.\n\n";
		      }else{
		          cout << "not the same.\n\n";
		      }
		     break;
		}
		
		if (prizeMenuChoice > 0) {
			cout << endl << "Press ENTER to continue";
			prizeReader.readString();
		}
	} while (prizeMenuChoice != 0);
}
Beispiel #4
0
int main()
{
    int choice = 0;
    int dayChoice = 0;
    int viewChoice = 0;
    bool quit = false;

    day monday;
    monday.name = "Monday";
    day tuesday;
    tuesday.name = "Tuesday";
    day wednesday;
    wednesday.name = "Wednesday";
    day thursday;
    thursday.name = "Thursday";
    day friday;
    friday.name = "Friday";
    day saturday;
    saturday.name = "Saturday";
    day sunday;
    sunday.name = "Sunday";


    while (quit == false)
    {
        bool quitSetup = false;
        bool quitView = false;

        system ("cls");
        cout << "\t\t\t-Your Daily Planner-" << endl;
        cout << "You have the options:" << endl;
        cout << "[1] Setup Each Day." << endl;
        cout << "[2] View Each Day." << endl;
        cout << "[0] Quit Program." << endl;
        cout << "\nYour choice: ";
        choice = reader.readInt (0,2);

        switch (choice)
        {
        case 1:
            while (quitSetup == false)
            {
                cout << "\nWhat day would you like to setup?\n";
                cout << "[1] Monday\n";
                cout << "[2] Tuesday\n";
                cout << "[3] Wednesday\n";
                cout << "[4] Thursday\n";
                cout << "[5] Friday\n";
                cout << "[6] Saturday\n";
                cout << "[7] Sunday\n";
                cout << "[0] Exit Setup\n";
                cout << "\nYour Choice: ";
                dayChoice = reader.readInt (0,7);
                switch (dayChoice)
                {
                case 1:
                    setupDay(monday);
                    break;
                case 2:
                    setupDay(tuesday);
                    break;
                case 3:
                    setupDay(wednesday);
                    break;
                case 4:
                    setupDay(thursday);
                    break;
                case 5:
                    setupDay(friday);
                    break;
                case 6:
                    setupDay(saturday);
                    break;
                case 7:
                    setupDay(sunday);
                    break;
                case 0:
                    quitSetup = true;
                    break;
                }
            }

            cout << "Would you like to save your data to view later? (Y) or (N)\n";
            cout << "Any unsaved data will be lost\n";
            if (toupper(reader.readChar ("YyNn"))== 'Y')
                save(&monday, &tuesday, &wednesday, &thursday, &friday, &saturday, &sunday);

            break;

        case 2:

            retrieve(&monday, &tuesday, &wednesday, &thursday, &friday, &saturday, &sunday);
            while (quitView == false)
            {
                cout << "\nWhat day would you like to view?\n";
                cout << "[1] Monday\n";
                cout << "[2] Tuesday\n";
                cout << "[3] Wednesday\n";
                cout << "[4] Thursday\n";
                cout << "[5] Friday\n";
                cout << "[6] Saturday\n";
                cout << "[7] Sunday\n";
                cout << "[0] Exit Day Viewing\n";
                cout << "\nYour Choice: ";
                viewChoice = reader.readInt (0,7);

                switch (viewChoice)
                {
                case 1:
                    system("cls");
                    printDay(monday);
                    cout << "Hit enter to continue";
                    reader.readString();
                    break;
                case 2:
                    system("cls");
                    printDay(tuesday);
                    cout << "Hit enter to continue";
                    reader.readString();
                    break;
                case 3:
                    system("cls");
                    printDay(wednesday);
                    cout << "Hit enter to continue";
                    reader.readString();
                    break;
                case 4:
                    system("cls");
                    printDay(thursday);
                    cout << "Hit enter to continue";
                    reader.readString();
                    break;
                case 5:
                    system("cls");
                    printDay(friday);
                    cout << "Hit enter to continue";
                    reader.readString();
                    break;
                case 6:
                    system("cls");
                    printDay(saturday);
                    cout << "Hit enter to continue";
                    reader.readString();
                    break;
                case 7:
                    system("cls");
                    printDay(sunday);
                    cout << "Please Hit Enter to Continue:";
                    reader.readString();
                    break;
                case 0:
                    quitView = true;
                    break;
                }
            }
            break;

        case 0:
            quit = true;

            break;
        }
    }

    return 0;
}
void boxTest(){
    CinReader boxReader;
    Box testBox;
    Prize testPrize;
    Prize removedPrize;
    
    char updateChoice;
    unsigned int boxMenuChoice = 0;
    unsigned int removeChoice = 0;
    unsigned int newBoxNumber;
    unsigned int newPrizeValue;
    string newBoxColor;
    string newPrizeName;
    bool prizeAdded;
    bool prizeRemoved;
	
    // CODE HERE -- INTERACTIVE TEST FOR BOX
	do {
		clearScreen();
		//menu here
		cout << "Box info -> " << testBox.getBoxNumber() << ", " << testBox.getBoxColor() << endl;
        cout << "[1] Add prize\n";
	    cout << "[2] View prizes\n";
	    cout << "[3] Remove prize\n";
	    cout << "[4] Box number\n";
	    cout << "[5] Box color\n";
	    cout << "[6] View prize capacity\n";
	    cout << "[7] View prize count\n";
	    cout << "[0] Back to main menu\n";
	    cout << "Your choice: ";
		// read in menu choice here
        boxMenuChoice = boxReader.readInt(true,0,7);
		clearScreen();
		
		// menu switch goes here
		switch(boxMenuChoice){
		    case 1:
		          prizeAdded = false;
		          cout << "Enter a new name for the prize: ";
		          newPrizeName = boxReader.readString();
		           
		          cout << "Enter a new value for the prize: ";
		          newPrizeValue = boxReader.readInt(true, 0, INT_MAX);
		          
		          testPrize.setPrizeName(newPrizeName);
		          testPrize.setPrizeValue(newPrizeValue);
		          
		          prizeAdded = testBox.addPrize(testPrize);
		          
		          if(prizeAdded){
		              cout << endl << endl << "Prize added.\n\n";
		          }else{
		              cout << endl << endl << "Prize unable to be added.\n\n";
		          }
		     break;
		    case 2:
		          cout << "Prizes: \n\n";
		          for(int i=0; i<testBox.getPrizeCount(); i++){
		              Prize prize_at_index;
		              prize_at_index = testBox.getPrize(i);
		              cout << i+1 << ": " << prize_at_index.getPrizeName() << endl;
		          }
		     break;
		    case 3:
		          prizeRemoved = false;
		          cout << "Choose from the list of prizes to be removed (type 0 to exit):\n\n";
		          for(int i=0; i<testBox.getPrizeCount(); i++){
		              Prize prize_at_index;
		              prize_at_index = testBox.getPrize(i);
		              cout << i+1 << ": " << prize_at_index.getPrizeName() << endl;
		          }
		          
		          cout << "Choice here: ";
		          removeChoice = boxReader.readInt(true, 0, testBox.getPrizeCount());
		          if(removeChoice == 0){
		            break;
		          }
		          
		          removedPrize = testBox.removePrize(removeChoice-1);
		          
		          cout << "\n\nPrize " << removedPrize.getPrizeName() << " has been removed.\n\n";
		          
		     break;
		    case 4:
		          cout << "\nBox number is " << testBox.getBoxNumber() << "\n\n";
		          cout << "update? (y/n)\n";
		      
		          updateChoice = boxReader.readChar("YyNn");
		      
		          switch(updateChoice){
		          case 'Y': case 'y':
		             cout << "Enter a new value for the box number: ";
		           
		             newBoxNumber = boxReader.readInt(true, 0, INT_MAX);
		             testBox.setBoxNumber(newBoxNumber);
		           
		             cout << endl << endl << "Box number updated.\n\n";
		           break;
		          case 'N': case 'n':
		           break;
		          }
		     break;
		    case 5:
		          cout << "\nBox color is " << testBox.getBoxColor() << "\n\n";
		          cout << "update? (y/n)\n";
		      
		          updateChoice = boxReader.readChar("YyNn");
		      
		          switch(updateChoice){
		          case 'Y': case 'y':
		             cout << "Enter a new value for the box color: ";
		           
		             newBoxColor = boxReader.readString();
		             testBox.setBoxColor(newBoxColor);
		           
		             cout << endl << endl << "Box color updated.\n\n";
		           break;
		          case 'N': case 'n':
		          break;
		          }
		     break;
		    case 6:
		          cout << "\nMaximum prizes that can be put in the box: " << testBox.getPrizeCapacity() << "\n\n";
		     break;
		    case 7:
		          cout << "\nPrizes in the box: " << testBox.getPrizeCount() << "\n\n";
		     break;
		}
		
		if (boxMenuChoice > 0) {
			cout << endl << "Press ENTER to continue";
			boxReader.readString();
		}
	} while (boxMenuChoice != 0);
}