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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int size=11;
class listing
{
public:
string name;
string price;
string brand;
string disp;
string power;
string category;
string speed;
string accel;
string cyl;
string cool;
string ohc;
string brake;
string valve;
string torque;
string weight;
string induct;
enum ParameterType
{
NAME=0,
PRICE,
BRAND,
DISPLACEMNT,
POWER,
CATEGORY,
TOPSPEED,
};
//Starting of Compare
bool Compare(const listing& i_RListing,ParameterType i_PType)
{
switch(i_PType)
{
case 0:
return name<i_RListing.name;
case 1:
return price<i_RListing.price;
case 2:
return brand<i_RListing.brand;
case 3:
return disp<i_RListing.disp;
case 4:
return power<i_RListing.power;
case 5:
return category<i_RListing.category;
case 6:
return speed<i_RListing.speed;
default:
return true;
};
}
//Ending of Compare.
};
string NameArray[11],PriceArray[11],BrandArray[11],DispArray[11],PowerArray[11],CategoryArray[11],SpeedArray[11],AcceleArray[11],CylArray[11],ValveArray[11],CoolArray[11],TorqueArray[11],BrakeArray[11],WeightArray[11],InductArray[11],OhcArray[11];
listing bikes[15],sortlist[15];
string SortListings (listing A[] , int n, listing::ParameterType i_Type)
{
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(!A[i].Compare(A[j],i_Type))
std::swap (A[i],A[j]);
}
int main()
{
//Start of data extraction
int i,j,ret;
string input;
ifstream datafile;
datafile.open("Bikes.txt",ios::in);
if(datafile.is_open())
{
for(i=0;i<size;i++)
{
if(datafile.good())
{
getline(datafile,input,'$');
NameArray[i]=input;
bikes[i].name=input;
sortlist[i].name=input;
getline(datafile,input,'$');
PriceArray[i]=input;
bikes[i].price=input;
sortlist[i].price=input;
getline(datafile,input,'$');
BrandArray[i]=input;
bikes[i].brand=input;
sortlist[i].brand=input;
getline(datafile,input,'$');
DispArray[i]=input;
bikes[i].disp=input;
sortlist[i].disp=input;
getline(datafile,input,'$');
PowerArray[i]=input;
bikes[i].power=input;
sortlist[i].power=input;
getline(datafile,input,'$');
CategoryArray[i]=input;
bikes[i].category=input;
sortlist[i].category=input;
getline(datafile,input,'$');
SpeedArray[i]=input;
bikes[i].speed=input;
sortlist[i].speed=input;
getline(datafile,input,'$');
AcceleArray[i]=input;
bikes[i].accel=input;
sortlist[i].accel=input;
getline(datafile,input,'$');
CylArray[i]=input;
bikes[i].cyl=input;
sortlist[i].cyl=input;
getline(datafile,input,'$');
ValveArray[i]=input;
bikes[i].valve=input;
sortlist[i].valve=input;
getline(datafile,input,'$');
CoolArray[i]=input;
bikes[i].cool=input;
sortlist[i].cool=input;
getline(datafile,input,'$');
TorqueArray[i]=input;
bikes[i].torque=input;
sortlist[i].torque=input;
getline(datafile,input,'$');
BrakeArray[i]=input;
bikes[i].brake=input;
sortlist[i].brake=input;
getline(datafile,input,'$');
WeightArray[i]=input;
bikes[i].weight=input;
sortlist[i].weight=input;
getline(datafile,input,'$');
InductArray[i]=input;
bikes[i].induct=input;
sortlist[i].induct=input;
getline(datafile,input,'$');
OhcArray[i]=input;
bikes[i].ohc=input;
sortlist[i].ohc=input;
//Code to test the working of data extraction -
}
}
}
else
cout<<"Bike database could not be accessed. \tThe file Bikes.txt is missing."<<endl;
//End of extraction
//Introduction for the user
cout<<"BIKOPEDIA \n\v";
cout<<"Hello! Welcome to Bikopedia -- the one stop wiki for sportsbikes in India. \n\v";
intro :
cout<<"\nHow would you like the bikes to be listed?\n";
cout<<"(1) By Alphabetical order\n(2) By Category\n(3) By Displacement Size\n(4) By Power\n(5) By Price\n(6) By Top Speed\n(7) By 0-100 Timings\n\n";
cout<<"Enter 'q' to QUIT\n\n";
int x, y;
cin>>input;
stringstream(input) >> x;
if (x < 0 || x > 4)
{cout<<"Please enter a valid option!\n"; goto intro;}
else if (input == "q")
exit(0);
else if (x == 1)
{
//Alphabetical Sort
int yy = 0, y1 = -1;
cout<<"\nBy Alphabetical Order -\n";
for (string xx : NameArray)
{
yy++; y1++;
cout<<"("<<yy<<") "<<xx<<", \b"<<BrandArray[y1]<<"\n";
}
cout<<"\n";
}
else if (x == 2)
//Category Sort
{
SortListings (sortlist , 11 , listing::CATEGORY);
int yy = 0, y1 = -1, i;
cout<<"\nBy Category -\n";
cout<<"\nCRUISERS\nLoud, big and stylish, these bikes are also a fashion statement!\n";
for (i=0;i<1;i++)
{
{yy++; cout<<"("<<yy<<") ";cout<<sortlist[i].name<<", "<<sortlist[i].brand<<"\n";}
}
cout<<"\nNAKED SPORTSBIKES \nAll about muscles and might, these bikes are perfect for some hooliganism on the streets!\n";
for (i=1;i<5;i++)
{
{yy++; cout<<"("<<yy<<") ";cout<<sortlist[i].name<<", "<<sortlist[i].name<<"\n";}
}
cout<<"\nSPORTS TOURERS\nFast, heavy, comfortable and good in a stright line, these bikes are perfect for some high speed touring on the highways!\n";
for (i=5;i<7;i++)
{
{yy++; cout<<"("<<yy<<") ";cout<<sortlist[i].name<<", "<<sortlist[i].name<<"\n";}
}
cout<<"\nSUPER SPORTS\nSwift, focused and elegant, these faired beauties are perfect for the racetracks!\n";
for (i=7;i<11;i++)
{
if (CategoryArray[i] == "SuperSport")
{yy++; cout<<"("<<yy<<") ";cout<<sortlist[i].name<<", "<<sortlist[i].name<<"\n";}
}
}
else if (x == 3)
{
SortListings (sortlist , 11 , listing::DISPLACEMNT);
//Displacement Sort
int yy = 0, y1 = -1;
cout<<"\nBy Displacement Order -\n";
for (string xx : sortlist[i].name)
{
yy++; y1++;
cout<<"("<<yy<<") "<<xx<<", \b"<<sortlist[y1].brand<<"\n";
}
cout<<"\n";
}
|