Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need to modify this c++ so when the user enter services thats not any of - robbery, violation, medical, fire- it askes the user

i need to modify this c++ so when the user enter services thats not any of - robbery, violation, medical, fire- it askes the user to try again and choose of of them. plz rewrite the whole code with the changes.

#include

#include

#include

#include

#include

#include

using namespace std;

const int size = 5 ;

string services [size]= {"Robbery ", "Violation ", "Medical ","Fire "};//The menu

string search;

string Thesrevice;

struct Info {

string name;

int age;

string location;

string AdditionalNote;

};

void Ask(string &z){// Function for Searching in array

cout<< " Your emergency?";

cout << endl;

cin>> z;

for (int i = 0 ; i< size ; i++){

if (services[i].find(z,0)!= string::npos){

cout<< "Your choice is "<< services[i]<

Thesrevice = services[i];

break;}

}}

void get_data(Info *array,int S){

cout<< "Enter Your name, age, location and any additional note"<

cin>> array[0].name>>array[1].age>>array[2].location>>

array[3].AdditionalNote;

}

int R(){

srand(time(0));

cout <<" "<< "Your code: "<< rand();

}

int gethelp(){

srand(time(0));

return rand()%(10-5+1)+5;

}

int main(){

string temp[size];

string tem;

Info Array [5];

string answer;

string repla;

cout<< " 911 What's your emergency? " ;

cout<< endl;

for(int i = 0; i

cout<< services[i]<<"\t";}

cout<< endl;

cout<< endl;

cout << "Enter your choice as word all small, ex: fire. ";

cout << "To repeate the menu in anoter order inter (other) ";

cout << "To sort the menu alphabetaically inter (abc) ";

Ask(search);

if (search == "other"){ // Shifting -right by 2

int NewIndex;

for (int i=0; i

{ NewIndex=i+2;

if(NewIndex >=size)

NewIndex=NewIndex % size;

temp [NewIndex]= services[i];

;}

cout<< "The new order:"<< endl;

for (int i =0; i

cout<< temp[i]<< "\t";

Ask(search);

}

if (search == "abc"){//Sorting Alphabetically

for (int x = 0; x < size; x++) {

for (int y = x+1; y < size; y++) {

if (services[x]>services [y]){

tem=services [x];

services[x]=services[y];

services[y]=tem;}}}

cout << " Alphabetical order of servisec : ";

for (int x = 0; x < size; x++)

cout << services[x] << "\t";

cout << endl;

Ask(search);}

cout<

cout<<"___________________________________________________ ";

cout<

get_data(Array,5);// Calling Function to get data fron user

cout<<"Okay " << Array[0].name << " calm down, we will send you help ";

cout<< "Your Name: "<<"\t"<< Array[0].name << " ";

cout<< "Your Age: "<<"\t"<< Array[1].age << " ";

cout<< "Your Location: "<<"\t"<< Array[2].location << " ";

cout<< "Additional Note: "<<"\t"<< Array[3].AdditionalNote << "\t";

cout<<" "<<" Please enter 1 if your info are right or 2 if you need to modify";

cin>> answer;

if (answer == "2"){

string Qrep;

string Qrepp;

string rep;

int repp;

int replaa;

cout<<"Do you want to replace? Enter Y or N"<< endl; //Adding value

cin>> Qrep;

if(Qrep == "Y"){

cout << "Is it your age? Enter Y or N"<< endl;

cin >> Qrepp;

if (Qrepp == "Y"){

cout<< "Enter your real age please!"<< endl;

cin>> repp; }

Array[1].age=repp;

}if (Qrepp=="N"){ // Updating values

cout << "Enter your wrong answer ";

cin>> rep;

cout << "Write your replacementt:";

cin>> repla;

if(Array[0].name== rep)

Array[0].name=repla;

if(Array[2].location== rep)

Array[2].location=repla;

if(Array[3].AdditionalNote== rep)

Array[3].AdditionalNote= repla;

}

if (Qrep == "N"){

R();

}

}

cout<<"Okay " << Array[0].name << " Your updated data: ";

cout<< "Your Name: "<<"\t"<< Array[0].name << " ";

cout<< "Your Age: "<<"\t"<< Array[1].age << " ";

cout<< "Your Location: "<<"\t"<< Array[2].location << " ";

cout<< "Additional Note: "<<"\t"<< Array[3].AdditionalNote << "\t"<

int random=gethelp();

cout<<"you will get help within:"<

R();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions