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()
{
}