Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Kevin Pavao
- //Southern Programming Team
- //SWISStoresSales.cpp
- #include<iostream>
- #include<string>
- #include<iomanip>
- #include<fstream>
- #include<cstring>
- #include<sstream>
- using namespace std;
- struct date
- {
- int month,
- day,
- year;
- char dash;
- };
- void menu();
- //enter sales by dept. returns filename
- string getSales();
- string getFileName(string storeNum, int month, int day, int year);
- //calculates sales from number of items sold
- double calculateSales(int index, string item, double price);
- //view the sales file
- void viewSales(string fileName);
- void clear();
- //converts int to string
- string itoa(int number);
- int main()
- {
- menu();
- return 0;
- }
- void menu()
- {
- int choice;
- string fileName;
- clear();
- cout << "Shoppers World Inc.\n\n";
- cout << "1. Enter the days sales by department.\n";
- cout << "2. View the days sales\n";
- cout << "3. Save the sales data\n";
- cout << "4. Quit\n";
- cout << "\n\nEnter choice: ";
- cin >> choice;
- switch(choice)
- {
- case 1:
- fileName=getSales();
- break;
- case 2:
- viewSales(fileName);
- break;
- case 3:
- {
- cout << "File Written.\n";
- cout << "Press enter to continue.";
- cin.get();
- cin.get();
- clear();
- menu();
- break;
- }
- case 4:
- {
- cout << "Press enter to quit.";
- cin.get();
- cin.get();
- break;
- }
- default:
- {
- clear();
- menu();
- break;
- }
- }
- }
- string getSales()
- {
- ofstream outfile;
- double sales[3][8], deptTtl[3]={0,0,0}, storeTtl=0;
- string department, storeNumber;
- date salesDate;
- string fileName;
- //items being sold
- string electronicItems[8]={ "Nintendos","TVs","Dell Computers","Keyboards","Media Players","Speakers","Playstation Games","DVD-Rs" };
- string clothingItems[8]={ "Shirts","Pants","Jeans","Hats","Sweaters","Shorts","Mens Underwear","Womens Underwear"};
- string outdoorItems[8]={ "Tents","Fishing Poles","Bait","Guns","Sleeping Bags","Lanterns","Flashlights","Stoves" };
- //item prices
- double electronicPrices[8]={100,250,500,25,200,50,59,20};
- double clothingPrices[8]={12,25,20,15,30,25,15,20};
- double outdoorPrices[8]={70,80,150,25,30,15,25,10};
- clear();
- cout << "Enter store number: ";
- cin >> storeNumber;
- cout << "Enter date (MM/DD/YYYY): ";
- cin >> salesDate.month >> salesDate.dash >> salesDate.day >> salesDate.dash >> salesDate.year;
- //check to see if date is valid
- while(salesDate.month < 1 || salesDate.month > 12 || salesDate.day < 1 || salesDate.day > 31 || salesDate.year < 1900)
- {
- cout << "Invalid date entered.\nPlease enter again (MM/DD/YYYY): ";
- cin >> salesDate.month >> salesDate.dash >> salesDate.day >> salesDate.dash >> salesDate.year;
- }
- //convert int variables in salesDate to string for the file name
- fileName=itoa(salesDate.month) + salesDate.dash + itoa(salesDate.day) + salesDate.dash + itoa(salesDate.year) + "_" + storeNumber + "_store.txt";
- cout << fileName;
- outfile.open(fileName.c_str());
- //outfile.open("testing.txt");
- if(!outfile) cout << "error";
- outfile << salesDate.month << salesDate.dash << salesDate.day << salesDate.dash << salesDate.year << endl;
- outfile << "Store Number: " << storeNumber << endl;
- for(int x=0; x<3; x++)
- {
- clear();
- if(x==0) department="Electronics";
- if(x==1) department="Clothing";
- if(x==2) department="Outdoor";
- cout << department << " Department Sales\n";
- outfile << endl << department << " Department Sales\n\n";
- outfile << setw(20) << left << "Item" << setw(15) << right << "Sales" << endl;
- outfile << setprecision(2) << setiosflags(ios::showpoint) << setiosflags(ios::fixed);
- for(int y=0; y<8; y++)
- {
- if(x==0)
- {
- //x=department, y=item
- sales[x][y]=calculateSales(y,electronicItems[y],electronicPrices[y]);
- deptTtl[x]+=sales[x][y];
- outfile << setw(20) << left << electronicItems[y];
- //outfile << setw(15) << left << static_cast<int>(sales[x][y]/electronicPrices[y]);
- outfile << setw(5) << right << "$" << setw(10) << right << sales[x][y] << endl;
- }
- else if(x==1)
- {
- sales[x][y]=calculateSales(y,clothingItems[y],clothingPrices[y]);
- deptTtl[x]+=sales[x][y];
- outfile << setw(20) << left << clothingItems[y];
- //outfile << setw(15) << left << static_cast<int>(sales[x][y]/clothingPrices[y]);
- outfile << setw(5) << right << "$" << setw(10) << right << sales[x][y] << endl;
- }
- else if(x==2)
- {
- sales[x][y]=calculateSales(y,outdoorItems[y],outdoorPrices[y]);
- deptTtl[x]+=sales[x][y];
- outfile << setw(20) << left << outdoorItems[y];
- //outfile << setw(15) << left << static_cast<int>(sales[x][y]/outdoorPrices[y]);
- outfile << setw(5) << right << "$" << setw(10) << right << sales[x][y] << endl;
- }
- }
- //outfile << endl;
- outfile << setw(20) << setfill('.') << left << "Dept. Total";
- outfile << setw(5) << right << "$" << setfill(' ') << setw(10) << right << deptTtl[x] << endl;
- storeTtl+=deptTtl[x];
- }
- outfile << endl;
- outfile << setw(20) << left << "Store Total ";
- outfile << setw(5) << right << "$" << setw(10) << storeTtl << endl;
- outfile.close();
- menu();
- return fileName.c_str();
- }
- double calculateSales(int index, string item, double price)
- {
- int numSold;
- double sales;
- cout << "How many " << item << " sold ($" << price << "/piece): ";
- cin >> numSold;
- sales=numSold*price;
- return sales;
- }
- void viewSales(string fileName)
- {
- ifstream infile(fileName.c_str());
- cout << fileName;
- //ifstream infile("testing.txt");
- char ch;
- clear();
- if(!infile)
- {
- cout << "Error reading file, please re-create.\n(Enter)";
- cin.get();
- cin.get();
- menu();
- }
- infile.get(ch);
- while(infile)
- {
- cout << ch;
- infile.get(ch);
- }
- infile.close();
- cout << "Press enter to continue.";
- cin.get();
- cin.get();
- menu();
- }
- void clear()
- {
- for(int x=0; x<=50; x++)
- cout << endl;
- }
- string itoa(int number)
- {
- ostringstream oss;
- oss << number;
- return oss.str();
- }
Add Comment
Please, Sign In to add comment