Thread: Class prob

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    Arrow Class prob

    Hi all, NEED HELP PLEASE!!!(i'm not good doing C++)I 'm having hard time doing this Class problem. My task is to implement the class Table. Have to add it to the file that contains the main program.

    I have to decide what private data members of the class needs and then the following methods have to be implemented:
    default constructor
    void addItem(string itemName, double price): adds an item to the tables bill.
    void printBill()rints the tables bill onto the screen.


    #include <string>
    #include <iostream>

    // put the Table class here

    /* -------------------------------------------------
    // don't change anything below this line - but make sure
    // you understand what the program is doing
    // this structure and the constant array below define the list
    // of items that are served in our restaurant.
    //
    struct MenuItem
    {
    char name[30];
    double price;
    };
    const MenuItem itemList[] = {
    { "Pizza", 5.90 },
    { "Salad", 3.99 },
    { "Lasagne", 7.99},
    { "Pepsi", 1.00},
    { "Sprite", 1.00},
    { "", 0.0 } // the last item terminates the list
    };
    //
    // prototypes
    //
    int main();

    void addItemFromList(Table&);



    //
    // implementation
    //
    int main()
    {
    Table t;
    int choice; // holds the choice entered by the user
    do
    {
    cout << "----------------------------------" << endl;
    cout << "Main Menu" << endl << endl;
    cout << "1 - Add Menu Item" << endl;
    cout << "2 - Print Bill" << endl;
    cout << "3 - Quit" << endl << endl;
    cout << "Enter choice:";
    cin >> choice;
    cout << "----------------------------------" << endl;
    switch(choice)
    {
    case 1 : addItemFromList(t); // let the user choose the item to be added
    break;
    case 2 : t.printBill(); // print the bill for the user
    break;
    }
    }
    while (choice != 3);
    return(0);
    }

    void addItemFromList(Table& t)

    {

    int choice;

    int max;
    // count available items in itemList
    for(max = 0; (itemList[max].price != 0.0); max++);
    do
    {
    cout << "----------------------------------" << endl;
    for(int i = 1; i <= max; i++)
    cout << i << " - " << itemList[i-1].name << endl;
    cout << max+1 << " - Go to main menu" << endl << endl;
    cout << "Enter choice: ";
    cin >> choice;
    cout << "----------------------------------" << endl;
    if ((choice >= 1) && (choice <= max))
    t.addItem(itemList[choice-1].name, itemList[choice-1].price);
    }
    while (choice != (max + 1)); // do while the user does not choose quit
    }

  2. #2
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Code:
    USE CODE TAGS

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Do you have a specific question about classes? Do you need a simple example of the syntax? I doubt anyone here will write the whole class as well as implementation for you, but we are all more than willing to answer questions you have about it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    99

    hmm

    Why are you supplying main with a prototype?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  4. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM