New Programmer

Discussion in 'C++' started by AKF, Dec 10, 2003.

  1. AKF

    AKF Guest

    I have a program that requires being able to read in a file, add a new
    item to the file and to delete an item from the file. How do I now
    implement it using an array?

    /*Declare header files to be used in the program*/
    #include<iostream.h>
    #include<string.h>
    #include<stdlib.h>
    #include<stdio.h>


    //Declaring structures to be used in the program
    struct Stock_Item;
    struct Bill;
    struct Bill_Item;
    struct Stock;

    struct Stock_Item //Function prototype for a Stock data type
    {
    int code;
    char description[25];
    float price;
    };

    struct Stock
    {
    Stock_Item si[20];
    int nStock_Item;
    };

    struct Bill_Item //Function prototype for a Bill_Item data type
    {
    int code;
    char description[25];
    float weight;
    float cost;
    };

    struct Bill //Function prototype for a Bill data type
    {
    Bill_Item bi[20];
    int nitems;
    };


    //Function Prototypes available to the data structure
    void add_Bill_Item(Bill_Item& bi, int* code, char* desc, float* w,
    float* c);
    void add_Stock_Item (Stock_Item& si, int* code, char* desc, float* c);
    void display_Bill_Item(Bill_Item bi);
    void display_Stock_Item(Stock_Item si);
    void create_Stock_Item(Stock_Item& si);
    void create_Stock(Stock& s);


    //Setting stock_Item

    void add_Stock_Item(Stock_Item& si, int code, char desc, float p)
    {
    cout << "Enter a code:";
    cin >> si.code;
    cout << "Enter a description:";
    cin >> si.description;
    cout << "Enter a price:";
    cin >> si.price;
    }

    //Display Stock_Item structure operations
    void display_Stock_Item(Stock_Item si)
    {
    cout << si.code << si.description << si.price <<endl;
    }


    //Setting Bill_Item

    void add_Bill_Item(Bill_Item& bi)

    {
    cout << "Enter a code:";
    cin >> bi.code;
    cout << "Enter a description:";
    cin >> bi.description;
    cout << "Enter a weight:";
    cin >> bi.weight;
    cout << "Enter a cost:";
    cin >> bi.cost;
    }


    //Display Bill_Item Structure Operations
    void display_Bill_Item(Bill_Item bi)
    {
    cout << bi.code << bi.description << bi.weight <<bi.cost <<endl;
    }




    //*****************THE ACTUAL PROGRAM STARTS HERE**************

    void main()
    {

    }
     
    AKF, Dec 10, 2003
    #1
    1. Advertising

  2. AKF

    jbruno4000 Guest

    >I have a program that requires being able to read in a file, add a new
    >item to the file and to delete an item from the file. How do I now
    >implement it using an array?
    >
    >/*Declare header files to be used in the program*/
    >#include<iostream.h>
    >#include<string.h>
    >#include<stdlib.h>
    >#include<stdio.h>
    >
    >
    >//Declaring structures to be used in the program
    >struct Stock_Item;
    >struct Bill;
    >struct Bill_Item;
    >struct Stock;
    >
    >struct Stock_Item //Function prototype for a Stock data type
    >{
    > int code;
    > char description[25];
    > float price;
    >};
    >
    >struct Stock
    >{
    > Stock_Item si[20];
    > int nStock_Item;
    >};
    >
    >struct Bill_Item //Function prototype for a Bill_Item data type
    >{
    > int code;
    > char description[25];
    > float weight;
    > float cost;
    >};
    >
    >struct Bill //Function prototype for a Bill data type
    >{
    > Bill_Item bi[20];
    > int nitems;
    >};
    >
    >
    >//Function Prototypes available to the data structure
    >void add_Bill_Item(Bill_Item& bi, int* code, char* desc, float* w,
    >float* c);
    >void add_Stock_Item (Stock_Item& si, int* code, char* desc, float* c);
    >void display_Bill_Item(Bill_Item bi);
    >void display_Stock_Item(Stock_Item si);
    >void create_Stock_Item(Stock_Item& si);
    >void create_Stock(Stock& s);
    >
    >
    >//Setting stock_Item
    >
    >void add_Stock_Item(Stock_Item& si, int code, char desc, float p)
    >{
    > cout << "Enter a code:";
    > cin >> si.code;
    > cout << "Enter a description:";
    > cin >> si.description;
    > cout << "Enter a price:";
    > cin >> si.price;
    >}
    >
    >//Display Stock_Item structure operations
    >void display_Stock_Item(Stock_Item si)
    >{
    > cout << si.code << si.description << si.price <<endl;
    >}
    >
    >
    >//Setting Bill_Item
    >
    >void add_Bill_Item(Bill_Item& bi)
    >
    >{
    > cout << "Enter a code:";
    > cin >> bi.code;
    > cout << "Enter a description:";
    > cin >> bi.description;
    > cout << "Enter a weight:";
    > cin >> bi.weight;
    > cout << "Enter a cost:";
    > cin >> bi.cost;
    >}
    >
    >
    >//Display Bill_Item Structure Operations
    >void display_Bill_Item(Bill_Item bi)
    >{
    > cout << bi.code << bi.description << bi.weight <<bi.cost <<endl;
    >}
    >
    >
    >
    >
    >//*****************THE ACTUAL PROGRAM STARTS HERE**************
    >
    >void main()
    >{
    >
    >}
    >
    >
    >


    Your question is very unclear. From your first 3 lines of text, I thought you
    were seeking advice on textfile processing and doing the same task using an
    array, but from the additional code you've written, it looks like you want
    someone to write the application for you. Which is it? If it's the advice, then
    please restate the question and stick to the issue.
     
    jbruno4000, Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sanny
    Replies:
    391
    Views:
    41,637
    anish.mathew84
    Jan 6, 2010
  2. Sanny
    Replies:
    396
    Views:
    7,080
    Noah Roberts
    Dec 17, 2008
  3. Isaac
    Replies:
    0
    Views:
    389
    Isaac
    Dec 8, 2010
  4. Isaac
    Replies:
    0
    Views:
    367
    Isaac
    Dec 8, 2010
  5. Replies:
    2
    Views:
    470
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page