ASS NO 06.cpp
ASS NO 06.cpp
#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);
};
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;
}
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;
}