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
|
#include <iostream>
#include <stdlib.h>
#define NL cout<<endl;
using namespace std;
void checkProductNum(float prodNumber[],float prixProd[],int number, string name[]);
void findDetail(float prodNumberArray[],float prodPrice[],float prodNumber, int number);
bool numExists (float prodNumberProd[],int number,int chiffre);
void arraySort(float prodNumberArray[],float prodPrice[],int number, int choice);
void main()
{
int number;
float prodNumber;
int choice=0;
float *prodNumberArray;
float *prodPrice;
string name[];
cout<<"How many items will you enter: ";
cin>>number;
prodNumberArray = new float[number];
prodPrice = new float[number];
checkProductNum(prodNumberArray,prodPrice,number,name);
system("cls");
while (choice != 4){
cout<<"Choose from the following: ";NL;NL;
cout<<"1 - View products by code number.";NL;
cout<<"2 - View products by price.";NL;
cout<<"3 - View a product detail.";NL
cout<<"4 - Quit";NL;
cout<<"Enter your choice: ";NL;
cin>>choice;
switch(choice){
case 1:
system("cls");
arraySort(prodNumberArray,prodPrice,number,choice);
break;
case 2:
system("cls");
arraySort(prodPrice,prodNumberArray,number,choice);
break;
case 3:
cout<<"Prix de quel produit: ";
cin>>prodNumber;
findDetail(prodNumberArray,prodPrice,prodNumber,prodNumber);NL;
break;
case 4:
system("cls");
delete prodNumberArray;
delete prodPrice;
break;
default:
system("cls");
cout<<"Invalid entry dumn ass!";
break;
}
}
}
void checkProductNum(float prodNumber[],float prixProd[],int number, string name[]){
float prodNumberTemp;
for (int i=0;i<number;i++) {
do{
cout<<"Enter the name for this item:";
cin>>name[i];
cout<<"Entrer le product number: ";
cin>>prodNumberTemp;
}while(numExists(prodNumber,number,prodNumberTemp));
prodNumber[i] = prodNumberTemp;
cout<<"Enter the price for this item:";
cin>>prixProd[i];
}
}
bool numExists (float prodNumberProd[],int number,int chiffre){
for(int i=0;i<number;i++){
if(prodNumberProd[i] == chiffre)
return true;
}
return false;
}
void findDetail(float prodNumberArray[],float prodPrice[],float prodNumber, int number){
if (numExists(prodNumberArray,number,prodNumber)== true){
for (int i=0;i<number;i++)
if (prodNumberArray[i] == prodNumber){
cout<<"The price of "<<prodNumberArray[i]<<" is "<<prodPrice[i]<<"$";NL;
system("pause");
system("cls");
}
}
else{
cout<<"The entered product number does not exist.";NL;
system("pause");
system("cls");
}
}
void arraySort(float prodNumberArray[],float prodPrice[], int number, int choice){
float tempCode;
float tempPrix;
for (int i=0; i<(number-1);i++){
for(int j=i+1;j<number; j++){
if (prodNumberArray[i]>prodNumberArray[j]){
tempCode=prodNumberArray[i];
tempPrix=prodPrice[i];
prodNumberArray[i]=prodNumberArray[j];
prodPrice[i]=prodPrice[j];
prodNumberArray[j]=tempCode;
prodPrice[j]=tempPrix;
}
}
}
if (choice == 1){
for(int i=0;i<number;i++){
cout<<"Code:"<<prodNumberArray[i]<<"----";
cout<<"Price:"<<prodPrice[i]<<"$";NL;
}
}
else if (choice == 2){
for(int i=(number-1);i>=0;i--){
cout<<"Price:"<<prodNumberArray[i]<<"$ ----";
cout<<"Code:"<<prodPrice[i];NL;
}
}
}
|