446,194 Members | 829 Online
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 #include  using namespace std;   class FastFood {       public:              void enterItemName(string, string, string);              void returnItemName(string&, string&, string&);              void enterCost(const float);              void returnCost( const float&);              void enterQuantity(int, int, int);              void returnQuantity(int&, int&, int&);         private:               string ItemName;               const float Cost;               int Quantity; };     int main() {     return 0; }   Oct 4 '06 #1
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 #include  using namespace std;   class FastFood {       public:              void enterItemName(string, string, string);              void returnItemName(string&, string&, string&);              void enterCost(const float);              void returnCost( const float&);              void enterQuantity(int, int, int);              void returnQuantity(int&, int&, int&);         private:               string ItemName;               const float Cost;               int Quantity; };     int main() {     return 0; }   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 int main() {   FastFood employee;  // create class object     // calling member functions example:   employee.enterItemName( "text" , "text" , "text");   employee.enterCost(10.50);   employee.enterQuantity(2,4,6); return 0; } 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 int main() {   FastFood employee;  // create class object     // calling member functions example:   employee.enterItemName( "text" , "text" , "text");   employee.enterCost(10.50);   employee.enterQuantity(2,4,6); return 0; } 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 int main() {   FastFood Burgers;   Burgers.enterItemName(Burgers); cout<<"Which item(s) would you like to purchase?";     return 0; }   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