By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Not Understanding OOP!

P: 3
First off I have to write an OOP Burger Stand. The instructions were as followed:

1. Create a Class - FastFood

2. Properities of the class
Item Name, Cost, Quantity

3. Methods of the Class
Enter Name, Cost, Quantity
Return Name, Cost, Quantity

Have the Employee Enter an Item

My question is how do I call the function to have the employee enter in an item (for example: Burgers)? This is where I' am completely lost.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class FastFood
  5. {
  6.       public:
  7.              void enterItemName(string, string, string);
  8.              void returnItemName(string&, string&, string&);
  9.              void enterCost(const float);
  10.              void returnCost( const float&);
  11.              void enterQuantity(int, int, int);
  12.              void returnQuantity(int&, int&, int&);
  13.  
  14.       private:
  15.               string ItemName;
  16.               const float Cost;
  17.               int Quantity;
  18. };
  19.  
  20.  
  21. int main()
  22. {
  23.  
  24.  
  25. return 0;
  26. }
  27.  
Oct 4 '06 #1
Share this Question
Share on Google+
5 Replies


P: 27
First off I have to write an OOP Burger Stand. The instructions were as followed:

1. Create a Class - FastFood

2. Properities of the class
Item Name, Cost, Quantity

3. Methods of the Class
Enter Name, Cost, Quantity
Return Name, Cost, Quantity

Have the Employee Enter an Item

My question is how do I call the function to have the employee enter in an item (for example: Burgers)? This is where I' am completely lost.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class FastFood
  5. {
  6.       public:
  7.              void enterItemName(string, string, string);
  8.              void returnItemName(string&, string&, string&);
  9.              void enterCost(const float);
  10.              void returnCost( const float&);
  11.              void enterQuantity(int, int, int);
  12.              void returnQuantity(int&, int&, int&);
  13.  
  14.       private:
  15.               string ItemName;
  16.               const float Cost;
  17.               int Quantity;
  18. };
  19.  
  20.  
  21. int main()
  22. {
  23.  
  24.  
  25. return 0;
  26. }
  27.  
Hi

Before you start calling class member functions to enter name, cost, quantity you have to implement their definitions. What you have so far are function prototypes only.

When you are done call your functions trough objects in main program:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   FastFood employee;  // create class object
  4.  
  5.   // calling member functions example:
  6.   employee.enterItemName( "text" , "text" , "text");
  7.   employee.enterCost(10.50);
  8.   employee.enterQuantity(2,4,6);
  9. return 0;
  10. }
Oct 5 '06 #2

10K+
P: 13,264
Remenber that the main method is always called first. It is the entry point to your program.
Oct 5 '06 #3

P: 3
Hi

Before you start calling class member functions to enter name, cost, quantity you have to implement their definitions. What you have so far are function prototypes only.

When you are done call your functions trough objects in main program:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   FastFood employee;  // create class object
  4.  
  5.   // calling member functions example:
  6.   employee.enterItemName( "text" , "text" , "text");
  7.   employee.enterCost(10.50);
  8.   employee.enterQuantity(2,4,6);
  9. return 0;
  10. }
Hey, and thanks alot. I did this the first time with Burgers, and it keeps giving me an error saying Burgers is not declare. I know that I have to called first it's just I don't know the structure.

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.  
  4. FastFood Burgers;
  5.  
  6. Burgers.enterItemName(Burgers);
  7. cout<<"Which item(s) would you like to purchase?";
  8.  
  9.  
  10. return 0;
  11. }
  12.  
Oct 5 '06 #4

P: 59
notice how you're passing a variable to your member function. It cannot be Burgers since Burgers refers to your class. Also, why are you passing a variable before it is being declared?

string myBurger; // or whatever the data type your function accepts
cout<<"Which item(s) would you like to purchase?";
cin >> myBurger;
Burgers.enterItemName(myBurger);
Oct 5 '06 #5

P: 3
notice how you're passing a variable to your member function. It cannot be Burgers since Burgers refers to your class. Also, why are you passing a variable before it is being declared?

string myBurger; // or whatever the data type your function accepts
cout<<"Which item(s) would you like to purchase?";
cin >> myBurger;
Burgers.enterItemName(myBurger);

Yeah, I realize that. Thank you all for the help; I fixed it.
Oct 5 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.