Created
March 18, 2014 03:50
-
-
Save utjacob/9613237 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const int MAX = 10; | |
int stockAry[MAX]; | |
int yearAry[MAX]; | |
string modelAry[MAX]; | |
void aryInitilaizer(); | |
void stockInput(int i); | |
void yearSort(); | |
void stockSort(); | |
void prompt(); | |
void sortPrompt(); | |
int main() { | |
aryInitilaizer(); | |
prompt(); | |
sortPrompt(); | |
output(); | |
} | |
void aryInitilaizer() { | |
for(int i=0; i < MAX; i++) { | |
stockAry[i] = 0; | |
yearAry[i] = 0; | |
modelAry[i] = "empty"; | |
//MakeAry | |
//MilesAry | |
//PriceAry | |
} | |
} | |
void prompt() { | |
int choice = 0; | |
"What would you like to do?" << endl; | |
"1) Enter new data" << endl; | |
"2) Sort Data" << endl; | |
"Enter 1 or 2: "; | |
cin >> choice; | |
if(choice != 1 || choice != 2) { | |
choice = 0; | |
} | |
switch(choice) { | |
case 0: | |
return 0; | |
case 1: | |
for(int i=0; i < MAX; i++) { | |
stockInput(i); | |
cout << "Enter Year: "; | |
cin >> yearAry[i]; | |
cout << endl; | |
cout << "Enter Model: "; | |
cin >> modelAry[i]; | |
cout >> endl; | |
//MakeAry | |
//MilesAry | |
//PriceAry | |
} | |
case 2: | |
sortPrompt(); | |
} | |
} | |
void sortPrompt() { | |
cout << "1) Sort by Stock Number " << endl; | |
cout << "2) Sort by Year " << endl; | |
cout << "3) Sort by Make " << endl; | |
cout << "4) Sort by Model " << endl; | |
cout << "5) Sort by Mileage " << endl; | |
cout << "6) Sort by Price " << endl; | |
cout << "7) Exit Program " << endl; | |
cout << "\n\n Please select an option :"; // Prompts user to pick sort method | |
cin >> option; // Takes option value and saving as variable "Option" | |
if(option > 7) { | |
option = 7; | |
} | |
if(option == 1) | |
{ | |
stockSort(); | |
} | |
if(option == 2) | |
{ | |
yearSort(); | |
} | |
if(option == 3) | |
{ | |
} | |
if(option == 4) | |
{ | |
} | |
if(option == 5) | |
{ | |
} | |
if(option == 6) | |
{ | |
} | |
else if(option == 7) | |
{ | |
cout << "Terminating Program" << endl; | |
} | |
} | |
void output() { | |
char input; | |
cout << "would you like to view the sorted results( y or n): "; | |
cin >> input; | |
switch(input) | |
case "y": | |
for(int i=0; i < MAX; i++) { | |
cout << "Car " << i << endl; | |
cout << "Stock #: " << stockAry[i] << endl; | |
cout << "Year #: " << yearAry[i] << endl; | |
cout << "Model #: " << modelAry[i] << endl; | |
} | |
case "n": | |
prompt(); | |
} | |
} | |
void stockInput(int i) { | |
int index = i; | |
cout << "Enter Stock #: "; | |
cin >> stockAry[index]; | |
cout << endl; | |
} | |
void stockSort(char a) { | |
int i =1; | |
int j =1; | |
int flag = 1; | |
int yearTemp = 0; | |
int stockTemp = 0; | |
string modelTemp = "null"; | |
//MakeTemp | |
//MilesTemp | |
//PriceTemp | |
for(i=1; (i <= MAX) && flag; i++) { // i = 3, | |
flag = 0; //set to false | |
for(j =0; j < (MAX -1); j++) { | |
if(stockAry[j+1] > stockAry[j]) { | |
yearTemp = yearAry[j]; | |
stockTemp = stockAry[j]; | |
modelTemp = modelAry[j]; | |
//MakeTemp | |
//MilesTemp | |
//PriceTemp | |
yearAry[j] = yearAry[j+1]; | |
stockAry[j] = stockAry[j+1]; | |
modelAry[j] = modelTemp[j+1]; | |
//MakeAry j = j+1 | |
//MilesAry j = j+1 | |
//PriceAry j = j+1 | |
yearAry[j+1] = yearTemp; | |
stockAry[j+1] = stockTemp; | |
modelAry[j+1] = modelTemp; | |
//MakeAry j+1 = temp | |
//MilesAry j+1 = temp | |
//PriceAry j+1 = temp | |
flag = 1; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good!