Thread: Please HELP

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    Please HELP

    Hi ALL~

    PLEASE HELP~~ ~_~
    I can't change the coke stock, the stock is always zero.

    What should i do?
    Thanks



    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>

    using namespace std;

    class Container
    {
    int stock_brand;
    public:
    Container(int stock=0)
    {
    cout << endl << "Constuctor Called";
    stock_brand = stock;
    }
    int GetStock()
    { return stock_brand; }
    };

    class Menu
    {
    char option;
    public:
    // Container CokeStock(3);
    void display(void);
    void process(void);
    char getOption()
    { return option; }
    };

    void Menu::display()
    {
    cout << "\n\nSuper Cheap Super Drinks \n\n";
    cout << "Brands available: \n\n";
    cout << "1. <C>oke $1.30 \n";
    cout << "2. <S>prite $1.20 \n";
    cout << "3. <F>anta $1.10 \n";
    cout << "4. <R>otTooth $0.90 \n";
    cout << "5. SuperFi<Z> $1.00 \n\n";
    cout << "Please select a brand: ";
    cin >> option;
    }

    void Menu:rocess()
    {
    Container CokeStock;
    cout << CokeStock.GetStock();
    switch(option)
    {
    case '1': case 'C': case 'c':
    { if (CokeStock.GetStock() < 1 )
    {
    cout <<"\nSold Out!";
    break;
    }
    else {
    cout <<"\nCOKE DISPENSED. HAVE A NICE DAY!";
    CokeStock.GetStock() - 1;
    break;
    }
    }
    //
    case '2': case 'S': case 's': cout <<"\nSPRITE DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '3': case 'F': case 'f': cout <<"\nFANTA DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '4': case 'R': case 'r': cout <<"\nROTTOOTH DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '5': case 'Z': case 'z': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case 'Q': case 'q': cout << "\nSORRY, DRINKS ARE INAVAILABLE" << endl;
    cout << "CLOSING DOWN FOR MAINTENANCE\n" << endl;
    getch();
    break;
    //
    default : cout << "\nNOT A VALID SELECTION. PLEASE SELECT AGAIN ";
    }
    }

    class Manager
    {
    Menu menu;
    public:
    void iterateMenu();
    };

    void Manager::iterateMenu()
    {
    // Container CokeStock(3);
    do
    {
    menu.display();
    menu.process();
    } while((menu.getOption()!='Q')&&(menu.getOption()!= 'q'));
    };

    void main()
    {
    // Container CokeStock(3);
    // cout << CokeStock.GetStock();
    // Container FandaStock(2);
    // cout << FandaStock.GetStock()-1;
    Manager start;
    start.iterateMenu();
    cout << "Press any key to continue . . . " << endl;
    getch();
    };

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

  3. #3
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    I can't change the coke stock, the stock is always zero.
    That's because you initialize it to zero when the class is constructed, but since the member is private you can't ever change it except from inside the class.
    What should i do?
    Rethink the design of your Container class. A quick and dirty fix would be to create a SetStock member function, or better yet, a Dispense function that decrements the stock and a Fill function that increments it. That way you have something a bit more predictable than SetStock.
    p.s. What the alphabet would look like without q and r.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    6
    I have added a SetsStock here....
    But it has some error on it....

    119 c:\docume~1\rabbit\desktop\oop\oop_a1\a1main~2.cpp
    no matching function for call to `Manager::Manager ()'

    I have not changed the manager.....
    but it says error......HELP.....

    Any idea? Thanks


    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>

    using namespace std;

    class Container
    {
    private:
    int stock;
    public:
    Container(int);
    void SetStock(int);
    int GetStock();
    };

    Container::Container(int i)
    {
    stock = i;
    }

    void Container::SetStock(int i)
    {
    stock = i;
    }

    int Container::GetStock()
    {
    return stock;
    }


    class Menu
    {
    char option;
    public:
    // Container CokeStock(3);
    Container CokeStock;
    void display(void);
    void process(void);
    char getOption()
    { return option; }
    };

    void Menu::display()
    {
    cout << "\n\nSuper Cheap Super Drinks \n\n";
    cout << "Brands available: \n\n";
    cout << "1. <C>oke $1.30 \n";
    cout << "2. <S>prite $1.20 \n";
    cout << "3. <F>anta $1.10 \n";
    cout << "4. <R>otTooth $0.90 \n";
    cout << "5. SuperFi<Z> $1.00 \n\n";
    cout << "Please select a brand: ";
    cin >> option;
    }

    void Menu::process()
    {
    // Container CokeStock;
    // cout << CokeStock.GetStock();
    switch(option)
    {
    case '1': case 'C': case 'c':
    { if (CokeStock.GetStock() < 1 )
    {
    cout <<"\nSold Out!";
    break;
    }
    else {
    cout <<"\nCOKE DISPENSED. HAVE A NICE DAY!";
    CokeStock.SetStock(CokeStock.GetStock()-1);;
    break;
    }
    }
    //
    case '2': case 'S': case 's': cout <<"\nSPRITE DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '3': case 'F': case 'f': cout <<"\nFANTA DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '4': case 'R': case 'r': cout <<"\nROTTOOTH DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '5': case 'Z': case 'z': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case 'Q': case 'q': cout << "\nSORRY, DRINKS ARE INAVAILABLE" << endl;
    cout << "CLOSING DOWN FOR MAINTENANCE\n" << endl;
    getch();
    break;
    //
    default : cout << "\nNOT A VALID SELECTION. PLEASE SELECT AGAIN ";
    }
    }

    class Manager
    {
    Menu menu;
    public:
    void iterateMenu();
    };

    void Manager::iterateMenu()
    {
    // Container CokeStock(3);
    do
    {
    menu.display();
    menu.process();
    } while((menu.getOption()!='Q')&&(menu.getOption()!= 'q'));
    };

    void main()
    {
    Container CokeStock(3);
    Manager start;
    start.iterateMenu();
    cout << "Press any key to continue . . . " << endl;
    getch();
    };

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    6
    Originally posted by alpha
    link to read 1
    link to read 2
    SORRY......~_~
    but i really don't know how to fix it...

  6. #6
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >119 c:\docume~1\rabbit\desktop\oop\oop_a1\a1main~2.cpp no matching function for call to `Manager::Manager ()'
    You need constructors.
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed