0% found this document useful (0 votes)
11 views4 pages

Practical 6

The document discusses a C++ program that creates and displays an adjacency matrix representing flight distances between cities. The program allows the user to input cities and distances to build the matrix, then displays the matrix. It uses classes, arrays, and string handling functions.

Uploaded by

Anjum Maner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Practical 6

The document discusses a C++ program that creates and displays an adjacency matrix representing flight distances between cities. The program allows the user to input cities and distances to build the matrix, then displays the matrix. It uses classes, arrays, and string handling functions.

Uploaded by

Anjum Maner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Bhumika Alhat- 2163

Practical No. 6

#include<iostream>
#include<string.h>
using namespace std;
class flight
{
public:
int am[10][10];
char city_index[10][10];
flight();
int create();
void display(int
city_count); };
flight::flight()
{
int i,j;
for(i=0;i<10;i++)
{
strcpy(city_index[i],"xx"); }
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
am[i][j]=0; }
}}
int flight::create()
{
int city_count=0,j,si,di,wt;
char s[10],d[10],c;
do
{
cout<<"\n\tEnter Source City : ";
cin>>s;
cout<<"\n\tEnter Destination City : ";
cin>>d;
for(j=0;j<10;j++)
{
if(strcmp(city_index[j],s)==0)
break;
}
if(j==10)
{
strcpy(city_index[city_count],s);
city_count++;
}
for(j=0;j<10;j++)
{
if(strcmp(city_index[j],d)==0)
break;
}
if(j==10)
{
strcpy(city_index[city_count],d);
city_count++;
}
cout<<"\n\t Enter Distance From "<<s<<" And "<<d<<": ";
cin>>wt;

for(j=0;j<10;j++)
{
if(strcmp(city_index[j],s)==0)
si=j;
if(strcmp(city_index[j],d)==0)
di=j;
}
am[si][di]=wt;
cout<<"\n\t Do you want to add more cities.....(y/n) : ";
cin>>c;
}while(c=='y'||c=='Y');
return(city_count);
}
void flight::display(int city_count)
{
int i,j;
cout<<"\n\t Displaying Adjacency Matrix :\n\t";
for(i=0;i<city_count;i++)
cout<<"\t"<<city_index[i];
cout<<"\n";

for(i=0;i<city_count;i++)
{
cout<<"\t"<<city_index[i];
for(j=0;j<city_count;j++)
{
cout<<"\t"<<am[i][j];
}
cout<<"\n";
}}
int main()
{
flight f;
int n,city_count;
char c;
do
{
cout<<"\n\t***** Flight Main Menu *****";
cout<<"\n\t1. Create \n\t2. Adjacency Matrix\n\t3. Exit";
cout<<"\n\t.....Enter your choice : ";
cin>>n;
switch(n)
{
case 1:
city_count=[Link]();
break;
case 2:
[Link](city_count);
break;
case 3:
return 0; }
cout<<"\n\t Do you Want to Continue in Main Menu....(y/n) : ";
cin>>c;
}while(c=='y'||c=='Y');
return 0;
}
Output:
***** Flight Main Menu *****
1. Create
2. Adjacency Matrix
3. Exit
Enter your choice : 1
Enter Source City : Pune
Enter Destination City : Mumbai
Enter Distance From Pune And Mumbai: 150
Do you want to add more cities.....(y/n) : y
Enter Source City : Dhule
Enter Destination City : Jalgone
Enter Distance From Dhule And Jalgone: 200
Do you want to add more cities.....(y/n) : n
Do you Want to Continue in Main Menu....(y/n) : y
***** Flight Main Menu *****
1. Create
2. Adjacency Matrix
3. Exit
.....Enter your choice : 2
Displaying Adjacency Matrix :
Pune Mumbai Dhule Jalgone
Pune 0 150 0 0
Mumbai 0 0 0 0
Dhule 0 0
0 200 Jalgone 0
0 0 0

You might also like