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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
const int maxitem = 400; //setting maxitem number for each catergory
char search_char;
void getdata(char sortletter[maxitem],int number[maxitem], std::string itemname[maxitem],std::string unit[maxitem],double price[maxitem]);
// Import data and store into each parameter. Sortletter refers to a letter that is sorting different types of item
// Number refers to itme number, name refers to name, unit refers to which you unit the items can be bought in
// and price refers to the unit price of each item.
// The importing process is following,
void search_number(char sortletter[maxitem],int number[maxitem], std::string itemname[maxitem],std::string unit[maxitem],double price[maxitem],char inputletter, int inputnumber,std::string itemoutname, std::string itemoutunit, double itemoutprice);
// uses all the first parameter to confirm, later the additional parameter for outputs
void search_name(char sortletter[maxitem],int number[maxitem], std::string itemname[maxitem],std::string unit[maxitem],double price[maxitem],char inputletter, int inputnumber, std::string inputname, std::string itemoutname, std::string itemoutunit, double itemoutprice);
// basically same as search_number but uses name this time
void search_name_string_change(std::string namesearch, std::string ioname);
//takes the search term and converts it back to capitalized characters to make the search simpler.
char search_name_char_change(char search_char,char new_char);
// changes item sort letter to capital
int main()
{ using namespace std;
int response; //Variables
char itemletter;
char first_char;
int itemnumber;
string itemname_search;
string itemoutname;
string itemoutunit;
double itemoutprice;
char sortletter[maxitem];
int number[maxitem];
string itemname[maxitem];
string unit[maxitem];
string input_itemname;
double price[maxitem];
char shoppinganswer;
char searchanswer='Y';
cout<< "Canamarine Supply Corp, Shopping List/Calculator" << endl;
cout<<"Welocome!" <<endl;
cout<<" "<<endl;
cout<<"Enter '1' to search by name or enter '2' to search by the product number"<<endl;
cout<<"1) Search By Name. "<<endl;
cout<<"2) Search By Number. "<<endl; //User Interface
cin >> response;
if(response ==1)
{cout<<"Enter The Product Name. "; //Search By name
cin>>itemname_search;
search_name_string_change(itemname_search,input_itemname);
}else if (response ==2)
{cout <<"Enter the Product Sorting Letter. "; //Search By Number, need capitalization function
cin >> first_char;
search_name_char_change(first_char,itemletter);
cout <<"Enter the Product Number. ";
cout << itemletter;
cin >> itemnumber;
}else do {if (response !=1||response!=2)
{cout<<"Please enter a valid Integer Value. "; // loop when wrong value is entered
cin>>response;
} }while (response == 1 || response == 2);
// still needs a fix!
getdata(sortletter,number,itemname,unit,price);
//function call
do
{search_name(sortletter, number, itemname, unit, price, itemletter,
itemnumber, input_itemname, itemoutname, itemoutunit, itemoutprice);
cout<< "The Search Result. "<< endl;
cout<< itemletter << itemnumber << endl;
cout<<itemoutname<< " "<<itemoutunit<<" "<<itemoutprice<<endl; //resutl price
cout<< "Add to the shopping cart? Y/N";
cin>> shoppinganswer;
//need a function call for shopping cart
cout<< "Search Again? Y/N"<< endl;
cin >> searchanswer;
if(searchanswer == 'y' || searchanswer == 'Y')
{searchanswer = 'Y';}
else;
} while (response == 1 && searchanswer == 'Y');
do
{search_number(sortletter,number,itemname,unit,price,itemletter,itemnumber,itemoutname,itemoutunit,itemoutprice);
cout<< "The Search Result. "<< endl;
cout<< itemletter << itemnumber << endl;
cout<<itemoutname<< " "<<itemoutunit<<" "<<itemoutprice<<endl; //result print
cout<< "Add to the shopping cart? Y/N";
cin>> shoppinganswer;
//need a function call for shopping cart
cout<< "Search Again? Y/N"<< endl;
cin >> searchanswer;
if(searchanswer == 'y' || searchanswer == 'Y')
{searchanswer = 'Y';}
else;
} while (response == 2 && searchanswer == 'Y');
system("pause");
return 0;
}
void getdata(char sortletter[maxitem],int number[maxitem], std::string itemname[maxitem],std::string unit[maxitem],double price[maxitem])
{ using namespace std;
int i =0;
ifstream infile1("H:\\CSC\\final project\\datafile.dat");
do {
infile1 >> sortletter[i];
infile1 >> number[i];
infile1 >> itemname [i];
infile1 >> unit [i];
infile1 >> price [i];
i++;
} while (i<400);
}
void search_number(char sortletter[maxitem],int number[maxitem], std::string itemname[maxitem],
std::string unit[maxitem],double price[maxitem],char inputletter, int inputnumber,
std::string itemoutname, std::string itemoutunit, double itemoutprice)
{ using namespace std;
int i=0;
do
{i++;}
while (inputletter != sortletter[i]);
inputletter = sortletter [i];
i=0;
do
{i++;}
while (inputnumber != number [i]);
inputnumber = number [i];
itemoutname = itemname [i];
itemoutunit = unit [i];
itemoutprice = price [i];
}
void search_name(char sortletter[maxitem],int number[maxitem], std::string itemname[maxitem],
std::string unit[maxitem],double price[maxitem],char inputletter, int inputnumber,
std::string inputname, std::string itemoutname, std::string itemoutunit, double itemoutprice)
{ using namespace std;
int i=0;
for (i=0; inputname != itemname [i]; i++)
{itemoutname = itemname [i];}
i++;
itemoutname = itemname [i];
inputletter = sortletter [i];
inputnumber = number [i];
itemoutname = itemname [i];
itemoutunit = unit [i];
itemoutprice = price [i];
}
void search_name_string_change(std::string namesearch,std::string ioname) //name conversion
{ using namespace std;
for (int i=0; i<(namesearch.length()); i++)
{
ioname = static_cast<char>(toupper(namesearch[i]));
}
}
char search_name_char_change(char search_char,char new_char) //letter conversion
{ using namespace std;
if (search_char == 'v'|| search_char == 'V')
{new_char = 'V';
}else if (search_char == 'm' || search_char == 'M')
{new_char = 'M';
}else if (search_char == 'f' || search_char == 'F')
{new_char = 'F';
}else if (search_char == 's' || search_char == 'S')
{new_char = 'S';
}else if (search_char == 'g' || search_char == 'G')
{new_char = 'G';
}else;
return (new_char);
}
|