New Programmer

A

AKF

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

}
 
J

jbruno4000

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top