Answer on Question#38291- Programming, C++
1. Problem:
A salesman travels from one to another state. he may visit either n=2,3,4,5 or 6 cities of punjab.
For every number of cities he may adopt different routes.
Some routes will be longer and other rwill be shorter.
We need to design a C++ Program.
*TO DISPLAY EACH ROUTE FOR PARTICULAR NUMBER OF CITIES "n".
*TO DISPLAY SHORTEST AND LONGEST ROUTE
Hint:
1:Develop a menu using switch
2:Enter the distance using two dimensional array.
I have made the switch menu but i dont know how to do it if anyone can help me out
Solution.
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int dist[6][2] = {0};
cout << "Enter the distance: " << endl;
for (int i = 0; i < 6; i++)
{
cout << "Start: ";
cin >> dist[i][0];
cout << endl << "End: ";
cin >> dist[i][1];
}
int iMenu = 0, n = 0;
cout << "1. Display the route for a particular city" << endl;
cout << "2. Display the shortest and longest route" << endl;
cout << "Enter your choice: ";
cin >> iMenu;
switch (iMenu)
{
case 1:
cout << "Enter the number of cities: ";
cin >> n;
// Code to display route for particular city
break;
case 2:
// Code to display shortest and longest route
break;
default:
cout << "Invalid choice" << endl;
}
return 0;
}
Comments