0% found this document useful (0 votes)
22 views

ASS NO 06.cpp

The document defines a class called flight that represents flight data with arrays to store city names and distances between cities. Methods are included to create a flight route by adding cities and display the adjacency matrix representing connections between cities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

ASS NO 06.cpp

The document defines a class called flight that represents flight data with arrays to store city names and distances between cities. Methods are included to create a flight route by adding cities and display the adjacency matrix representing connections between cities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

#include<string.h>
using namespace std;

class flight
{
public:
int am[10][10]; // matrix array for weight
char city_index[10][10]; // array for City name
flight(); //constructor of class
int create();
void display(int city_count);

};

flight::flight() //initializing matrix


{
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) //if source is already
available then break
break; //if both strings are equal
then break the condition
}
if(j==10)
{
strcpy(city_index[city_count],s); // If not presesnt then copy
that source city at current index initially it is 0
city_count++;
}

for(j=0;j<10;j++)
{
if(strcmp(city_index[j],d)==0)
break;
}

if(j==10) // same for


destination
{
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) // 4*4 matrix it will return 4 as 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++) // j is for Row i is for incremeantation
{
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=f.create();
break;
case 2:
f.display(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;
}

You might also like