Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

DESIGN PROBLEM OF COMPUTING II.

TITLE-CREATE A MAZE PROGRAM TO FIND


OUT PATH.

Submitted to:

Submitted by:

Mr.PAWAN KUMAR

ASHISH DHYANI
MCA(H)
ERNO.10812279
ROLLNO--40

//source code for the maze program is as


follows.
/*

ashish dhyani
e roll. 10812279
rollno --40

*/

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class p
{
private:
char **p,*start,*end;

public:

void getdata();
void showdata(int,int,char**);
p()
{
start=NULL;

end=NULL;
}
};

int check(char **);


void find(char **);
void p :: getdata()
{
int rows,cols;
int init=0,last=0;
cout<<"\n Enter the size of matrix(p) : ";
cout<<"\t";
cout<<"Rows :-";
cin>>rows;
cout<<"\t\n";
cout<<"Cols :- ";
cin>>cols;

*p=(char*)malloc(rows*cols);
cout<<"\n ******user manual *****\n\n user have to
use only four keywords \n\n 1.# at the beginning\n\n 2.1
or 0 in between\n\n 3. @ at the last as destinnation point";
cout<<"wrong keywords will lead to system failure
\n\n***** enter your keywords*******\n\n\t";

for(int i=0;i<rows;i++)
{
for (int j=0;j<cols;j++)
{
cin>>(*(*(p+i)+j));

if((*(*(p+i)+j))=='#')
{
if(init==0)
{
start=&(p[i][j]);
init++;
}
else
{
cout<<endl<<"Sorry !!! you are on
wrong way \n pls try right keywords";
j--;
}
}

else if((*(*(p+i)+j))=='@')

{
if(last==0)
{
end=&(p[i][j]);
last++;
}
else
{
cout<<endl<<"Sorry !!! you are on
wrong way \n pls try right keywords";
j--;
}

else if((*(*(p+i)+j))!='1' && ((*(*(p+i)+j))!


='0') && (*(*(p+i)+j))!='#' && (*(*(p+i)+j))!='@')
{
cout<<endl<<"Sorry !!! you are on
wrong way \n pls try right keywords";
j--;
}
}
}

clrscr();
if(start==NULL || end==NULL)
{
cout<<"source not available.";
}

else
{
cout<<endl<<endl<<"\n\n The required ways of
the maze are.\n";
for(i=0;i<rows;i++)
{
cout<<endl<<endl;
for (int j=0;j<cols;j++)
{
cout<<" "<<*(*(p+i)+j);
}
}
}
showdata(rows,cols,p);
}

void p :: showdata(int m,int n, char **a)

{
int i=0;
int j=0;

if(i==0 && j==0)


a[i][j]=2;

do{

if((i>=0 && j+1>=0 && i<=m-1 && j+1<=n-1 )&& a[i]


[j+1]==0)
{
j++;
a[i][j]=2;

else if((i+1>=0 && j>=0 && i+1<=m-1 && j<=n-1) &&


a[i+1][j]==0)
{i++;
a[i][j]=2;

else
if((i>=0 && j-1>=0 && i<=m-1 && j-1<=n-1) && a[i][j1]==0)
{
j--;
a[i][j]=2;
}

else if((i-1>=0 && j>=0 && i-1<=m-1 && j<=n-1) && a[i-1]
[j]==0)
{
i--;
a[i][j]=2;

else
if((i>=0 && j+1>=0 && i<=m-1 &&j+1<=n-1) && a[i]
[j+1]==2)
{
a[i][j]=3;
j++;
}

else if((i+1>=0 && j>=0 && i+1<=m-1 &&j<=n-1) &&


a[i+1][j]==2)
{
a[i][j]=3;
i++;
}
else if((i>=0 && j-1>=0 && i<=m-1 && j-1<=n-1) && a[i][j1]==2)
{
a[i][j]=3;
j--;
}
else if((i-1>=0 && j>=0 && i-1<=m-1 && j<=n-1) && a[i-1]
[j]==2)
{
a[i][j]=3;

i--;
}
}
while( ( i!=m-1) &&( j!=n-1));
}

void main()
{

p o;
clrscr();
o.getdata();
getch();

You might also like