## chetan12

please help me for this program... You are working for a company designing cute, funny robot vacuum cleaners. At a high level, the robots’
behavior is divided into three modes:
1. Exploration
2. Vacuuming
3. Rampant Killing
Unfortunately, while consumer testing shows that the last two modes are working perfectly, the exploration
mode still has bugs. You’ve been put in charge of debugging.
At the beginning of the exploration mode, the robot is placed into a convex polygonal room. It has
sensors that should tell it where all the walls are. Your job is to write a program that verifies that these
readings are correct. To do this, the robot needs to physically touch every wall in the room.
Your problem is this: given the shape of a convex polygonal room with N walls and a starting point P
inside it, determine the shortest route that touches each wall and then returns to P. Touching a corner
counts as touching both incident walls.

## happygeek 2,346

Show us your code so we can see how far you have got with your homework assignment and tell us where you are stuck. DaniWeb members are not here to do your homework for you, but will help guide you if you show some effort...

## Suzie999 245

I think it's fine to say, that you are basically looking at the "travelling salesman problem"
Reasearch that.

## chetan12

``````#include<iostream.h>
#include<conio.h>
#include<dos.h>
class robb
{      float rx,x[500],y[500],ry,robx,roby,a,b;
public:
void robot()
{
for(int i=0;i<n;i++)
{
if((rx-x[i])<(rx-x[i+1]))
{
float robx;
robx=x[i];
cout<<"\n robx="<<robx;
}
else if((ry-y[i])<(ry-y[i+1]))
{
float roby;
roby=y[i];
cout<<"\n roby="<<roby;
}
else cout<<"\n not valid co-ordinates";
}
// robx=a,roby=b;
}
float rob()
{
if(robx<roby)
return robx;
else return roby;
}

};
void main()
{        robb b;
int n,i;
float x[500],y[500],area=0;
float elect=5.6,clean=12.3,rx,ry;
float cost=0;
clrscr();
cout<<"\n A mini project on Room Service by a robot";
delay(1000);
cout<<"\n Student Name:  Mane Chetan K.\t\tRoll no:02";
cout<<"\n\t\t Kapase Suwarna H.\tRoll no:01";
delay(2000);
clrscr();
cout<<"\n enter no of co-ordinates you want to enter";
cin>>n;

if(n<=2)
{
cout<<"Cordiantes are invalid"<<endl;
}

else if((n>2) && (n<10))
{
cout<<"\n enter co-ordinates:\n";
for(i=1;i<=n;i++)
{
//   for(int j=1;j<=n;j++)
//{
cout<<"\n enter x-co-ordinate and y-co-ordinate for "<<i<<"\n";
cin>>x[i]>>y[i];
//    }
}
cout<<"\n Enter Robot's location in Room:\n Robo must be in Room\n";
cin>>rx>>ry;

}
// else if(n==3 &&n<9)
{
switch(n)
{
case 3:
cout<<"\n room is triangular";
float th,tb,tc,base=0,height=0 ;
for(i=1;i<=3;i++)
{
tb=x[3]-x[2];
th=y[3]-y[2];
tc=y[2]-y[1];
base=tb;
height=(tc+th)/2;

}
area=0.5*base*height;
cost=area*(2.0*b.rob())*(elect+clean);
cout<<"\n Total Cost for cleaning: "<<cost;
break;
case 4:
float sl,sb;
if(x==y)
{
cout<<"\n room is square";
for(i=1;i<=4;i++)
{
sl=x[4]-x[1];
sb=y[4]-y[2];
}
area=sl*sb;
cost=area*2*b.rob()*elect+clean;
cout<<"\n Total Cost is:"<<cost;
}
else
{
cout<<"\n room is rectangular";
for(i=1;i<=4;i++)
{
sl=x[4]-x[1];
sb=y[4]-y[2];
}
area=sl*sb;
cost=area*2*b.rob()*elect+clean;
cout<<"\n Total Cost is:"<<cost;
}
break;
case 5:
cout<<"\n room is pentagon";
float ab,bc,cd,de,ef;
for(i=1;i<=6;i++)               // pts req for plotting pentagon is 6
{
ab=x[6]-x[5];
bc=x[5]-x[4];
cd=x[4]-x[3];
de=x[3]-x[2];
ef=x[2]-x[1];
}
if(ab==bc==cd==de==ef)
{
area=3.14*5*ab;
cost=area*2*b.rob()*(elect+clean);
cout<<"\n Total cost is:"<<cost;
}
else
{
area=3.14*ab*bc*cd*de*ef;
cost=area*2*b.rob()*(elect+clean);
cout<<"\n Total cost is :"<<cost;
}
break;
case 6:
cout<<"\n room is hexagon";
float ab1,b1c,cd1,d1e,ef1,hf1;
for(i=0;i<=6;i++)
{
ab1=x[6]-x[5];
b1c=x[5]-x[4];
cd1=x[4]-x[3];
d1e=x[3]-x[2];
ef1=x[2]-x[1];
hf1=x[1]-x[0];
}
area=3.14*ab1*b1c*cd1*d1e*ef1*hf1;
cost=area*2*b.rob()*(elect+clean);
cout<<"\n Total cost:"<<cost;
break;
case 7:
float s1s2,s2s3,s3s4,s4s5,s5s6,s6s7,s7s1;
cout<<"\n room has septagonal shape:";
for(i=0;i<=7;i++)
{
s1s2=x[7]-x[6];
s2s3=x[6]-x[5];
s3s4=x[5]-x[4];
s4s5=x[4]-x[3];
s5s6=x[3]-x[2];
s6s7=x[2]-x[1];
s7s1=x[1]-x[0];
}
area=3.14*s1s2*s2s3*s3s4*s4s5*s5s6*s6s7*s7s1;
cost=area*2*b.rob()*(elect+clean);
cout<<"\n Total cost is:"<<cost;
break;
case 8:
cout<<"\n room has octagonal shape";
float o1o2,o2o3,o3o4,o4o5,o5o6,o6o7,o7o8,o8o1;
for(i=0;i<=8;i++)
{
o1o2=x[8]-x[7];
o2o3=x[7]-x[6];
o3o4=x[6]-x[5];
o4o5=x[5]-x[4];
o5o6=x[4]-x[3];
o6o7=x[3]-x[2];
o7o8=x[2]-x[1];
o8o1=x[1]-x[0];
}
area=3.14*o1o2*o2o3*o3o4*o4o5*o5o6*o6o7*o7o8*o8o1;
cost=area*2*b.rob()*(elect+clean);
break;
case 9:
float n1n2,n2n3,n3n4,n4n5,n5n6,n6n7,n7n8,n8n9,n9n1;
cout<<"\n room has nenthagonal shape";
for(i=0;i<=9;i++)
{
n1n2=x[9]-x[8];
n2n3=x[8]-x[7];
n3n4=x[7]-x[6];
n4n5=x[6]-x[5];
n5n6=x[5]-x[4];
n6n7=x[4]-x[3];
n7n8=x[3]-x[2];
n8n9=x[2]-x[1];
n9n1=x[1]-x[0];
}
area=3.14*n1n2*n2n3*n3n4*n4n5*n5n6*n6n7*n7n8*n8n9*n9n1;
cost=area*2*b.rob()*(elect+clean);
cout<<"\n Total cost is:"<<cost;
break;
}
}
if(n>10)
{
float other[500];
cout<<"\n Room has another shape";
for(i=0;i<n;i++)
{
other[i]=x[i+1]-x[i];
}
for(i=0;i<n;i++)
{
area=other[1]*other[i];
}
cost=3.14*area*2*b.rob()*(elect+clean);
}
// else cout<<"\n";
getch();
}
``````

## tinstaafl 1,060

OK, you're getting there. You've got a description of your goal. You've got the code you've developed so far. Now we need a description of the problem(s) in your code that you have trouble fixing.