Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ graphics oops
i am using turbo c complier for the given code :-
 
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
class hexa
{
    private:
int x,y,pts[12][12],s;
float h,r;
   public:
 
void set(){
cout<<"enter the cordinates";
cin>>x>>y;
cout<<"enter the length of hexagonal";
cin>>s;
}
void disp(){
cout<<x<<y;
cout<<s;
}
 

void Draw()
    {
h = 0.5* s;
r = 0.866*s;
 

 
                pts[0][0] =x; pts[0][1] =y;
                pts[1][0] =x+h; pts[1][1] = y+r;
                pts[2][0] =x; pts[2][1] = y+r;
                pts[3][0] =x-h; pts[3][1] =y+r;
                pts[4][0] =x;  pts[4][1] =y-r;
                pts[5][0] =x-h;   pts[5][1] =y-r;
                pts[6][0] =x+h;  pts[6][1] =y-r;
 

  drawpoly(7,pts[0][0],pts[0][1],pts[1][0],pts[1][1],pts[2][0],pts[2][1],pts[3][0],pts[3][1],pts[4][0],pts[4][1],pts[5][0],pts[5][1],pts[6][0],pts[6][1],pts[0][0],pts[0][1]);
 

 

 
}
};
 
main()
{
hexa c;
 
   int gd=DETECT,gm;
   initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
 
c.set();
c.disp();
c.Draw();
 

   getch();
   closegraph();
   return 0;
 

}
 
and it gives the following errors :-
1)cannot convert int to const int far*
2)type mismatch parameter _polypoints to call a drawpoly(int,const int far)
3)extra parameter in call to drawpoly(int,const int far)
 

am not able to recover errors plz help me .. i'll be thankfull to uh.
Posted 4-Dec-12 5:40am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The function drawpoly takes an int and a int*, not an int and then loads of ints;
 
So instead of;
drawpoly(7,pts[0][0],pts[0][1],pts[1][0],pts[1][1],pts[2][0],pts[2][1],pts[3][0],pts[3][1],pts[4][0],pts[4][1],pts[5][0],pts[5][1],pts[6][0],pts[6][1],pts[0][0],pts[0][1]);
 
I think you should do;
drawpoly(7, pts);
 
as the function expects a count of items and a pointer to them, not each item individually.
 
Hope this helps,
Fredrik
  Permalink  
Comments
garima alreja at 4-Dec-12 12:52pm
   
i did this .. but it again gives errors that cannot convert int[12]* to const int far
infact i did some verification in code :-
#include
#include
#include
class hexa
{
private:
int x,y,pts[12][12],s;
float h,r;
public:
 
void set(){
cout<<"enter the cordinates";
cin>>x>>y;
cout<<"enter the length of hexagonal";
cin>>s;
}
void disp(){
cout<<x<<y;
cout<<s;
}
 

 

 
hexa()
{
h = 0.5* s;
r = 0.866*s;
pts[0][0] =x; pts[0][1] =y;
pts[1][0] =x+h; pts[1][1] = y+r;
pts[2][0] =x; pts[2][1] = y+r;
pts[3][0] =x-h; pts[3][1] =y+r;
pts[4][0] =x; pts[4][1] =y-r;
pts[5][0] =x-h; pts[5][1] =y-r;
pts[6][0] =x+h; pts[6][1] =y-r;
 

drawpoly(7,pts);
 

 

 
}
 

 

};
 
main()
{
hexa c;
 
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
 
c.set();
c.disp();
hexa c;
 

getch();
closegraph();
return 0;
 

}
but it again gives errors . sir please sort this i am not able to do
Fredrik Bornander at 4-Dec-12 13:00pm
   
You can either cast pts; drawpoly(7, reinterpret_cast(pts));
Or declare it as a pointer, int* pts = new int[12*12];
If you go for the pointer declaration, do not forget to delete it.
 
/Fredrik
garima alreja at 4-Dec-12 13:22pm
   
what i dont have to delete ?
and i did int* pts = new int[12*12];
it ask me we cannot initailise class member here
i did following:-
#include
#include
#include
class hexa
{
private:
int x,y,s;
int *pts=new pts[12*12];
float h,r;
public:
 
void set(){
cout<<"enter the cordinates";
cin>>x>>y;
cout<<"enter the length of hexagonal";
cin>>s;
}
void disp(){
cout<<x<<y;
cout<<s;
}
 

 

 
hexa()
{
h = 0.5* s;
r = 0.866*s;
pts[0][0] =x; pts[0][1] =y;
pts[1][0] =x+h; pts[1][1] = y+r;
pts[2][0] =x; pts[2][1] = y+r;
pts[3][0] =x-h; pts[3][1] =y+r;
pts[4][0] =x; pts[4][1] =y-r;
pts[5][0] =x-h; pts[5][1] =y-r;
pts[6][0] =x+h; pts[6][1] =y-r;
 

drawpoly(7,pts);
 

 

 
}
 

 

};
 
main()
{
hexa c;
 
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
 
c.set();
c.disp();
 

 
getch();
closegraph();
return 0;
 

}
garima alreja at 4-Dec-12 13:43pm
   
sir actuaally my project is about draw hexagonal cells
i am trying it hard to give the concept of oops and graphics
i know how to use graphics in c ..
but i have to apply concept of classes..
i am trying from last 1 week to apply . but all the time i am having problem is iniatialisation .. i asked from every teacher every teachers in my collage gives me a diffrent concept to apply .. i made 3-4 programs .. every1 says its correct but uh have iniatialisation problem.. so i tried for onl9 teachers but still i am trying from 12 hrs from many onl9 teachers i am not able to recover errors..
tomarroww i have to submit and have not even made hexagonal cells then i have to colour also them ..
so in a very complicated situation ? need help really ..
garima alreja at 4-Dec-12 13:45pm
   
my project is about :-The Groupe Spécial Mobile (GSM) was created in 1982 to provide a standard for a mobile telephone
system. The first GSM network was launched in 1991 by Radiolinja in Finland with joint technical
infrastructure maintenance from Ericsson. Today, GSM is the most popular standard for mobile
phones in the world, used by over 2 billion people across more than 212 countries. GSM is a cellular
network with its entire geographical range divided into hexagonal cells. Each cell has a
communication tower which connects with mobile phones within the cell. All mobile phones connect
to the GSM network by searching for cells in the immediate vicinity. GSM networks operate in only
four different frequency ranges. Study the cells of a GSM mobile phone network and Model a
software module to assign at most four different frequencies for any GSM mobile phone network..
garima alreja at 4-Dec-12 13:46pm
   
i did this:-#include
#include
#include
class hexa
{
private:
int x,y,
int *pts[12*12],s;
float h,r;
public:
 
void set(){
cout<<"enter the cordinates";
cin>>x>>y;
cout<<"enter the length of hexagonal";
cin>>s;
}
void disp(){
cout<<x<<y;
cout<<s;
}
hexa()
{
h = 0.5* s;
r = 0.866*s;
pts[0][0] =x; pts[0][1] =y;
pts[1][0] =x+h; pts[1][1] = y+r;
pts[2][0] =x; pts[2][1] = y+r;
pts[3][0] =x-h; pts[3][1] =y+r;
pts[4][0] =x; pts[4][1] =y-r;
pts[5][0] =x-h; pts[5][1] =y-r;
pts[6][0] =x+h; pts[6][1] =y-r;
drawpoly(7,pts);
}
};
main()
{
hexa c;
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
c.set();
c.disp();
getch();
closegraph();
return 0;
}
garima alreja at 4-Dec-12 13:47pm
   
i even did this :-include
#include
#include
class hexa
{
int pointr1[14]={30,15,70,15,85,45,70,75,30,75,15,45,30,15};
int pointb[14]={85,105,125,105,140,75,125,45,85,45,70,75,85,105};
int pointg[14]={30,135,70,135,85,105,70,75,30,75,15,105,30,135};
int pointw[14]={85,105,125,105,140,135,125,165,85,165,70,135,85,105};
int pointr2[14]={ 85,-15,125,-15,140,15,125,45,85,45,70,15,85,-15};
int pointw2[14]={140,15,180,15,195,45,180,75,140,75,125,45,140,15};
int pointw3[14]={140,75,180,75,195,105,180,135,140,135,125,105,140,75};
 

 

public:
void draw()
{
 
drawpoly(7, pointr1);
drawpoly(7, pointb);
drawpoly(7, pointg);
drawpoly(7, pointw);
drawpoly(7, pointr2);
drawpoly(7, pointw2);
drawpoly(7, pointw3);
 
};
main()
{
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
hexa h;
h.draw();
 

getch();
closegraph();
return 0;
}
garima alreja at 4-Dec-12 13:48pm
   
i even did this:-
#include
#include
#include
class hexa
{
protected:
int x,y,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
public:
hexa()
{
x1=x;y1=y;
x2=x1+40;y2=y1;
x3=x2+15;y3=y2+15;
x4=x3+15;y4=y3+30;
x5=x4+40;y5=y4;
x6=x5+15;y6=y5+30;
}
void disp()
{
cout<<"THE GSM CELLS ARE AS FOLLOW";
 
}
 
};
class red:public hexa
{
int z,w;
 

int ptr1[14]={x1,b1,c1,e1,f1,a1};
int ptr6[14]={a6,b6,c6,e6,f6,a6};
 

public:
 
red(){
z=30;w=15}
void draw1_poly()
{
drawpoly(7,ptr1);
drawpoly(7,ptr6);
}
void colour1_poly()
{
cout<<setfillsytle(SOLID_FILL,RED);
}
};
class blue:public hexa
{
int a2=(x1=x=85,y1=y=105),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 
int ptr2[14]={a2,b2,c2,e2,f2,a2};
 
void draw2_poly()
{
cout<<drawpoly(7,ptr2);
 
}
void colour2_poly()
{
cout<<setfillsytle(SOLID_FILL,BLUE);
}
};
class green:public hexa
{
int a3=(x1=x=30,y1=y=135),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
int a7=(x1=x=140,y1=y=75),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
int ptr3[14]={a3,b3,c3,e3,f3,a3};
int ptr7[14]={a7,b7,c7,e7,f7,a7};
 
void draw3_poly()
{
cout<<drawpoly(7,ptr3);
cout<<drawpoly(7,ptr7);
}
void colour3_poly()
{
cout<<setfillsytle(SOLID_FILL,GREEN);
}
};
class yellow:public hexa
{
int a4=(x1=x=85,y1=y=105),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
int a5=(x1=x=85,y1=y=-15),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 
int ptr4[14]={a4,b4,c4,e4,f4,a4};
int ptr5[14]={a5,b5,c5,e5,f5,a5};
 

void draw4_poly()
{
 
cout<<drawpoly(7,ptr4);
cout<<drawpoly(7,ptr5);
}
 
void colour4_poly()
{
cout<<setfillsytle(SOLID_FILL,YELLOW);
}
};
main()
{
char colour,red,blue,green,yellow;
 
hexa c;
red c1;
blue c2;
green c3;
yellow c4;
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
 
c.disp();
c.set();
c1.draw1_poly();
c2.draw2_poly();
c3.draw3_poly();
c4.draw4_poly();
 
cout<<"***********************************";
cout<<"enter the colour";
cout<<"***********************************";
cout<<1. red<<endl<<2. blue<<endl<<3. green<<endl<<4. yellow;
 
if (colour==red)
{
c1.colour1_poly();
}
else if(colour==blue)
{
c2.colour2_poly();
}
else if(colour==green)
{
c3.colour3_poly();
{
else (colour==yellow)
{
c4.colour4_poly();
}
getch();
closegraph();
return 0;
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The error messages from the compiler tells you that you are using the drawpoly function incorrectly. The second argument should a reference to a one dimensional array of points.
 
http://www.programmingsimplified.com/c/graphics.h[^]
 
Alan/
  Permalink  
Comments
garima alreja at 4-Dec-12 13:33pm
   
sir actuaally my project is about draw hexagonal cells
i am trying it hard to give the concept of oops and graphics
i know how to use graphics in c ..
but i have to apply concept of classes..
i am trying from last 1 week to apply . but all the time i am having problem is iniatialisation .. i asked from every teacher every teachers in my collage gives me a diffrent concept to apply .. i made 3-4 programs .. every1 says its correct but uh have iniatialisation problem.. so i tried for onl9 teachers but still i am trying from 12 hrs from many onl9 teachers i am not able to recover errors..
tomarroww i have to submit and have not even made hexagonal cells then i have to colour also them ..
so in a very complicated situation ? need help really ..
Alan N at 4-Dec-12 14:18pm
   
Why not start with the example of a simple triangle given in the reference for drawpoly. Once you have that working, modify the code so that it draws a hexagon. Then modify again to colour the hexagon.
 
It's important to go one step at a time when you are learning. That way you will know that any error is due to the last bit of code you changed.
garima alreja at 4-Dec-12 15:00pm
   
i did this help me solving this program
#include
#include
#include
void draw()
{ int pointr1[14]={30,15,70,15,85,45,70,75,30,75,15,45,30,15};
int pointb[14]={85,105,125,105,140,75,125,45,85,45,70,75,85,105};
int pointg1[14]={30,135,70,135,85,105,70,75,30,75,15,105,30,135};
int pointw1[14]={85,105,125,105,140,135,125,165,85,165,70,135,85,105};
int pointw2[14]={ 85,-15,125,-15,140,15,125,45,85,45,70,15,85,-15};
int pointr2[14]={140,15,180,15,195,45,180,75,140,75,125,45,140,15};
int pointg2[14]={140,75,180,75,195,105,180,135,140,135,125,105,140,75};
 
drawpoly(7, pointr1);
drawpoly(7, pointb);
drawpoly(7, pointg1);
drawpoly(7, pointw1);
drawpoly(7, pointw2);
drawpoly(7, pointr2);
drawpoly(7, pointg2);
}
main()
{
int gd=DETECT,gm,pointr1[14],pointb[14],pointg1[14],pointw1[14],pointw2[14],pointr2[14],pointg2[14];
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
cout<<"THE GSM CELLS ARE AS FOLLOW";
cout<<endl;
draw();
char colour,red,blue,green,white;

cout<<"***********************************";
cout<<"enter the colour";
cout<<"***********************************";
cout<<"1. red"<< endl << "2. blue" << endl << "3. green" << endl << "4. white";
switch(colour)
{
case 1:
if(colour==red)
{
fillpoly(4,pointr1);
fillpoly(4,pointr2);
}
break;
case 2:
if(colour==blue)
{
fillpoly(1,pointb);
}
break;
case 3:
if(colour==green)
{
fillpoly(2,pointg1);
fillpoly(2,pointg2);
}
break;
case 4:
if(colour==white)
{
fillpoly(15,pointw1);
fillpoly(15,pointw2);
}
break;
default:
cout<<"given colour doesnot match";
break;
}
getch();
closegraph();
return 0;
}
garima alreja at 4-Dec-12 13:41pm
   
my project is about :-The Groupe Spécial Mobile (GSM) was created in 1982 to provide a standard for a mobile telephone
system. The first GSM network was launched in 1991 by Radiolinja in Finland with joint technical
infrastructure maintenance from Ericsson. Today, GSM is the most popular standard for mobile
phones in the world, used by over 2 billion people across more than 212 countries. GSM is a cellular
network with its entire geographical range divided into hexagonal cells. Each cell has a
communication tower which connects with mobile phones within the cell. All mobile phones connect
to the GSM network by searching for cells in the immediate vicinity. GSM networks operate in only
four different frequency ranges. Study the cells of a GSM mobile phone network and Model a
software module to assign at most four different frequencies for any GSM mobile phone network..
 
i made this:-
#include
#include
#include
class hexa
{
private:
int x,y,
int *pts[12*12],s;
float h,r;
public:
 
void set(){
cout<<"enter the cordinates";
cin>>x>>y;
cout<<"enter the length of hexagonal";
cin>>s;
}
void disp(){
cout<<x<<y;
cout<<s;
}
 

 

 
hexa()
{
h = 0.5* s;
r = 0.866*s;
pts[0][0] =x; pts[0][1] =y;
pts[1][0] =x+h; pts[1][1] = y+r;
pts[2][0] =x; pts[2][1] = y+r;
pts[3][0] =x-h; pts[3][1] =y+r;
pts[4][0] =x; pts[4][1] =y-r;
pts[5][0] =x-h; pts[5][1] =y-r;
pts[6][0] =x+h; pts[6][1] =y-r;
 

drawpoly(7,pts);
 

 

 
}
 

 

};
 
main()
{
hexa c;
 
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
 
c.set();
c.disp();
 

 
getch();
closegraph();
return 0;
 

}
i made this:-
#include
#include
#include
class hexa
{
protected:
int x,y,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
public:
hexa()
{
x1=x;y1=y;
x2=x1+40;y2=y1;
x3=x2+15;y3=y2+15;
x4=x3+15;y4=y3+30;
x5=x4+40;y5=y4;
x6=x5+15;y6=y5+30;
}
void disp()
{
cout<<"THE GSM CELLS ARE AS FOLLOW";
 
}
 
};
class red:public hexa
{
int z,w;
 

int ptr1[14]={x1,b1,c1,e1,f1,a1};
int ptr6[14]={a6,b6,c6,e6,f6,a6};
 

public:
 
red(){
z=30;w=15}
void draw1_poly()
{
drawpoly(7,ptr1);
drawpoly(7,ptr6);
}
void colour1_poly()
{
cout<<setfillsytle(SOLID_FILL,RED);
}
};
class blue:public hexa
{
int a2=(x1=x=85,y1=y=105),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 
int ptr2[14]={a2,b2,c2,e2,f2,a2};
 
void draw2_poly()
{
cout<<drawpoly(7,ptr2);
 
}
void colour2_poly()
{
cout<<setfillsytle(SOLID_FILL,BLUE);
}
};
class green:public hexa
{
int a3=(x1=x=30,y1=y=135),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
int a7=(x1=x=140,y1=y=75),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 

int ptr3[14]={a3,b3,c3,e3,f3,a3};
int ptr7[14]={a7,b7,c7,e7,f7,a7};
 
void draw3_poly()
{
cout<<drawpoly(7,ptr3);
cout<<drawpoly(7,ptr7);
}
void colour3_poly()
{
cout<<setfillsytle(SOLID_FILL,GREEN);
}
};
class yellow:public hexa
{
int a4=(x1=x=85,y1=y=105),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
int a5=(x1=x=85,y1=y=-15),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 
int ptr4[14]={a4,b4,c4,e4,f4,a4};
int ptr5[14]={a5,b5,c5,e5,f5,a5};
 

void draw4_poly()
{
 
cout<<drawpoly(7,ptr4);
cout<<drawpoly(7,ptr5);
}
 
void colour4_poly()
{
cout<<setfillsytle(SOLID_FILL,YELLOW);
}
};
main()
{
char colour,red,blue,green,yellow;
 
hexa c;
red c1;
blue c2;
green c3;
yellow c4;
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
 
c.disp();
c.set();
c1.draw1_poly();
c2.draw2_poly();
c3.draw3_poly();
c4.draw4_poly();
 
cout<<"***********************************";
cout<<"enter the colour";
cout<<"***********************************";
cout<<1. red<<endl<<2. blue<<endl<<3. green<<endl<

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 363
1 OriginalGriff 344
2 George Jonsson 248
3 Shemeemsha RA 138
4 Animesh Datta 130
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 4 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100