Help

A

AKF

I need to be able to total an amount. Can anyone tell me how to do it
please?

i need to be able to enter a weight and to multiply that weight by the
price in another structure. Then i need to be able to produce a total
cost.

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

const int SIZE = 20;
const int QUIT = 0;

//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[SIZE];
int nsi;
};

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[SIZE];
int nbi;
};


//Function Prototypes available to the data structure
void add_Stock_Item (Stock& s, Stock_Item si);
void display_Stock_Item(Stock_Item si);
void display_All_Stock_Items(Stock s);
void create_Stock_Item(Stock_Item& si);
int get_code(Stock_Item si);

void create_Stock(Stock& s);
void delete_Stock(Stock& s, Stock_Item si);
void loadStock(Stock &s);

void create_Bill(Bill& b);
void add_Bill_Item(Bill_Item& bi, int code, char desc, float w, float
c);
void display_Bill_Item(Bill_Item bi);
void create_Bill_Item(Bill_Item& bi);
void delete_Bill(Bill& b, Bill_Item bi);
int get_code(Bill_Item bi);

void display_menu();
void get_option(int&);


int get_code(Stock_Item si)
{
return si.code;
}


int get_code(Bill_Item bi)
{
return bi.code;
}


//initialising Stock Items to zero for the array
void create_Stock(Stock& s)
{
s.nsi = 0;
}

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

void display_All_Stock_Items(Stock s)
{
for (int i = 0; i < s.nsi; i++)
{
display_Stock_Item(s.si);
}
}

//Setting stock_Item

void add_Stock_Item (Stock& s, Stock_Item Stock_Item)
{
s.si[s.nsi] = Stock_Item;
s.nsi++;
}


void create_Stock_Item (Stock_Item &si)
{
cout <<"Enter a code number: ";
cin >> si.code;
cout <<"Enter a product description: ";
cin >> si.description;
cout <<"Enter a price: ";
cin >>si.price;
}


//Deleting a Stock Item
void delete_Stock(Stock& s)
{
int scode, dindex = -1;

cout <<"Enter a code number: ";
cin >> scode;

for (int i=0; i < s.nsi; i++)
if(get_code(s.si) == scode) dindex = i;

if (dindex != -1)
{
s.si[dindex] = s.si[s.nsi - 1];
s.nsi--;
}

}
//***************************END OF STOCK & STOCK
ITEMS*****************


//**************************START OF BILL ITEMS &
BILLS****************

//Initialising Bill_Items to zero

void create_Bill(Bill& b)
{
b.nbi = 0;
}

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

//Displays all Bill_Items
void display_All_Bill_Items(Bill b)
{
for (int i = 0; i < b.nbi; i++)
{
display_Bill_Item(b.bi);
}
}

//Setting Bill_Item

void add_Bill_Item(Bill& b, Bill_Item Bill_Item)

{
b.bi[b.nbi] = Bill_Item;
b.nbi++;

}


void create_Bill_Item (Bill_Item &bi)
{
cout <<"Enter a code number: ";
cin >> bi.code;
cout <<"Enter a product description: ";
cin >> bi.description;
cout <<"Enter a Weight: ";
cin >> bi.weight;

}



//Deleting a Bill Item
void delete_Bill(Bill& b)
{
int bcode, dindex = -1;

cout <<"Enter a code number: ";
cin >> bcode;

for (int i=0; i < b.nbi; i++)
if(get_code(b.bi) == bcode) dindex = i;

if (dindex != -1)
{
b.bi[dindex] = b.bi[b.nbi - 1];
b.nbi--;
}

}

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

void main()

{
int option;
Stock myStock;
create_Stock(myStock);
Stock_Item myStockItem;
loadStock(myStock);

Bill mybill;
create_Bill(mybill);
Bill_Item mybillitem;


do
{
display_menu();
get_option(option);

switch (option)
{
case 1: //Save_Stock(& s);

break;

case 2:
display_All_Stock_Items(myStock);
break;

case 3:
create_Stock_Item(myStockItem);
add_Stock_Item(myStock, myStockItem);
break;

case 4:
delete_Stock(myStock);
break;

case 5:
create_Bill_Item(mybillitem);
add_Bill_Item(mybill, mybillitem);
break;

case 6:
delete_Bill(mybill);
break;

case 7:
display_All_Bill_Items(mybill);
break;


}

}
while(option !=QUIT);
}

//Display menu options

void display_menu()
{
cout << "Options Menu\n\n";
cout << "0 - QUIT\n";
cout << "1 - Save Stock\n";
cout << "2 - Display Stock All Items\n";
cout << "3 - Add Stock Item\n";
cout << "4 - Delete Stock Items\n";
cout << "5 - Add Bill Item\n";
cout << "6 - Delete a Bill Item\n";
cout << "7 - Display Bill\n";

}

//Get menu option

void get_option(int& opt)
{
while (cin >> opt, (opt > 7 || opt < QUIT))
cout << "This is not a valid option between 1 and 6 \n";
}

//How to load the stock file
void loadStock(Stock &s)
{
Stock_Item si;

ifstream fin;
fin.open("prices.txt");

fin >> si.code >> si.description >> si.price;

while (!fin.eof())
{
add_Stock_Item(s,si);
fin >> si.code >> si.description >> si.price;
}

fin.close();
}
 

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

Similar Threads


Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,405
Latest member
DavidCex

Latest Threads

Top