Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string.h>
- using namespace std;
- struct custInfo
- {
- char custName[30];
- char custTel[20];
- char orderType[20];
- char orderMenu[30];
- int orderUnit;
- char modePurchase;
- float totalPrice;
- } customer[30];
- void readData(custInfo[], ifstream &);
- void calculatePrice(custInfo[]);
- void Sales(custInfo[], ofstream &);
- int main()
- {
- ifstream read;
- read.open("data.txt");
- if(read.fail())
- {
- cout << "Unable to open file!";
- exit(0);
- }
- ofstream write;
- write.open("theSales.txt");
- if(write.fail())
- {
- cout << "Unable to open file!";
- exit(0);
- }
- readData(customer, read);
- read.close();
- calculatePrice(customer);
- Sales(customer, write);
- write.close();
- }
- void readData(custInfo customer[], ifstream & read)
- {
- while(!read.eof())
- {
- for(int i = 0; i < 30; i++)
- {
- read >> customer[i].custName;
- read >> customer[i].custTel;
- read >> customer[i].orderType;
- read >> customer[i].orderMenu;
- read >> customer[i].orderUnit;
- read >> customer[i].modePurchase;
- }
- }
- }
- void calculatePrice(custInfo customer[])
- {
- for(int k = 0; k < 30; k++)
- {
- if(strcmp(customer[k].orderType, "Broiler") == 0)
- {
- if(strcmp(customer[k].orderMenu, "salmon") == 0)
- {
- customer[k].totalPrice = 60.00;
- }
- else if(strcmp(customer[k].orderMenu, "catfish") == 0)
- {
- customer[k].totalPrice = 45.00;
- }
- else if(strcmp(customer[k].orderMenu, "trout") == 0)
- {
- customer[k].totalPrice = 30.00;
- }
- }
- else if(strcmp(customer[k].orderType, "fryer") == 0)
- {
- if(strcmp(customer[k].orderMenu, "fish plate") == 0)
- {
- customer[k].totalPrice = 25.00;
- }
- else if(strcmp(customer[k].orderMenu, "calamari plate") == 0)
- {
- customer[k].totalPrice = 35.00;
- }
- else if(strcmp(customer[k].orderMenu, "fish and chips") == 0)
- {
- customer[k].totalPrice = 30.00;
- }
- }
- if(customer[k].modePurchase == 'R')
- {
- customer[k].totalPrice = customer[k].totalPrice;
- }
- else if(customer[k].modePurchase == 'W')
- {
- customer[k].totalPrice = customer[k].totalPrice - (customer[k].totalPrice * 5/100);
- }
- }
- }
- void Sales(custInfo customer[], ofstream & write)
- {
- for(int i = 0; i < 30; i++)
- {
- write << customer[i].custName;
- write << customer[i].custTel;
- write << customer[i].orderType;
- write << customer[i].orderMenu;
- write << customer[i].orderUnit;
- write << customer[i].totalPrice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement