CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Posts
    11

    Menu, how to put calculation in there

    so, this is my coding.

    Code:
    #include<iostream.h>
    #include<fstream.h>
    #include<stdlib.h>
    #include<iomanip.h>
        using std::cout;
        using std::cin;
        using std::endl;
        
        struct menu
    	typedef struct menu RECORD;
    	void addRecord(RECORD input[], int arraycounter);
    	void printRecord( input[]);	
    	void printAllRecord( input[]);
    	
    int main()
    {
        fstream submit;
    	submit.open("D:jualan.dat",ios::out);
    	
        {
        int menuEnter;
        int arraycounter=0;
        
        do
        {
        cout<<"\tFamily Outfit Shop"<<endl;
        cout<<"\t    MAIN MENU"<<endl;
        cout<<"\t-------------------"<<endl;
        cout<<" 1 = Add a record\n";
        cout<<" 2 = Displays sales report for a category\n";
        cout<<" 3 = Displays sales report for all category\n";
        cout<<" 4 = Exit";
        cout<<"\nEnter Menu Number : ";
        cin>> menuEnter;
         
        if(menuEnter == 1 )
        addRecord;
        else if (menuEnter == 2 )
        printRecord;
        else if (menuEnter == 3)
        printAllRecord;
        } while (menuEnter!=4);
        return 0;
        }
         
    	void addRecord(RECORD input[], int arraycounter);
        {
        char codeCate; // code category
        char codeNumbCate;  // code number category
    
        cout<<"Enter code category : \n";
        cin>>input[arraycounter].codeCate;
        cout<<"Enter code number of category : \n";
        cin>>input[arraycounter].codeNumbCate;
        arraycounter++;
        }
         
    	void printRecord(RECORD input[]);
        {
         
        cout<<"SALES REPORT FOR "<<explanation<<endl;
        cout<<"\nItem Number\t\tPrice" << endl;
        cout<<"------------------------------"<<endl;
        cout<<codeCate<<"\t\t"<<price<<endl;
        cout<<"------------------------------"<<endl;
        cout<<"Total Sales\t\t"<<totalSales<<endl;
        cout<<endl;
        }
    
    	void printAllRecord(RECORD input[]);
        {
        cout<<"SALES REPORT FOR ALL CATEGORIES"<<endl;
        cout<<"\nCategory\t\tSales" << endl;
        cout<<"------------------------------"<<endl;
        cout<<explation<<"\t\t"<<price<<endl;
        cout<<"------------------------------"<<endl;
        cout<<"Total Sales\t\t"<<totalSales<<endl;
        cout<<endl;
        }
    }
    error? yes, it is, bcoz i still did not finish it...
    still, i'm running doing this coding and keep doing it, but i need help.
    i keep doing mine, still someone must help me.
    i will post update for my new coding...

    there is the question. sorry bcoz it is long.

    Family Outfit Shop decided to create a computerized system to maintain the shop inventory. The shop sells variety of garments and the garments are categorized to a particular group. Each category is given a code and the explanation for each code is given bellow.


    CODE | EXPLANATION
    A | baby wear
    B | children wear
    C | ladies wear
    D | menswear

    You as a programmer are required to write a program which contains a menu as bellow:

    Family Outfit Shop
    MAIN MENU
    1)Add a record
    2)Display sales report for a category
    3)Display sales report for all category
    4)Exit


    Guideline
    The program should give the user an option to choose any sub menu and it would only stop when the user choose the Exit sub menu.

    1)Add a record
    This sub menu will add a sales record for a particular garment into a file name jualan.dat. Each record consists of three fields which are item number, item code and price. The user may add more than one record at a time. You can use a sentinel value to control the loop. Assumed that file jualan.dat already exists. Example of file jualan.dat is shown as bellow:
    A101= A =10.00
    B101= B = 12.00
    A102 =A= 5.00
    B105= B = 17.00
    C103 =C= 40.00
    D101 =D = 15.00
    B104 =B =20.00


    2)Display sales report for a category
    In this sub menu the sales report of a particular category will be displayed. The category shall be chosen by the user.

    SALES REPORT FOR BABY WEAR
    Item Number | Price
    A101 | 10.00
    A102 | 5.00
    Total Sales | 15.00


    3)Display sales report for all category
    In this sub menu the sales report for all the categories will be displayed.

    SALES REPORT FOR ALL CATEGORIES
    Category Sales
    Baby wear 15.00
    Children wear 49.00
    Ladies wear 40.00
    Menswear 15.00
    Total Sales 119.00


    4)Exit
    End of program.
    so, how / where to put claculation in there?
    i means, in record or print...
    i try....
    and also, how to display multiple of item number?
    Last edited by khelly; December 27th, 2011 at 12:16 AM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Menu, how to put calculation in there

    Code:
    #include<iostream.h>
    #include<fstream.h>
    #include<iomanip.h>
    What compiler are you using? It certainly isn't Visual C++, at least not any version of Visual C++ that is less than 12 years old.

    There is no such header as <iostream.h>, <fstream.h>, or <iomanip.h>. The correct headers are:
    Code:
    #include<iostream>
    #include<fstream>
    #include<iomanip>
    Second, since you are using the wrong headers, this code makes no sense:
    Code:
        using std::cout;
        using std::cin;
        using std::endl;
    There is no "std" namespace defined in those incorrect .h headers. Use the proper headers, and then the code above makes sense.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Dec 2011
    Posts
    11

    Re: Menu, how to put calculation in there

    ok, that qould be help...

    seriously anybody?

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Menu, how to put calculation in there

    Quote Originally Posted by khelly View Post
    so, how / where to put claculation in there?
    i means, in record or print...
    i try....
    Create a function that performs the calculation. Then you can call that function anywhere you want to that makes sense.

    The problem with your program is you have one gigantic main() function, and you can't write a program that has this many requirements by sticking everything in main().

    You're supposed to take each piece, write a function, test that function. Then when they are all tested, then you write a main() program that calls those functions.

    Also, the menu is the least important part of this assignment. It doesn't matter how the data gets in, whether it be a menu or if it's hard-coded -- the most important part of the assignment is when given data (regardless where it comes from), does it do the calculations correctly. All of that stuff with doing this and that with menus is designed to have you waste a lot of time doing the unimportant things in a program, while the things that really matter never get done.

    That's why you concentrate on the "business logic" first, and the fancy menus come last. A program that has fancy menus and can't calculate anything is worthless. A program that can calculate but has no user interface is worth much more, as programming a user interface is very simple.

    Regards,

    Paul McKenzie

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Menu, how to put calculation in there

    Code:
       
     if(menuEnter == 1 )
        addRecord;
    That's not how you call functions.

    Is it really that much trouble to write "because"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured