Data Structure (C++) Help!!!

Discussion in 'School Work Help' started by dom88_rx7, Mar 2, 2010.

  1. dom88_rx7

    dom88_rx7 Well-Known Member

    266
    268
    64
    1) write a simple Point Of Sales system
    2) Interface in DOS mode only
    3) use binary file to keep the daily sales
    4) try your creativity to create it different from other group
    5) must use ADT link list, Stack or Queue
    6) submit report with formal cover page project, printed source code and screen shot.
     
  2. dom88_rx7

    dom88_rx7 Well-Known Member

    266
    268
    64
    my plan of doing tis programming is:
    1)File opening storing items with price
    2)Body:
    type the code of the items,price wil come out
    require user to type quantity
    quantity times the price wil get the total prices
    total up the total prices(for many items)
    delete the items tat was inputted wrongly
    queue up items tat have been sold the most in terms of quantity
    destroy the whole list of the inputs
    3)Output: DOS interface with the total sales with details of items,quantity sold, total sold and grand total
    4)Output files: textpad files tat store daily sales n convert them in binary files so ppl can't c the codings

    Questions:
    how to do it in C++ programming coding?
    how to store files in binary?

    here's the library n implementation(resource) file i've done

    1st library

    #include "StackException.h"
    const int MAX_STACK = maximum-size-of-stack;
    typedef desired-type-of-stack-item StackItemType;

    /** @class Stack
    * ADT stack - Array-based implementation. */
    class Stack
    {
    public:
    // constructors and destructor:
    /** Default constructor. */
    Stack();
    // copy constructor and destructor are
    // supplied by the compiler

    // stack operations:
    /** Determines whether this stack is empty.
    * @pre None.
    * @post None.
    * @return True if this stack is empty; otherwise returns
    * false. */
    bool isEmpty() const;

    /** Adds an item to the top of this stack.
    * @pre newItem is the item to be added.
    * @post If the insertion is successful, newItem is on the top
    * of this stack.
    * @param newItem The given StackItemType.
    * @throw StackException If the item cannot be placed on this
    * stack. */
    void push(const StackItemType& newItem) throw(StackException);

    /** Removes the top of this stack.
    * @pre None.
    * @post If this stack is not empty, the item that was added most
    * recently is removed. However, if this stack is empty,
    * deletion is impossible.
    * @throw StackException If this stack is empty. */
    void pop() throw(StackException);

    /** Retrieves and removes the top of this stack.
    * @pre None.
    * @post If this stack is not empty, stackTop contains the item
    * that was added most recently and the item is
    * removed. However, if this stack is empty, deletion is
    * impossible and stackTop is unchanged.
    * @throw StackException If this stack is empty. */
    void pop(StackItemType& stackTop) throw(StackException);

    /** Retrieves the top of this stack.
    * @pre None.
    * @post If this stack is not empty, stackTop contains the item
    * that was added most recently. However, if this stack is
    * empty, the operation fails and stackTop is
    * unchanged. This stack is unchanged.
    * @throw StackException If this stack is empty. */
    void getTop(StackItemType& stackTop) const
    throw(StackException);

    private:
    /** Array of stack items */
    StackItemType items[MAX_STACK];
    /** Index to top of stack */
    int top;
    }; // end Stack

    class StackA
    {
    public:
    StackA(void);
    public:
    ~StackA(void);
    };
    // End of header file.


    2nd library

    #include <stdexcept>
    #include <string>

    using namespace std;

    /** @class StackException
    * Exception class throw by ADT stack. */
    class StackException : public logic_error
    {
    public:
    StackException(const string& message = "")
    : logic_error(message.c_str())
    {} // end constructor
    }; // end StackException


    implementation (resource) file

    #include "Stacka.h" // Stack class specification file

    Stack::Stack() : top(-1)
    {
    } // end default constructor

    bool Stack::isEmpty() const
    {
    return top < 0;
    } // end isEmpty

    void Stack::push(const StackItemType& newItem)
    throw(StackException)
    {
    // if stack has no more room for another item
    if (top >= MAX_STACK-1)
    throw StackException("StackException: stack full on push");
    else
    { ++top;
    items[top] = newItem;
    } // end if
    } // end push

    void Stack::pop() throw(StackException)
    {
    if (isEmpty())
    throw StackException("StackException: stack empty on pop");
    else
    --top; // stack is not empty; pop top
    } // end pop

    void Stack::pop(StackItemType& stackTop) throw(StackException)
    {
    if (isEmpty())
    throw StackException("StackException: stack empty on pop");
    else
    { // stack is not empty; retrieve top
    stackTop = items[top];
    --top; // pop top
    } // end if
    } // end pop

    void Stack::getTop(StackItemType& stackTop) const throw(StackException)
    {
    if (isEmpty())
    throw StackException("StackException: stack empty on getTop");
    else
    // stack is not empty; retrieve top
    stackTop = items[top];
    } // end getTop
    // End of implementation file.


    Main(source) file

    #include <iostream>
    #include <string>
    #include <fstream>
    #include <math.h>
    #include <StackA.h>
    #include <StackException.h>
    #include <StackA.cpp>
    using namespace std;

    ifstream inFile("input.txt")
    ?
    ?
    ?
    HELP ME!!! I think til my brain explode oso cannot figure out how to do the rest...
     
  3. i'd help you but i don't know c++ XD
     
  4. dom88_rx7

    dom88_rx7 Well-Known Member

    266
    268
    64
    huh. i'm run out of ideas.
    most of my coursemates who are dealing with tis question is oso out of ideas.
    ask lecturer, after he talk nonsense, oso no ideas.
    find internet, i got tis:

    #include <iostream>
    #include <iomanip>

    using namespace std;

    void display_menu();
    void tax();
    float total = 0;

    int main()
    {
    char choice;
    display_menu();
    cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << setprecision(2);
    while {
    cout << "Welcome to the Rodeo Snack Bar!" << endl;
    cout << "Your current total is: $"<< total << endl;
    cout << "Please enter the letter of your selection: ";
    cin >> choice;
    cout << endl;
    switch (choice) {
    case 'S': case 's':
    cout << "Sandwich - $5.00" << endl;
    total+=5;
    display_menu();
    break;
    case 'C': case 'c':
    cout << "Chips - $1.50" << endl;
    total+=1.5;
    display_menu();
    break;
    case 'P': case 'p':
    cout << "Pickle - $0.75" << endl;
    total+=.75;
    display_menu();
    break;
    case 'B': case 'b':
    cout << "Brownie - $1.00" << endl;
    total+=1;
    display_menu();
    break;
    case 'R': case 'r':
    cout << "Regular Drink - $2.00" << endl;
    total+=2;
    display_menu();
    break;
    case 'L': case 'l':
    cout << "Large Drink - $3.50" << endl;
    total+=3.5;

    but stil no ideas
    display_menu();
    break;
    case 'X' : case 'x':
    cout << "Canceled, please start over." << endl;
    total = 0;
    display_menu();
    break;
    case 'T' : case 't':
    tax();
    break;
    default:
    display_menu();
    }
    }
    }

    void display_menu()
    {
    cout << endl;
    cout << "S - Sandwich $5.00" << endl;
    cout << "C - Chips $1.50" << endl;
    cout << "P - Pickle $0.75" << endl;
    cout << "B - Brownie $1.00" << endl;
    cout << "R - Regular Drink $2.00" << endl;
    cout << "L - Large Drink $3.50" << endl;
    cout << "X - Cancel sale and start over" << endl;
    cout << "T - Total the sale" << endl;
    cout << "All items have additional 8.25% tax." << endl;
    }


    void tax(float total)

    cout << "Sub-total: " << total << endl;
    cout << "+ Tax : " << total*0.0825 << endl;
    cout << "Total : " << total + (total*0.0825)<< endl;
     
  5. iiimj4everiii

    iiimj4everiii Well-Known Member

    211
    241
    0
    arg i took basic c++ so im not sure. can u put the ordered items in a 2d array and if toggled X/x, you can select which item(s) to delete. and the array will total up the sum as you add/delete stuffs from it. This way u wont have to cancel the whole menu and set total to 0. Also you might want to count how many items are being ordered so something like

    int count = 0;
    int itemNum [100];
    char itemCode [100];
    float itemPrice [100];

    for (int i = 0, i < 100, i++){
    itemPrice = 0;
    itemNum = i+1;
    }

    and then the switch thing.

    then whenever you toggle X/x, bring up itemNum, itemCode and itemPrice. and use build-in array functions to help you take things off.
     
    #5 iiimj4everiii, Apr 2, 2010
    Last edited: Apr 2, 2010
  6. iiimj4everiii

    iiimj4everiii Well-Known Member

    211
    241
    0
    also i ran the program above, the while loop needs a fix, and this whole junk here
    cin >> choice;
    cout << endl;
    switch (choice) {
    case 'S': case 's':
    cout << "Sandwich - $5.00" << endl;
    total+=5;
    display_menu();
    break;
    case 'C': case 'c':
    cout << "Chips - $1.50" << endl;
    total+=1.5;
    display_menu();
    break;
    case 'P': case 'p':
    cout << "Pickle - $0.75" << endl;
    total+=.75;
    display_menu();
    break;
    case 'B': case 'b':
    cout << "Brownie - $1.00" << endl;
    total+=1;
    display_menu();
    break;
    case 'R': case 'r':
    cout << "Regular Drink - $2.00" << endl;
    total+=2;
    display_menu();
    break;
    case 'L': case 'l':
    cout << "Large Drink - $3.50" << endl;
    total+=3.5;

    but stil no ideas
    display_menu();
    break;
    case 'X' : case 'x':
    cout << "Canceled, please start over." << endl;
    total = 0;
    display_menu();
    break;
    case 'T' : case 't':
    tax();
    break;
    default:
    display_menu();

    should be a function