Answer to Question #270473 in C++ for Amey

Question #270473

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.

1
Expert's answer
2021-11-23T05:28:43-0500
#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;
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS