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
|
#include <iostream>
#include <ostream>
#include <istream>
#include "GasStation.h"
#include <fstream>
#include <string>
#include <sstream>
#include <list>
using namespace std;
int main (int argc, char* argv[] )
{
/*cout<<argc<<endl;*/
list<Gas_station> lst; // Creates list // Creates list of argc-2 copies of Gas_station() the -2 is because first file is the exe file secound is the simulation and after comes the Stations informaitions.
for( int counter=0,counter_arg_v=1 ; counter< argc-1; counter++,counter_arg_v++ )
{
Gas_station Station1;
lst.push_front(Station1);
//list<T> lst(n, e); // Creates list of n copies of e.
char nameafter[40];
string str98 ("Octan98");
string str95 ("Octan95");
string line ;
ifstream myfile (argv[counter_arg_v]); // open the txt file
if (myfile.is_open())
{
while ( myfile.good() )//scan each row and do the right commands untill the end of the file
{
getline (myfile,line);
if (line[0]!='#')
{
if(line[0]=='S') // to get the station name
{
std::string y;
const std::string::size_type pos = line.find(":"); // after :
if(pos != std::string::npos)
y = line.substr(pos + 1);
strcpy(nameafter,y.c_str());
std::cout<<nameafter<<endl<<endl; // the name of the station got from file
Station1.set_m_station_name(nameafter);//copy the name of the station from the txt file into the object
}
else if(line[0]=='O') // Octan cheak ang get values of price
{
std::string part2;
std::stringstream ss2(line);
std::getline(ss2, part2, ',');
if(part2.compare(str98)==0)
{
std::cout<<"Using "<<str98<<endl;
getline(ss2,part2, ',');
std::cout<<"Full service"<< part2<<endl;
Station1.set_mFull_price(atof(part2.c_str())); //convert the string from string to int and assing
getline(ss2,part2, ',');
std::cout<<"Self service "<<part2<<endl<<endl;
Station1.set_mSelf_price(atof(part2.c_str()));//convert the string from string to int and assing
}
else if(part2.compare(str95)==0)
{
std::cout<<"Using "<<str95<<endl;
getline(ss2,part2, ',');
std::cout<<"Full service"<< part2<<endl;
Station1.set_m_Full_price(atof(part2.c_str()));//convert the string from string to int and assing
getline(ss2,part2, ',');
std::cout<<"Self service "<<part2<<endl<<endl;
Station1.set_m_Self_price(atof(part2.c_str()));//convert the string from string to int and assing
}
else
{
std::cout<<"You enter a wrong fild of Fule , pleas try again"<<endl;
exit(1);
}
}
else //fullers list
{
list<FULER_INFO> lst2; //list of fulers in the station
lst2.push_front(Station1.FULER_info);
std::string part2;
std::stringstream ss2(line);
std::getline(ss2, part2, ',');
std::cout<<"The car number is "<< part2<<endl;
strcpy(Station1.FULER_info.car_id,part2.c_str());// copy the car id to fild
std::getline(ss2, part2, ','); //copy the fuling kind 95/98
std::cout<<"The fuling kind is "<< part2<<endl;
if(part2[0]=='9')
{
if(part2[1]=='5')
Station1.FULER_info.Octan_type=octan95;
}
else if(part2[0]=='9')
{
if ((part2[1])=='8')
Station1.FULER_info.Octan_type=octan98;
}
else
{
cerr<<"You enterd wrong value of fuel"<<endl;
exit(1);
}
std::getline(ss2, part2, ','); // copy the number of liters feuled
std::cout<<"The number of liters is "<< part2<<endl;
Station1.FULER_info.num_of_liteRs=atof(part2.c_str());
std::getline(ss2, part2, ',');
std::cout<<"The fuling type is "<< part2<<endl<<endl;
if(part2[0]=='F') //means full service is used
Station1.FULER_info.SERVICE_TYPE_=FullService;
else if (part2[0]=='S')//means self service is used
Station1.FULER_info.SERVICE_TYPE_=SelfService;
else
{
cout<<"You enter wrong service type"<<endl;
exit(1);
}
} //else //fullers list
} //if (line[0]!='#')
}//while ( myfile.good() )
} //if (myfile.is_open())
else std::cout << "Unable to open file"<<endl;
myfile.close();
std::cout<<lst.size()<<endl;
}//for(...)
return 0;
}//main()
|