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
|
#include<iostream>
#include "Grocery (2).h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <string>
using namespace std;
#include<fstream>
//void BubbleSort (char* names, int size);
//void strcpy(char* , char* );
//void Swap (char*, int n, int k);
const int NUM_ITEMS = 10;
int main()
{
GroceryItem grocery_items[NUM_ITEMS];
ifstream inFile;
inFile.open("Grocery.txt");
int k, result;
char* tempy = new char;
double temp;
int stock;
for(k = 0; k < NUM_ITEMS; k++)
{
inFile.getline(tempy,256,'\n');
grocery_items[k].set_item_name(tempy);
inFile >> temp;
grocery_items[k].set_item_price(temp);
inFile >> stock;
grocery_items[k].set_qty_on_hand(stock);
inFile.ignore();
}
cout<<"The grocery items along with their respective price, and qty on hand are: "<<endl;
for(k = 0; k < NUM_ITEMS; k++)
{
cout<<grocery_items[k].get_item_name()<<" "<<grocery_items[k].get_item_price()
<<" "<<grocery_items[k].get_qty_on_hand()<<endl;
}
char* item = new char;
int want;
char answer;
do
{
cout<<"Please indicate the grocery items you want: ";
cin.getline(item,30,'\n');
cout<<endl<<"Please the quantity of the items wanted: ";
cin>>want;
cout<<endl<<"Would you like to continue purchasing items? Please enter Y for yes or N for no."<<endl;
cin.ignore();
cin>>answer;
for( int r = 0; r < NUM_ITEMS; r++)
{
result = strcmp(grocery_items[r].get_item_name(),item);
if(!result)
{
grocery_items[r].set_qty_purchased(want);
}
}
cin.ignore();
}while(answer=='y'||answer=='Y');
double Total = 0;
int i, j;
char* temporary = NULL;
for(i = 0; i < NUM_ITEMS; i++)
for(j = 0; j < NUM_ITEMS-1; j++)
if(strcmp(grocery_items[i].get_item_name(), grocery_items[i+1].get_item_name()) > 0){
//swap the two array elements
strcpy(temporary, grocery_items[j].get_item_name());
strcpy(grocery_items[j].get_item_name(), grocery_items[j+1].get_item_name());
strcpy(grocery_items[j+1].get_item_name(), temporary);
}
//BubbleSort(grocery_items[10].get_item_name(), 20);
for(int m = 0; m < NUM_ITEMS; m++)
{//BubbleSort(grocery_items[m].get_item_name(), 20);
if(grocery_items[m].get_qty_purchased() == 0)
{
}
else
{
cout<<"The customer purchased: "<<grocery_items[m].get_qty_purchased()<<" "<<grocery_items[m].get_item_name()<<endl;
Total = Total + grocery_items[m].get_item_price() * grocery_items[m].get_qty_purchased();
}
}
cout<<"The customer's total bill is: "<<Total<<endl;
cout<<"The order will be delivered by the end of the day."<<endl;
inFile.close();
system("pause");
return 0;
}
|