By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

New Programmer

P: n/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()
{

}
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
>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.
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.