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:
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
10 5699
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.
I understand what you said about passing nothing to my size function.....I can just pass a default value of 10"......however, 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.
- //******************************************************************************
-
// 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:
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.
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:
Sorry for all of the questions. I do greatly appreciate your help.
The constructor you have actually isn't a default constructor...it accepts 2 arguments (2 ints). The default constructor will accept no arguments, and will have the header:
and definition - 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.
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.cpp 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::getPizzaSize': function call missing argument list; use '&Pizza::getPizzaSize' to create a pointer to member
Error 2 error C3867: 'Pizza::getPizzaTop': function call missing argument list; use '&Pizza::getPizzaTop' 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:
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!
I've tried to use a pointer like it suggests. Here's is what I did to my Pizza_Program.cpp file:
I'm still getting same error about creating a pointer to a member.
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.getPizzaTop 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!
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(int, int) Here's what I have:
I really appreciate the help!
OK, I tried compiling this, and I got the following errors: - 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. - 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. - 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?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Haoyu Zhang |
last post by:
Dear Friends,
Python assignment is a reference assignment. However, I really can't
explain the difference in the following example. When the object is
a list, the assignment seems to be a...
|
by: Klaus Neuner |
last post by:
Hello,
I would like to understand the reason for the following difference
between dealing with lists and dealing with strings: What is this
difference good for? How it is accounted for in Python...
|
by: Edward Diener |
last post by:
Is there a way to override the default processing of the assignment operator
for one's own __value types ? I realize I can program my own Assign method,
and provide that for end-users of my class,...
|
by: Tony Johansson |
last post by:
Hello Experts!
Assume I have a class called SphereClass as the base class and a class
called BallClass that is derived from the SphereClass. The copy constructor
initialize the left hand object...
|
by: ma740988 |
last post by:
Consider:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
using namespace std;
class msg {
std::string someStr;
|
by: gyarnell |
last post by:
Just ran into a problem upgrading from GCC 2.96 to GCC 3.3.2. There is a bug somewhere, could be in 2.96, could be in 3.3.2, could be in the code I'm compiling. Here's a minimal example
class A
{...
|
by: raylopez99 |
last post by:
I need an example of a managed overloaded assignment operator for a
reference class, so I can equate two classes A1 and A2, say called
ARefClass, in this manner: A1=A2;. For some strange reason...
|
by: Bartholomew Simpson |
last post by:
I know this is a VB.Net ng. But hopefully, someone remembers some
classic (VB6) coding - besides I've not had any response when I posted
this to the VB6 specific ng.
I wrote a C++ librray that I...
|
by: Rambaldi |
last post by:
Since i am not use to program in c++, i got this question:
I've been thinking in making a mp3 player in C#, the language i am more confortable dealing with, but instead of using librarys provided...
|
by: khalfan |
last post by:
Assignment Objectives:
The objective of this assignment is to implement java programs with major object oriented concepts and applet with event handling.
Assignment Purposes
This assignment aims...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |