C++ assignment dealing with classes and functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonic
    New Member
    • Nov 2006
    • 40

    C++ assignment dealing with classes and functions

    I'm not sure if I'm heading in the right direction with this school project. I am suppose to create a 3 file, class based program that will allow you to run a very simple pizza parlor program. The menu should be displayed similar to what is shown below.

    MENU
    --------------------------------------------------------------------------------------------
    A) What size of pizza do you want?
    B) What type of toppings do you want?
    C) Display/Place current order.
    D) Cancel current order.
    E) Quit program.

    I've only attempted to complete the first 2 menu items. Can anyone tell me if I'm heading in the right direction. I have 3 days before I need to finish this so any suggestions would be greatly appreciated. Here's the code I have so far:

    Code:
    // "Pizza.h"
    // Specification file for Pizza class
    
    #ifndef PIZZA_H
    #define PIZZA_H
    
    class Pizza
    {
    	private:
    		int pizzaSize;
    		int pizzaTop;
    
    	public:
    		void setPizzaSize(int);
    		void setPizzaTop(int);
    		int getPizzaSize() const;
    		int getPizzaTop() const;
    };
    
    #endif
    
    
    
    
    // "Pizza.cpp"
    // Implementation file for Pizza class
    
    #include "Pizza.h"
    #include <iostream>
    
    using namespace std;
    
    // setPizzaSize sets default value of ordered pizza
    void Pizza::setPizzaSize(int p)
    {pizzaSize = p;}
    
    // setPizzaTop sets topping default value of ordered pizza
    void Pizza::setPizzaTop(int t)
    {pizzaTop = t;}
    
    // getPizzaSize returns value in the member variable pizzaSize
    int Pizza::getPizzaSize() const
    {return pizzaSize;}
    
    // getPizzaTop returns value in the member variable pizzaTop
    int Pizza::pizzaTop() const
    {return pizzaTop;}
    
    
    
    // "Pizza_Program.cpp"
    // Program simulates a simple pizza parlor menu ordering system
    
    #include "Pizza.h"
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    // Function prototypes
    void displayMenu();
    void size(Pizza &);
    void topping(Pizza &);
    
    int main()
    {	
    	Pizza dinner;  // Instance of pizza class object
    	char choice; // menu selection
    
    	cout << fixed << showpoint << setprecision(2);
    
    	do
    	{
    		// Display menu and get valid selection
    		diplayMenu();
    		cin >> choice;
    
    		while (toupper(choice) < 'A' || toupper(choice) > 'B')
    		{
    			cout << "Please make a choice from the menu below (A-B): ";
    			cin >> choice;
    		}
    
    		// Process user choice
    		switch(choice)
    		{
    		case 'a':
    		case 'A': cout << "Enter size of pizza (10,16,20,24 inches): ";
    				  size();
    				  break;
    
    		case 'b':
    		case 'B': cout << "Please enter toppings on pizza: ";
    				  topping();
    				  break;
    		}
    	}
    	while (toupper(choice) != 'C');
    
    	return 0;
    }
    
    //********************************************************
    // This function displays the user's menu on the screen. *
    //********************************************************
    
    void displayMenu()
    {
    	cout << "\n					MENU\n";
    	cout << "--------------------------------------------------\n";
    	cout << "A)  What size of pizza do you want?\n";
    	cout << "B)  What type of toppings do you wants?\n";
    	cout << "C)  Quit Program\n\n";
    	cout << "Enter your choice: ";
    }
    
    //********************************************************************************
    // This function accepts a reference to a Pizza object.  The user is asked for   *
    // size of pizza and the setPizzaSize member of Pizza object is called.          *
    //********************************************************************************
    
    void size(Pizza &dinner)
    {
    	int size;
    
    	cout << "
    Thank you for any help that can be offered. Would like to know if I'm heading in the right direction. I'm not posting my code in hopes of someone completing it, but rather to see if I'm heading at this the correct way. Thank you for you time in advance.

    -Roger
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Everything looks good so far. One thing I noticed is, when you call the size() function from your main (inside the switch statement), you pass it no arguments. But, in the start of your definition, you have a single argument - a reference pizza object. This is also mentioned in your documentation. Perhaps you should make a pizza, and then call size using that pizza. You can also call toppings, etc. until the customer is done with the pizza, then add it to their order.

    Comment

    • sonic
      New Member
      • Nov 2006
      • 40

      #3
      I understand what you said about passing nothing to my size function.....I can just pass a default value of 10"......howeve r, not sure what you mean about making a pizza first and then calling size and toppings. Do you mean I should first make a pizza feeding in all the default arguments (first choices of size and topping menu)? Thank you for your earlier reply. Will continue working on project tomorrow.

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Code:
        //******************************************************************************
        // This function accepts a reference to a Pizza object.  The user is asked for   *
        // size of pizza and the setPizzaSize member of Pizza object is called.          *
        //******************************************************************************
        
        void size(Pizza &dinner)
        You wrote down that this function should be receiving a reference to a Pizza object. But, in your main, you write size() with no arguments, so this won't compile.

        What I'm thinking of is this: The user has told you they want to order a pizza. So, in order to have an object to work with, you create a Pizza object with no constructor arguments:

        Code:
        Pizza myPizza;
        You should have a default constructor prepared to assign default values to toppings and size.

        Now that you have a pizza, you can get the vital information from the user: what size do they want? What toppings? Etc. etc. You will pass myPizza to each function so that it can edit the pizza, changing the necessary information using the Pizza functions.

        Comment

        • sonic
          New Member
          • Nov 2006
          • 40

          #5
          I think I've made the changes you suggested. I created a default constructor and have passed an instance of Pizza to both the size and topping function in main(). I'm still having problems with it compiling. Also, I'm not sure what to call in selection 'D' from the menu. Should I call the default constructor to clear previous customer selections? Here is my code:

          Code:
          // "Pizza.h"
          // Specification file for Pizza class
          
          #ifndef PIZZA_H
          #define PIZZA_H
          
          class Pizza
          {
          	private:
          		int pizzaSize;
          		int pizzaTop;
          
          	public:
          		Pizza(int, int);         // Constructor
          		void setPizzaSize(int);
          		void setPizzaTop(int);
          		int getPizzaSize() const;
          		int getPizzaTop() const;
          };
          
          #endif
          
          
          
          // "Pizza.cpp"
          // Implementation file for Pizza class
          
          #include "Pizza.h"
          #include <iostream>
          
          using namespace std;
          
          // Construtor accepts arguments for pizzaSize and pizzaTop
          Pizza::Pizza(int s, int t)
          {
          	pizzaSize = s;
          	pizzaTop = t;
          }
          
          // setPizzaSize sets default value of ordered pizza
          void Pizza::setPizzaSize(int p)
          {pizzaSize = p;}
          
          // setPizzaTop sets topping default value of ordered pizza
          void Pizza::setPizzaTop(int t)
          {pizzaTop = t;}
          
          // getPizzaSize returns value in the member variable pizzaSize
          int Pizza::getPizzaSize() const
          {return pizzaSize;}
          
          // getPizzaTop returns value in the member variable pizzaTop
          int Pizza::pizzaTop() const
          {return pizzaTop;}
          
          
          // "Pizza_Program.cpp"
          // Program simulates a simple pizza parlor menu ordering system
          
          #include "Pizza.h"
          #include <iostream>
          #include <iomanip>
          
          using namespace std;
          
          // Function prototypes
          void displayMenu();
          void size(Pizza &);
          void topping(Pizza &);
          
          int main()
          {	
          	Pizza dinner;  // Instance of pizza class object
          	char choice; // menu selection
          
          	cout << fixed << showpoint << setprecision(2);
          
          	do
          	{
          		// Display menu and get valid selection
          		diplayMenu();
          		cin >> choice;
          
          		while (toupper(choice) < 'A' || toupper(choice) > 'E')
          		{
          			cout << "Please make a choice from the menu below (A-E): ";
          			cin >> choice;
          		}
          
          		// Process user choice
          		switch(choice)
          		{
          		case 'a':
          		case 'A': cout << "Enter size of pizza (10,16,20,24 inches): ";
          				  size(dinner);
          				  break;
          
          		case 'b':
          		case 'B': cout << "Please enter toppings on pizza: ";
          				  topping(dinner);
          				  break;
          
          		case 'c':
          		case 'C': cout << "You chose a " << dinner.getPizzaSize << "inch pizza with" << dinner.getPizzaTop << "\n";
          				  break;
          
          // Not sure what to do here.  Should I call default construtor to wipe it clean??
          
          		case 'd':
          		case 'D': 
          		}
          	}
          	while (toupper(choice) != 'E');
          
          	return 0;
          }
          
          //********************************************************
          // This function displays the user's menu on the screen. *
          //********************************************************
          
          void displayMenu()
          {
          	cout << "\n				MENU\n";
          	cout << "--------------------------------------------------\n";
          	cout << "A)  What size of pizza do you want?\n";
          	cout << "B)  What type of toppings do you wants?\n";
          	cout << "C)  Display/Place current order.\n";
          	cout << "D)  Cancel current order.\n";
          	cout << "E)  Quit Program\n\n";
          	cout << "Enter your choice: ";
          }
          
          //********************************************************************************
          // This function accepts a reference to a Pizza object.  The user is asked for   *
          // size of pizza and the setPizzaSize member of Pizza object is called.          *
          //********************************************************************************
          
          void size(Pizza &dinner)
          {
          	int size;
          
          	cout << "Enter either (10,16,20,24) for the size pizza you would like: ";
          	cin >> size;
          	dinner.setPizzaSize(size);
          
          }
          
          //*******************************************************************************
          // This function accepts a reference to a Pizza object.  The user is asked for  *
          // choice of topping and the setPizzaTop member of Pizza object is called.      *
          //*******************************************************************************
          
          void topping(Pizza &dinner)
          {
          	int topping;
          
          	cout << "\t\t Toppings Choices\n";
          	cout << "\t---------------------------------\n";
          	cout << "\t 1) pepperoni\n";
          	cout << "\t 2) sausage\n";
          	cout << "\t 3) vegetarian\n";
          	cout << "\t 4) deluxe\n";
          	cout << "\t 5) plain cheese\n";
          	cin >> topping;
          	dinner.setPizzaTop(topping);
          
          }
          Sorry for all of the questions. I do greatly appreciate your help.
          Last edited by sonic; Apr 23 '07, 03:38 PM. Reason: forgot to close code tag

          Comment

          • Ganon11
            Recognized Expert Specialist
            • Oct 2006
            • 3651

            #6
            The constructor you have actually isn't a default constructor...i t accepts 2 arguments (2 ints). The default constructor will accept no arguments, and will have the header:

            Code:
            Pizza();
            and definition

            Code:
            Pizza::Pizza() {
               // ...
            }
            However, this isn't a huge problem. Once you add this, you should be fine in that department. (Inside the constructor's body, set the size and toppings so some default value, like 10 inches with 0 toppings).

            Unfortunately, no, you can't call the constructor after an object has been made. The constructor is like a set of instructions, listing what steps should be taken to properly build a Pizza. Once the Pizza is built, it doesn't make sense to call the constructor again - it can't be built again!

            You should instead add a new function, reset(). reset() can do just what it says - reset size and toppings to the default values.

            Comment

            • sonic
              New Member
              • Nov 2006
              • 40

              #7
              Thank you again for the continued input. I still have having trouble getting it to compile. I have five errors which is down from the original 11 that I had....yay!. They are all in my pizza_program.c pp file. They say I have to create a pointer to a member. I'm not sure why I need a pointer. Here are the error messages:

              Error 1 error C3867: 'Pizza::getPizz aSize': function call missing argument list; use '&Pizza::getPiz zaSize' to create a pointer to member

              Error 2 error C3867: 'Pizza::getPizz aTop': function call missing argument list; use '&Pizza::getPiz zaTop' to create a pointer to member

              Error 3 error C2065: 'dinner' : undeclared identifier

              Error 4 error C2228: left of '.setPizzaSize' must have class/struct/union

              Error 5 error C2228: left of '.setPizzaTop' must have class/struct/union


              Here is my code:

              Code:
              // "Pizza_Program.cpp"
              // Program simulates a simple pizza parlor menu ordering system
              
              #include "Pizza.h"
              #include <iostream>
              #include <iomanip>
              
              using namespace std;
              
              // Function prototypes
              void displayMenu();
              void size(Pizza &);
              void topping(Pizza &);
              void reset();
              
              int main()
              {	
              	Pizza dinner;  // Instance of pizza class object
              	char choice; // menu selection
              
              	cout << fixed << showpoint << setprecision(2);
              
              	do
              	{
              		// Display menu and get valid selection
              		displayMenu();
              		cin >> choice;
              
              		while (toupper(choice) < 'A' || toupper(choice) > 'E')
              		{
              			cout << "Please make a choice from the menu below (A-E): ";
              			cin >> choice;
              		}
              
              		// Process user choice
              		switch(choice)
              		{
              		case 'a':
              		case 'A': cout << "Enter size of pizza (10,16,20,24 inches): ";
              				  size(dinner);
              				  break;
              
              		case 'b':
              		case 'B': cout << "Please enter toppings on pizza: ";
              				  topping(dinner);
              				  break;
              
              		case 'c':
              		case 'C': cout << "You chose a " << dinner.getPizzaSize << "inch pizza with" << dinner.getPizzaTop << "\n";
              				  break;
              
              		case 'd':
              		case 'D': reset();
              		}
              	}
              	while (toupper(choice) != 'E');
              
              	return 0;
              }
              
              //********************************************************
              // This function displays the user's menu on the screen. *
              //********************************************************
              
              void displayMenu()
              {
              	cout << "\n				MENU\n";
              	cout << "--------------------------------------------------\n";
              	cout << "A)  What size of pizza do you want?\n";
              	cout << "B)  What type of toppings do you wants?\n";
              	cout << "C)  Display/Place current order.\n";
              	cout << "D)  Cancel current order.\n";
              	cout << "E)  Quit Program\n\n";
              	cout << "Enter your choice: ";
              }
              
              //********************************************************************************
              // This function accepts a reference to a Pizza object.  The user is asked for   *
              // size of pizza and the setPizzaSize member of Pizza object is called.          *
              //********************************************************************************
              
              void size(Pizza &dinner)
              {
              	int size;
              
              	cout << "Enter either (10,16,20,24) for the size pizza you would like: ";
              	cin >> size;
              	dinner.setPizzaSize(size);
              
              }
              
              //*******************************************************************************
              // This function accepts a reference to a Pizza object.  The user is asked for  *
              // choice of topping and the setPizzaTop member of Pizza object is called.      *
              //*******************************************************************************
              
              void topping(Pizza &dinner)
              {
              	int topping;
              
              	cout << "\t\t Toppings Choices\n";
              	cout << "\t---------------------------------\n";
              	cout << "\t 1) pepperoni\n";
              	cout << "\t 2) sausage\n";
              	cout << "\t 3) vegetarian\n";
              	cout << "\t 4) deluxe\n";
              	cout << "\t 5) plain cheese\n";
              	cin >> topping;
              	dinner.setPizzaTop(topping);
              
              }
              
              //*********************************************************************
              // This function cancels the currect order.  It resets the pizzaSize  *
              // and pizzaTop private member variables.                             *
              //*********************************************************************
              
              void reset()
              {
              	int size = 10;
              	int topping = 1;
              
              	dinner.setPizzaSize(size);
              	dinner.setPizzaTop(topping);
              
              }
              
              
              
              // "Pizza.cpp"
              // Implementation file for Pizza class
              
              #include "Pizza.h"
              #include <iostream>
              
              using namespace std;
              
              // Construtor 
              Pizza::Pizza()
              {
              	pizzaSize = 10;
              	pizzaTop = 1;
              }
              
              // setPizzaSize sets default value of ordered pizza
              void Pizza::setPizzaSize(int p)
              {pizzaSize = p;}
              
              // setPizzaTop sets topping default value of ordered pizza
              void Pizza::setPizzaTop(int t)
              {pizzaTop = t;}
              
              // getPizzaSize returns value in the member variable pizzaSize
              int Pizza::getPizzaSize() const
              {return pizzaSize;}
              
              // getPizzaTop returns value in the member variable pizzaTop
              int Pizza::getPizzaTop() const
              {return pizzaTop;}
              
              
              // "Pizza.h"
              // Specification file for Pizza class
              
              #ifndef PIZZA_H
              #define PIZZA_H
              
              class Pizza
              {
              	private:
              		int pizzaSize;
              		int pizzaTop;
              
              	public:
              		Pizza();         // Constructor
              		void setPizzaSize(int);
              		void setPizzaTop(int);
              		int getPizzaSize() const;
              		int getPizzaTop() const;
              };
              
              #endif
              I'm going to continue trying. I'm not sure why I can't use dinner as an identifier in my reset() function. Do I need to use a destructor to eliminate the old Pizza dinner object and then use a constructor to rebuild it so I can reset it to default values? Thank you so much for your help!

              Comment

              • sonic
                New Member
                • Nov 2006
                • 40

                #8
                I've tried to use a pointer like it suggests. Here's is what I did to my Pizza_Program.c pp file:

                Code:
                // "Pizza_Program.cpp"
                // Program simulates a simple pizza parlor menu ordering system
                
                #include "Pizza.h"
                #include <iostream>
                #include <iomanip>
                
                using namespace std;
                
                // Function prototypes
                void displayMenu();
                void size(Pizza &);
                void topping(Pizza &);
                void reset();
                
                int main()
                {	
                	Pizza dinner;  // Instance of pizza class object
                	char choice; // menu selection
                	Pizza* pizzaPtr;
                	pizzaPtr = &dinner;
                
                	cout << fixed << showpoint << setprecision(2);
                
                	do
                	{
                		// Display menu and get valid selection
                		displayMenu();
                		cin >> choice;
                
                		while (toupper(choice) < 'A' || toupper(choice) > 'E')
                		{
                			cout << "Please make a choice from the menu below (A-E): ";
                			cin >> choice;
                		}
                
                		// Process user choice
                		switch(choice)
                		{
                		case 'a':
                		case 'A': cout << "Enter size of pizza (10,16,20,24 inches): ";
                				  size(dinner);
                				  break;
                
                		case 'b':
                		case 'B': cout << "Please enter toppings on pizza: ";
                				  topping(dinner);
                				  break;
                
                		case 'c':
                		case 'C': cout << "You chose a " << pizzaPtr->getPizzaSize << " inch pizza with" << pizzaPtr->getPizzaTop << "\n";
                				  break;
                
                		case 'd':
                		case 'D': reset();
                		}
                	}
                	while (toupper(choice) != 'E');
                
                	return 0;
                }
                
                //********************************************************
                // This function displays the user's menu on the screen. *
                //********************************************************
                
                void displayMenu()
                {
                	cout << "\n				MENU\n";
                	cout << "--------------------------------------------------\n";
                	cout << "A)  What size of pizza do you want?\n";
                	cout << "B)  What type of toppings do you wants?\n";
                	cout << "C)  Display/Place current order.\n";
                	cout << "D)  Cancel current order.\n";
                	cout << "E)  Quit Program\n\n";
                	cout << "Enter your choice: ";
                }
                
                //********************************************************************************
                // This function accepts a reference to a Pizza object.  The user is asked for   *
                // size of pizza and the setPizzaSize member of Pizza object is called.          *
                //********************************************************************************
                
                void size(Pizza &dinner)
                {
                	int size;
                
                	cout << "Enter either (10,16,20,24) for the size pizza you would like: ";
                	cin >> size;
                	dinner.setPizzaSize(size);
                
                }
                
                //*******************************************************************************
                // This function accepts a reference to a Pizza object.  The user is asked for  *
                // choice of topping and the setPizzaTop member of Pizza object is called.      *
                //*******************************************************************************
                
                void topping(Pizza &dinner)
                {
                	int topping;
                
                	cout << "\t\t Toppings Choices\n";
                	cout << "\t---------------------------------\n";
                	cout << "\t 1) pepperoni\n";
                	cout << "\t 2) sausage\n";
                	cout << "\t 3) vegetarian\n";
                	cout << "\t 4) deluxe\n";
                	cout << "\t 5) plain cheese\n";
                	cin >> topping;
                	dinner.setPizzaTop(topping);
                
                }
                
                //*********************************************************************
                // This function cancels the currect order.  It resets the pizzaSize  *
                // and pizzaTop private member variables.                             *
                //*********************************************************************
                
                void reset()
                {
                	int size = 10;
                	int topping = 1;
                
                	dinner.setPizzaSize(size);
                	dinner.setPizzaTop(topping);
                
                }
                I'm still getting same error about creating a pointer to a member.

                Comment

                • Ganon11
                  Recognized Expert Specialist
                  • Oct 2006
                  • 3651

                  #9
                  OK, stick with the non-pointer version. Using pointers now will likely get you confused later. You are getting the pointer-errors because, in your display, you say dinner.getPizza Top without parentheses. Adding parentheses to this function call (and getPizzaSize) should eliminate the error.

                  Next, dinner is undeclared because it is a local object, declared inside the main() fnction. That means it is only visible to the main() and not in reset. The reset() function should be a part of the Pizza class, so you will call dinner.reset() to reset the Pizza. Try these changes and see if it works.

                  It's looking closer and closer every time!

                  Comment

                  • sonic
                    New Member
                    • Nov 2006
                    • 40

                    #10
                    Almost there I think. What am I doing wrong in my class declaration file? I think reset() would have to be able receive two integers to reset private member variables pizzaSize and pizzaTop. However, I seem to be running into problems when I try to return Pizza (my constructor) to void Pizza:reset(). Do I need to change void Pizza::reset() to enable it to accept two integers? Ex: Pizza::reset(in t, int) Here's what I have:

                    Code:
                    // "Pizza.h"
                    // Specification file for Pizza class
                    
                    #ifndef PIZZA_H
                    #define PIZZA_H
                    
                    class Pizza
                    {
                    	private:
                    		int pizzaSize;
                    		int pizzaTop;
                    
                    	public:
                    		Pizza();         // Constructor
                    		void setPizzaSize(int);
                    		void setPizzaTop(int);
                    		int getPizzaSize() const;
                    		int getPizzaTop() const;
                    		void reset(int, int);
                    
                    };
                    
                    #endif
                    
                    
                    
                    // "Pizza.cpp"
                    // Implementation file for Pizza class
                    
                    #include "Pizza.h"
                    #include <iostream>
                    
                    using namespace std;
                    
                    // Construtor 
                    Pizza::Pizza()
                    {
                    	pizzaSize = 10;
                    	pizzaTop = 1;
                    }
                    
                    // setPizzaSize sets default value of ordered pizza
                    void Pizza::setPizzaSize(int p)
                    {pizzaSize = p;}
                    
                    // setPizzaTop sets topping default value of ordered pizza
                    void Pizza::setPizzaTop(int t)
                    {pizzaTop = t;}
                    
                    // getPizzaSize returns value in the member variable pizzaSize
                    int Pizza::getPizzaSize() const
                    {return pizzaSize;}
                    
                    // getPizzaTop returns value in the member variable pizzaTop
                    int Pizza::getPizzaTop() const
                    {return pizzaTop;}
                    
                    // reset sets default values of pizzaSize and pizzaTop member variables
                    void Pizza::reset()
                    {return Pizza;}
                    
                    
                    
                    // "Pizza_Program.cpp"
                    // Program simulates a simple pizza parlor menu ordering system
                    
                    #include "Pizza.h"
                    #include <iostream>
                    #include <iomanip>
                    
                    using namespace std;
                    
                    // Function prototypes
                    void displayMenu();
                    void size(Pizza &);
                    void topping(Pizza &);
                    void reset();
                    
                    int main()
                    {	
                    	Pizza dinner;  // Instance of pizza class object
                    	char choice; // menu selection
                    	char subChoice; // sub-menu selection in select case 'C'
                    
                    	cout << fixed << showpoint << setprecision(2);
                    
                    	do
                    	{
                    		// Display menu and get valid selection
                    		displayMenu();
                    		cin >> choice;
                    
                    		while (toupper(choice) < 'A' || toupper(choice) > 'E')
                    		{
                    			cout << "Please make a choice from the menu below (A-E): ";
                    			cin >> choice;
                    		}
                    
                    		// Process user choice
                    		switch(choice)
                    		{
                    		case 'a':
                    		case 'A': size(dinner);
                    				  break;
                    
                    		case 'b':
                    		case 'B': topping(dinner);
                    				  break;
                    
                    		case 'c':
                    		case 'C': cout << "You chose a " << dinner.getPizzaSize() << " inch pizza with" << dinner.getPizzaTop() << "\n\n";
                    				  cout << "Choose either (R) to restart or (E) to exit.";
                    			      cin >> subChoice;
                    				  if (toupper(subChoice) != 'R' || toupper(subChoice) != 'E')
                    				  {cout << "Please enter R or D: ";
                    				   cin >> subChoice;
                    				  }
                    				  else
                    				  break;
                    
                    		case 'd':
                    		case 'D': reset();
                    				  size(dinner);
                    				  break;
                    		}
                    	}
                    	while (toupper(choice) != 'E');
                    
                    	return 0;
                    }
                    
                    //********************************************************
                    // This function displays the user's menu on the screen. *
                    //********************************************************
                    
                    void displayMenu()
                    {
                    	cout << "\n				MENU\n";
                    	cout << "--------------------------------------------------\n";
                    	cout << "A)  What size of pizza do you want?\n";
                    	cout << "B)  What type of toppings do you wants?\n";
                    	cout << "C)  Display/Place current order.\n";
                    	cout << "D)  Cancel current order.\n";
                    	cout << "E)  Quit Program\n\n";
                    	cout << "Enter your choice: ";
                    }
                    
                    //********************************************************************************
                    // This function accepts a reference to a Pizza object.  The user is asked for   *
                    // size of pizza and the setPizzaSize member of Pizza object is called.          *
                    //********************************************************************************
                    
                    void size(Pizza &dinner)
                    {
                    	int size;
                    
                    	cout << "Enter either (10,16,20,24) for the size pizza you would like: ";
                    	cin >> size;
                    	if (size != 10 && size != 16 && size != 20 && size != 24)
                    		{cout << "Please enter 10,16,20,24 for size of pizza!";
                    		cin >> size;
                    		}
                    	else
                    	dinner.setPizzaSize(size);
                    
                    }
                    
                    //*******************************************************************************
                    // This function accepts a reference to a Pizza object.  The user is asked for  *
                    // choice of topping and the setPizzaTop member of Pizza object is called.      *
                    //*******************************************************************************
                    
                    void topping(Pizza &dinner)
                    {
                    	int topping;
                    
                    	cout << "\t\t Toppings Choices\n";
                    	cout << "\t---------------------------------\n";
                    	cout << "\t 1) pepperoni\n";
                    	cout << "\t 2) sausage\n";
                    	cout << "\t 3) vegetarian\n";
                    	cout << "\t 4) deluxe\n";
                    	cout << "\t 5) plain cheese\n";
                    	cin >> topping;
                    	if (topping < 1 || topping > 5)
                    	{cout << "Please enter a valid topping (1-5): ";
                    	cin >> topping;
                    	}
                    
                    	dinner.setPizzaTop(topping);
                    
                    }
                    
                    //*********************************************************************
                    // This function cancels the currect order.  It resets the pizzaSize  *
                    // and pizzaTop private member variables.                             *
                    //*********************************************************************
                    
                    void reset()
                    {
                    	dinner.reset();
                    }
                    I really appreciate the help!

                    Comment

                    • Ganon11
                      Recognized Expert Specialist
                      • Oct 2006
                      • 3651

                      #11
                      OK, I tried compiling this, and I got the following errors:

                      Code:
                      60 C:\Documents and Settings\Stark\My Documents\Untitled1.cpp prototype for `void Pizza::reset()' does not match any in class `Pizza' 
                      19 C:\Documents and Settings\Stark\My Documents\Untitled1.cpp void Pizza::reset(int, int)
                      You declared the function as receiving two ints, then defined it as having no arguments. I don't think it should have any int arguments - if the Pizza is being reset, then what does it matter what size/toppings it has? The user should still have to input that information. Thus, the reset() function should set size and toppings to some arbitrary value - perhaps 0, since you know you can't have a pizza of diameter 0 inches. If you ever see an output of 0 inches, you know the pizza hasn't had its size set.

                      Code:
                      C:\Documents and Settings\Stark\My Documents\Untitled1.cpp In member function `void Pizza::reset()': 
                      60 C:\Documents and Settings\Stark\My Documents\Untitled1.cpp expected primary-expression before ';' token 
                      60 C:\Documents and Settings\Stark\My Documents\Untitled1.cpp return-statement with a value, in function returning 'void'
                      These two deal with the fact that you are trying to return a class name in reset() - this is not how it should be implemented.

                      Code:
                       C:\Documents and Settings\Stark\My Documents\Untitled1.cpp In function `void reset()': 
                      201 C:\Documents and Settings\Stark\My Documents\Untitled1.cpp `dinner' undeclared (first use this function)
                      Again, dinner is local to main() and not visible in any other function - instead of having a function reset() that calls dinner.reset(), why not just call dinner.reset() in the first place?

                      Comment

                      Working...