Not Understanding OOP!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FARiNk
    New Member
    • Oct 2006
    • 3

    Not Understanding OOP!

    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.
    Code:
    #include <iostream>
    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;
    }
  • dush
    New Member
    • Sep 2006
    • 27

    #2
    Originally posted by FARiNk
    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.
    Code:
    #include <iostream>
    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:

    Code:
    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;
    }

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Remenber that the main method is always called first. It is the entry point to your program.

      Comment

      • FARiNk
        New Member
        • Oct 2006
        • 3

        #4
        Originally posted by dush
        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:

        Code:
        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.

        Code:
        int main()
        {
        
        FastFood Burgers;
        
        Burgers.enterItemName(Burgers);
        cout<<"Which item(s) would you like to purchase?";
        
        
        return 0;
        }

        Comment

        • gasfusion
          New Member
          • Sep 2006
          • 59

          #5
          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.enterIt emName(myBurger );

          Comment

          • FARiNk
            New Member
            • Oct 2006
            • 3

            #6
            Originally posted by gasfusion
            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.enterIt emName(myBurger );

            Yeah, I realize that. Thank you all for the help; I fixed it.

            Comment

            Working...