PLZ试着帮我制作程序!!! [英] plz try to help in making me program !!!

查看:131
本文介绍了PLZ试着帮我制作程序!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GroupeSpécialMobile(GSM)成立于1982年,旨在为移动电话提供一个标准的
系统。第一个GSM网络由芬兰Radiolinja于1991年推出,由爱立信提供联合技术

基础设施维护。如今,GSM是全球最受欢迎的移动电话标准,超过212个国家的超过20亿人使用。 GSM是一个蜂窝网络,其整个地理范围分为六角形小区。每个小区都有一个

通信塔,它与小区内的移动电话相连。通过搜索附近的小区,所有移动电话都将
连接到GSM网络。 GSM网络仅在四个不同的频率范围内运行。研究GSM移动电话网络的小区和模型a / b
软件模块,为任何GSM移动电话网络分配最多四种不同的频率。





看到我尝试过的东西请检查它的确定与否......请帮助我恢复错误: -

代码: -

  #include   <   iostream.h  >  
#include < conio.h >
#include < graphics.h >
class hexa
{
protected
int x,y,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
public
void set()
{
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<< GSM CELLS如下:;

}

};
class red: public hexa
{
int a1 =(x1 = x = 30 ,y1 = y = 15 < /跨度>),B1 =(X2,Y2),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(X6,Y6);
int a6 =(x1 = x = 140 ,y1 = y = 15 ),B1 =(X2,Y2),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(X6, Y6);
int ptr1 [ 14 ] = {a1,b1,c1,e1,f1,a1 };
int ptr6 [ 14 ] = {a6,b6,c6,e6,f6,a6 };


public
void draw1_poly()
{
cout<< drawpoly( 7 ,ptr1);
cout<< 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),C =(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),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(X6,Y6);
int a7 =(x1 = x = 140 ,y1 = y = 75 ),B1 =(X2,Y2),C =(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 黄色: public hexa
{
int a4 =(x1 = x = 85 ,y1 = y = 105 < /跨度>),B1 =(X2,Y2),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(X6,Y6);
int a5 =(x1 = x = 85 ,y1 = y = - 15 ),B1 =(X2,Y2),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(5233 ,Y6);

int ptr4 [ 14 ] = {a4,b4,c4,e4 ,F4,A4};
int ptr5 [ 14 ] = {a5,b5,c5,e5,f5,a5 };


void draw4_poly()
{

cout<< drawpoly(< span class =code-digit> 7
,ptr4);
cout<< drawpoly( 7 ,ptr5);
}

void colour4_poly()
{
cout<< setfillsytle(SOLID_FILL,YELLOW) ;
}
};
main()
{
char 颜色,红色,蓝色,绿色,黄色;

hexa c;
red c1;
blue c2;
green c3;
黄色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<< 输入颜色;
cout<< ***************** ******************;
cout<< 1。红色和LT;< ENDL<&2。蓝色<< ENDL<< 3。绿色<< ENDL<< 4。黄色;

if (color == red)
{
c1.colour1_poly();
}
其他 if (color == blue)
{
c2.colour2_poly();
}
其他 if (color == green)
{
c3.colour3_poly();
{
else (color == yellow)
{
c4.colour4_poly();
}

getch();
closegraph();
return 0 ;


}

解决方案

这是四种颜色定理的实例,isn''是吗?



从这里开始: http://en.wikipedia。 org / wiki / Graph_coloring [ ^ ]

  class 黄色: 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),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(5233 ,Y6);

int ptr4 [ 14 ] = {a4,b4,c4,e4 ,F4,A4};
int ptr5 [ 14 ] = {a5,b5,c5,e5,f5,a5 };



这些赋值在C ++中都不正确。您不能在类声明中初始化类的成员变量。一点都没!甚至不是常数。



从逻辑上思考:你试图做的是等于说对于这个类的每个实例,成员变量应该初始化为这个。或者更重要的一个例子:int类型的每个变量都应该初始化为85。虽然有可能出现这种情况,但C / C ++并没有这样做。只有在声明或实例化之后才初始化给定类型的变量:

  int  a = < span class =code-digit> 85 ; 



这里你已经声明了一个类型 int的变量,并且该变量(并且只有那个变量)初始化为85.那没关系。



对于课程,它更多一点复杂,但为了帮助您初始化类的实例,您有构造函数。这些是应该用来初始化变量的函数。



如果你不知道构造函数是什么,或者它们是如何被使用的,你真的必须阅读在他们身上,这简直太难以在简短的回答中解释。 E. g。你可以从这里开始: http://www.cplusplus.com/doc/tutorial/classes/ [< a href =http://www.cplusplus.com/doc/tutorial/classes/target =_ blanktitle =New Window> ^ ]



PS:还有另一个大问题:你用红色,蓝色等名称声明了类,然后你声明了同名的变量!请注意,类名是typename:您所做的与写作相同

  int  < span class =code-keyword> int ; 



猜猜:那是'错误!


除了我决定单独发布的初始化之外,还有很多错误(e),糟糕设计(d)和可能的语义错误(



(d)类 hexa :成员变量几乎总是 private ,不受保护!只有方法受保护公共



(s)方法 hexa :: set():当你的代码编译时,如果编译器有任何好处,它应该发出警告,说 x y 未经初始化即被使用。然后,它可能不会,因为它们不是局部变量。虽然有可能在调用set之前在别处初始化它们,但将x和y的值作为函数参数传递会更安全,更清晰!



此外,您指定的x和y值构成奇数模式,根本不是十六进制,它是一条倾斜的S形曲线。



(d)函数 hexa :: disp()与类hexa没有任何关系。为什么它被定义为hexa中的方法?



(d)类 red 派生自基类, hexa 。但是,hexa中没有定义虚函数。这意味着没有可以覆盖的功能,因此没有继承的理由。当几个类共享一个共同的行为时使用继承,并且行为通过方法而不是成员变量表示。



如果你的意图是分享坐标,那么包含一个类型为hexa的成员变量而不是继承它!



(e,d,s)

  int  a1 =(x1 = x =  30 ,y1 = y =  15 ),B1 =(X2,Y2),C =(X3,Y3),D1 =(X4,Y4),E1 =(X5,Y5),F1 =(X6,Y6); 



哎哟!现在,这一行有很多错误,很难理解你的意图:

1.表达式的值(A,B)总是 A 。如果它是一个表达式,编译器将评估 A ,如果它是一个表达式,它可以评估 B 。无论如何,如果你指定那个表达式, B 是无关紧要的,因为结果总是 A



鉴于此,使用此语法仅在一些非常罕见的特定情况下才有意义。更有可能的是,你想要的东西完全不同,这不是你想要的。



2.值 x,y,x1,y1 ,等,不存在。不管怎样,还没有。这些变量是类型 hexa 的成员变量,并且访问存储在其中的的唯一方法是创建该类型的实例!此代码放在类的声明中。类声明就像一个蓝图:每次需要这个类的实例时,都使用类名作为类型,运行时系统将根据声明创建一个对象。



(s,e)以下几行肯定没有达到你的预期:

  int  ptr1 [ 14 ] = {a1,b1,c1,e1,f1,a1}; 



它的作用是定义一个足以包含14个int值的数组,并使用int变量a1到f1和a1的值初始化前7个值。



或者更确切地说,如果将a1到f1定义为常数,它们就是这样!你不能用一个只能在运行时知道的值初始化任何变量,所以这是另一个初始化错误的情况!



从前面的行判断,你的意图是什么是要分配给该数组的7个值的数组。为此,您需要14个单独的变量,或者每个变量需要7个2个变量的数组。然后,生成的数组可以是您在此处定义的14个值的简单数组,也可以是2x7元素的二维数组。由于您使用该数组作为函数 draw_poly()的参数,您需要哪种形式取决于该函数(您在代码中没有包含该函数) 。



(d)函数 draw1_poly() draw2_poly()等等完全彻底地忽略了面向对象编程的概念。更重要的是,这些功能可以利用你的课程,否则根本没有理由存在。但是你有机会。



此外,没有理由使用不同的名称:无论你是否使用类层次结构,你都可以对这些函数使用相同的名称,因为它们的全名(编译器内部使用)也隐含地包括类名。



另一方面,那是什么函数 draw_poly()你在那里使用?



(e?)行

  char 颜色,红色,蓝色,绿色,黄色; 



使用您已经用于类的相同名称定义变量。我不确定这实际上是合法的(即被编译器接受),但至少,它非常非常混乱并且是一个巨大的错误来源。 不要这样做!您应该为变量和类型/类使用不同的名称。当我说不同的时候,我不仅仅意味着使用小写/大写(因为C ++区分大小写,实际上可以工作) - 使用真正不同的名称,你不会因为一个简单的拼写错误而误认为另一个。< br $> b $ b

(e,s)

 cout<< 1。红色和LT;< ENDL<&2。蓝色<< ENDL<< 3。绿色<< ENDL<< 4。黄色; 



您省略了引号。

但更糟糕的是,在该行之后您省略了读取响应,因此值变量 color 未定义。


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.

[edit note="from OP''s comment"]
see i tried something please check its ok or not .. and please help me to recover errors :-
code:-

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
class hexa
{
protected:
int x,y,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
public:
void set()
{
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 a1=(x1=x=30,y1=y=15),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 int a6=(x1=x=140,y1=y=15),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);
 int ptr1[14]={a1,b1,c1,e1,f1,a1};
 int ptr6[14]={a6,b6,c6,e6,f6,a6};


public:
void draw1_poly()
  {
 cout<<drawpoly(7,ptr1);
 cout<<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;


}

解决方案

This is an instance of the four colours theorem, isn''t it ?

Start here: http://en.wikipedia.org/wiki/Graph_coloring[^]


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};


None of these assignments are correct in C++. You cannot initialize member variables of a class in the class declaration. At all! Not even constants.

Think about it logically: what you were trying to do is equivalen to saying "for every instance of this class, the member variables should be intialized like this". Or an example more to the point: "every variable of type int should be initialized to 85". While there may be cases where this makes sense, C/C++ doesn''t work that way. You initialize a variable of a given type only after you declare or instantiate it:

int a = 85;


here you''ve declared a variable of the type int, and that variable (and only that variable) is intialized to 85. That''s fine.

For classes, it is a bit more complex, but to help you initialize an instance of a class, you have constructors. These are the functions that should be used to initialize your variables.

If you don''t know what constructors are, or how they are used, you really must read up on them, that is simply too much to explain in a short answer. E. g. you could start here: http://www.cplusplus.com/doc/tutorial/classes/[^]

P.S.: there is another huge issue: You declared classes with the names red, blue, etc., and then you declared variables of the same name! Note that a class name is a typename: what you were doing is the same as writing

int int;


Guess what: that''s an error!


There are so many errors (e), cases of bad design (d), and probable semantic errors (s) in addition to the initialization that I decided to make a separate posting:

(d) class hexa: member variables should almost always be private, not protected! Only methods should be protected or public.

(s) method hexa::set(): while your code will compile, if your compiler is any good, it should issue a warning, saying that x and y are used without being initialized. Then again, it may not because they are not local variables. While it is possible that you initialize them elsewhere before calling set, it would be much safer and clearer to pass the values for x and y as function arguments!

Also, the x and y values you assign make an odd pattern, that is not a hex at all, it is a slanted S-shaped curve..

(d) the function hexa::disp() has nothing at all to do with the class hexa. Why is it defined as a method in hexa?

(d) class red is derived from the base class, hexa. However, there are no virtual functions defined in hexa. That means there is no function you can override, and therefore no reason for inheritance. Inheritance is used when several classes share a common behaviour, and behaviour is expressed through methods, not member variables.

If your intention was to share the coordinates, then include a member variable of type hexa rather than inheriting from it!

(e,d,s)

int a1=(x1=x=30,y1=y=15),b1=(x2,y2),c1=(x3,y3),d1=(x4,y4),e1=(x5,y5),f1=(x6,y6);


Ouch! Now, that single line has so many errors in it it''s hard to understand what your intention was:
1. the value of the expression (A,B) is always A. The compiler will evaluate A if it is an expression, and it may evaluate B if it is an expression. Anyway, if you assign that expression, B is irrelevant, as the result is always A.

Given that, using this syntax only makes sense in some very rare, specific cases. More likely, you intended something completely different, and this is not what you wanted.

2. The values x, y, x1, y1, etc., do not exist. Not yet, anyway. These variables are member variables of the type hexa, and the only way to access the values stored therein, is create an instance of that type! This code is placed within the declaration of the class. The class declaration is like a blueprint: every time you need an instance of this class, you use the class name as the type, and the runtime system will then create an object according to the declaration.

(s,e) The following line almost certainly does not do what you expect:

int ptr1[14]={a1,b1,c1,e1,f1,a1};


What it does is define an array big enough to contain 14 int values, and the first 7 values are initialized with the values of the int variables a1 through f1 and a1.

Or, rather, they would be, if a1 through f1 were defined as constants! You cannot initialize any variable with a value that can only be known at runtime, so here is another case of initialization error!

Judging by the preceding lines, what you intended is an array of 7 pairs of values to be assigned to this array. For that purpose, you either need 14 individual variables, or 7 arrays of 2 variables each. The resulting array can then either be a simple array for 14 values as you defined it here, or a two-dimensional array for 2x7 elements. Since you are using that array as an argument to the function draw_poly(), which form you need depends on that function (you didn''t include that function in your code).

(d) The functions draw1_poly(), draw2_poly(), etc. completely and utterly ignore the concepts of object oriented programming. Even more, these functions could take advantage of your hierarchie of classes, that otherwise has no reason to exist at all. But you forwent that opportunity.

Besides, there is no reason at all to use different names: no matter whether you do or do not use a class hierarchy, you can use the same name for these functions, as their full name (that the compiler internally uses) implicitely includes the class name as well.

On another note, what is that function draw_poly() you are using there?

(e?) The line

char colour,red,blue,green,yellow;


defines variables using the same names you already used for your classes. I am not sure this is in fact legal (i. e. accepted by the compiler), but at the very least, it is very, very confusing and a huge source of errors. Do not do this! You should use different names for variables and types/classes. And when I say different, I don''t just mean using lowercase/uppercase (as C++ is case sensitive, that would actually work) - use really different names that you can''t accidentally mistake for another with a simple typo.

(e,s)

cout<<1. red<<endl<<2. blue<<endl<<3. green<<endl<<4. yellow;


You omitted the quotation marks.
But what''s worse, after that line you omitted reading the response, so the value of the variable colour is undefined.


这篇关于PLZ试着帮我制作程序!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆