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
|
#include <iostream>
#include <cstdlib>
using namespace std;
const int P = 10;
void SortingStringArray(string* str,float* intig,int lenght, bool ascending){
int PizzaNameLenght[lenght],i;
string tmp;
float tmp2;
for(int i=0;i<lenght;i++)
PizzaNameLenght[i] = str[i].length();
for (int k=0;k<lenght-1;k++){
for(int j=0;j<lenght-1;j++){
i=0;
if (ascending){
do{
if ((int)str[j].at(i)>(int)str[j+1].at(i)){
tmp = str[j];
str[j]=str[j+1];
str[j+1]=tmp;
tmp2 = intig[j];
intig[j]=intig[j+1];
intig[j+1]=tmp2;
}
i++;
}while((int)str[j].at(i-1) == (int)str[j+1].at(i-1) && PizzaNameLenght[0] > i && PizzaNameLenght[0] > i);
}
else{
do{
if ((int)str[j].at(i)<(int)str[j+1].at(i)){
tmp = str[j];
str[j]=str[j+1];
str[j+1]=tmp;
tmp2 = intig[j];
intig[j]=intig[j+1];
intig[j+1]=tmp2;
}
i++;
}while((int)str[j].at(i-1) == (int)str[j+1].at(i-1) && PizzaNameLenght[0] > i && PizzaNameLenght[0] > i);
}
}
}
}
void SortingFloatArray(float* array,string* str, int length, bool ascending){
string tmp2;
float tmp;
if (ascending){ //karto augosa seciba
for(int j=0;j<length-1;j++)
for(int i=0;i<length-1;i++)
if (array[i] > array[i+1]){
tmp2 = str[i];
str[i]=str[i+1];
str[i+1]=tmp2;
tmp = array[i];
array[i]=array[i+1];
array[i+1]=tmp;
}
}
else{ //karto dilstosa seciba
for(int j=0;j<length-1;j++)
for(int i=0;i<length-1;i++)
if (array[i] < array[i+1]){
tmp2 = str[i];
str[i]=str[i+1];
str[i+1]=tmp2;
tmp = array[i];
array[i]=array[i+1];
array[i+1]=tmp;
}
}
}
void ShowBasket(string* array,float* prices,int Order[],int length){
int cnt=0;
for (int i=0;i<length;i++){
if (Order[i] > 0){
cnt++;
}
}
if (cnt>0){
bool comma;
float total=0;
int counter=0;
cout << "Tavs grozins: ";
for (int i=0;i<length;i++){
if (Order[i]>0){
counter++;
cout << array[i] << "(" << Order[i] << ")";
total = total + Order[i]*prices[i];
if (counter==cnt)
cout << ".\n";
else
cout << ", ";
}
}
cout << "Kopa ir " << total << " Euro.\n\n";
}
}
bool AskBoolQuestion(string question){
string answer;
do{
cout << question;
cin >> answer;
system("cls");
if ((int)answer.at(0) == 49 && answer.length() == 1 )
return true;
if ((int)answer.at(0) == 50 && answer.length() == 1 )
return false;
else
cout << "Tadas iespejas nav ludzu izveleties velreiz.\n";
}
while (1<2);
}
void PrintPizza(string* Name,float* Price,int strlenght){
for(int i=0;i<strlenght;i++){
cout << Name[i];
for(int j=0;j<15-Name[i].length();j++)
cout << " ";
cout << Price[i] << endl;
}
}
int AskPizzaName(string* Name,float* Price,int Order[], int length){
string answer;
do{
cout << "\nKadu picu jus velaties pasutit? - ";
cin >> answer;
for(int i=0;i<length;i++)
if (answer == Name[i])
return i;
system("cls");
ShowBasket(Name,Price,Order,length);
PrintPizza(Name,Price,length);
cout << "\nTadas picas nav.";
}
while (1<2);
}
int main(){
string PizzaName[P]={"Turistu", "Parmas", "Vezuva", "Peperoni", "Chili","Havaju","Garda","Studentu","Rietumu","Vegetariesu" };
float PizzaPrice[P]={12.32, 17.91, 12.31, 17.63, 16.64, 13.76, 16.26, 15.49, 12.99, 13.69};
int PizzaOrder[P]={0},tmp,tmp2;
bool SortByName,Ascending,Finish;
SortByName = AskBoolQuestion("Izveleties picas pec Nosaukuma(1) vai Cenas(2):");
Ascending = AskBoolQuestion("Augosa(1) vai dilstosa(2) seciba:");
if (SortByName)
SortingStringArray(PizzaName,PizzaPrice,P,Ascending);
else
SortingFloatArray(PizzaPrice,PizzaName,P,Ascending);
do{
system("cls");
ShowBasket(PizzaName,PizzaPrice,PizzaOrder,P);
PrintPizza(PizzaName,PizzaPrice,P);
tmp = AskPizzaName(PizzaName,PizzaPrice,PizzaOrder,P);
system("cls");
ShowBasket(PizzaName,PizzaPrice,PizzaOrder,P);
PrintPizza(PizzaName,PizzaPrice,P);
cout << "\nCik " << PizzaName[tmp] << " picas jus velaties pasutit? - ";
cin >> tmp2;
PizzaOrder[tmp]=PizzaOrder[tmp]+tmp2;
Finish = AskBoolQuestion("Vai velaties pasutit vel citas picas(ne-1,ja-2)? - ");
}
while(!Finish);
ShowBasket(PizzaName,PizzaPrice,PizzaOrder,P);
return 0;
}
|