143k views
2 votes
Write a C++ program that displays the tariff charges for reaching different destinations by bus. Show a list of five destinations • Get the input for the destination from the user and depending on that display the fare of destination station • Give a brief description of the chosen destination (Min 5 statements; use numbering) • If the user gives a wrong input, display an error message

1 Answer

3 votes

Answer:

#include <iostream>

#include <map>

using namespace std;

int main(){

map<string, double> destination;

string search;

char isEnd = 'n';

while (isEnd == 'n'){

string dest;

double tarrif;

cout<<"Enter destination: ";

cin>> dest;

cout<<"Enter tarrif: ";

cin>> tarrif;

destination.insert(pair<string, double>(dest, tarrif));

cout<<"Do you want to add more locations? y/n: ";

cin>> isEnd;

}

cout<<"Enter a search term: ";

cin>>search;

auto iter= destination.find(search);

cout<< "The tariff for "<<iter->first<<" is: "<<iter->second;

}

Step-by-step explanation:

The C++ source code provides the input prompt to fill the map data structure "destination". The structure contains data of mapped locations and tariffs. The program also prompts user to search for the tariff of their desired location, if the location is in the map, the tarrif is given else an error message is displayed.

User Nick Kahn
by
9.0k points