John Schmidt works as the data entry operator in New York. His daily activity includes assigning vehicle number for the new vehicles that enter the city. The vehicle number has the following format: First two letters represent the state Next one/two letter represent the series number (A to Z and AA to ZZ) Last 5 digits represent the Vehicle number When the vehicle number reached 99999, the next series will start from 00001. As there is a huge amount of vehicle movement now days, he wants to automate the process. Help john to auto generate vehicle numbers given the starting vehicle number.
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
string state, serNum, vehNum, fullNum;
vector<string>v;
int firstLet='A';
int secondLet='A';
bool secLet=false;//indicator to turn on second letter
int num=1;
do
{
//Entering first two letters of state
cout<<"John Schmidt, please, enter two letters of the state (Q-quit): ";
cin>>state;
if(state=="Q")break;
do
{
if(state.size()!=2)
{
cout<<"State must have two letters!\n";
break;
}
else
{
if(num==100000&&(!secLet))//indicator to change first letter
{
num=1;
firstLet++;
}
if(num==100000&&secLet)//indicator to change second letter
{
num=1;
secondLet++;
}
if(secondLet=='[')//indicator of next symbol after Z
{
secondLet='A';
firstLet++;
}
if(firstLet=='[')//indicator of next symbol after Z
{ //and turning on second letter
firstLet='A';
secLet=true;
}
vehNum=to_string(num);
num++;
if(secLet==true)
{
serNum=firstLet;
serNum+=secondLet;
}
else
{
serNum=firstLet;
}
while(vehNum.size()!=5)vehNum='0'+vehNum;//Make 5 digit number
fullNum=state+serNum+vehNum;//Collect whole number
v.push_back(fullNum);//Add new entry to vector
cout<<fullNum<<" entry added\n";
break;
}
}while(state.size()!=2);
}while(state!="Q");
if(!v.empty())
{
cout<<"You are entered this vehicle numbers:\n";
vector<string>::iterator it;
for(it=v.begin();it!=v.end();it++)
{
cout<<*it<<endl;
}
}
}
Comments
Leave a comment