1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
struct Item{
int iNo;
string iName;
double iPrice;
int stock;
int iDiscount;
int reLevel;
int reQuan;
};
struct Sale{
int sNo;
int quan;
double total;
int discount;
double bill;
};
int searchItem(Item items[], int numItems, int iNo){
int i;
i=0;
while (i<numItems) {
if(items[i].iNo == iNo)
return i;
i=i+1;
}
return -1;
}
int searchSale(Sale sales[], int numSales, int iNo){
int i;
i=0;
while (i<numSales) {
if(sales[i].sNo == iNo)
return i;
i=i+1;
}
return -1;
}
void Operation1 (Item items[], int numItems, int iNo){
int found;
int i;
Item *m;
m=(Item*)malloc(sizeof(Item));
found=searchItem(items, numItems, iNo);
if (found==-1)
cout<<"Item "<<iNo<<" was not found."<<endl;
cout<<endl;
for(i=0; i<numItems; i=i+1){
if(items[i].iNo==items[found].iNo){
cout<<"Displaying part #"<<iNo<<endl;
cout<<"Part Name: "<< items[i].iName<<endl;
cout<<"Selling Price: $"<< items[i].iPrice<<endl;
cout<<"Quantity in Stock: "<< items[i].stock<<endl;
cout<<"Discount Quantity: "<< items[i].iDiscount<<endl;
cout<<"Reorder Level: " << items[i].reLevel<<endl;
cout<<"Reorder Quantity: " << items[i].reQuan << endl;
cout<<endl;
}
}
}
int Operation2 (Item items[], int numItems, int iNo, int amount){
int found;
Sale sales[100];
Sale *s;
s=(Sale*) malloc(sizeof(Sale));
double dis=0.0;
double itemCost=0.0;
int numSales=0;
int re=0;
found=searchItem(items, numItems, iNo);
if(found==-1){
cout<<"Item "<<iNo<<" was not found."<<endl;
cout<<endl;
}
else{
if(amount<=items[found].stock){
itemCost=items[found].iPrice*amount;
(*s).sNo=iNo;
cout<<amount<<" "<<items[found].iName<<"(s) sold"<<endl;
cout<<endl;
items[found].stock=items[found].stock-amount;
}else{
cout<<"Not enough stock available."<<endl;
itemCost=items[found].iPrice;
cout<<endl;
}
if(amount>=items[found].iDiscount){
dis=(items[found].iPrice*dis);
itemCost=items[found].iPrice-dis;
items[found].iPrice=itemCost;
}
(*s).quan=amount;
(*s).total=itemCost;
(*s).discount=dis;
(*s).bill=itemCost;
sales[numSales]=*s;
numSales=numSales+1;
}
return numSales;
}
void Operation3(Sale sales[], Item items[], int numSales, int numItems, int iNo){
int found;
int i;
Sale *s;
s=(Sale*) malloc(sizeof(Sale));
found=searchSale(sales, numSales, iNo);
cout<<"Sales for part #"<<iNo<<endl;
if(found==-1){
cout<<"No sales for "<<iNo<<endl;
cout<<endl;
}
else{
for(i=0; i<numSales; i=i+1){
if(sales[i].sNo==iNo){
cout<<"Quantity: "<< sales[i].quan<<endl;
cout<<"Total Cost: $"<<sales[i].total<<endl;
cout<<"Discount: $"<< sales[i].discount<<endl;
cout<<"Bill Amount: $" <<sales[i].bill<<endl;
cout<<endl;
}
}
}
}
void Operation4(Item items[], int numItems){
Item *m;
m=(Item*)malloc(sizeof(Item));
int re;
if((*m).stock<(*m).reLevel)
re=re+1;
else if (re==0)
cout<<"There are no items that need reordering."<<endl;
else{
if(re>0){
cout<<"Items that need re-ordering:"<<endl;
for(int i=0; i<numItems; i=i+1){
if (items[i].stock<=items[i].reQuan)
cout<<items[i].iNo<<endl;
}
}
}
}
int main(){
ifstream in;
ifstream fin;
ofstream out;
Item items[100];
Item *m;
m=(Item*)malloc(sizeof(Item));
Sale sales[100];
Sale *s;
s=(Sale*) malloc(sizeof(Sale));
int numItems=0;
int id;
int i=0;
in.open("input.txt");
in>>id;
while(id!=-1){
(*m).iNo = id;
in>> (*m).iName >> (*m).iPrice >> (*m).stock >> (*m).iDiscount >> (*m).reLevel >> (*m).reQuan;
items[i] = *m;
numItems = numItems + 1;
i=i+1;
in >> id;
}
in.close();
int re=0;
int numSales=0;
int iNo;
int op;
int amount;
if(numItems==-1)
return 0;
in.open("sales.txt");
in>>op;
while(op!=5){
in>>iNo;
in>>amount;
if(op==1)
Operation1(items, numItems, iNo);
if(op==2){
numSales=Operation2(items, numItems, iNo, amount);
cout<<endl;
}
if(op==3)
Operation3(sales, items, numSales, numItems, iNo);
if(op==4)
Operation4(items, numItems);
in>>op;
}
if(op==5)
return 0;
}
|