Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 18.06.2013, 17:44   #31
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Цитата:
Сообщение от BDA Посмотреть сообщение
Приведите получившийся код.
Не забывайте использовать кнопочку Решетка # для оформления кода.
Вот программный код
Код:
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
# include <stdio.h>
# include <dos.h>
# include <graphics.h>
# include <string.h>

char s[255] = "";

//Class Figure
class Figure
{ protected:
    int Color;
    int CenterX;
    int CenterY;
  public:
    Figure (int iCenterX, int iCenterY)
      {
       Color=RED;
       CenterX=iCenterX;
       CenterY=iCenterY;
    strcat(s, "Create class Figure \n");
      }
    void SetNewColor (int NewColor)
      {Hide(); Color=NewColor; Show();}
    virtual void Show () = 0;
    virtual void Hide ()
      {
      int prev_col=Color;
      Color=getbkcolor();
      Show();
      Color=prev_col;
      }
    void Move (int DeltaX, int DeltaY)
	 {
	  Hide();
	  CenterX+=DeltaX;
	  CenterY+=DeltaY;
	  Show();
	 }
    virtual ~Figure()
  {strcat(s, "Del class Figure \n");};
};


// Љ«*бб –€‹€Ќ„ђ
class Cylinder: public Figure
{
private:
  int Radius;//а*¤Ёгб н«ЁЇб* 1
  int h;
public:
  Cylinder(int iCenterX, int iCenterY, int iRadius) :
    Figure(iCenterX, iCenterY)
  {
     Radius = iRadius;
     h = iRadius;
   strcat(s,"Create class Cylinder \n");
  }
  void Show();
    virtual ~Cylinder()
  {strcat(s, "Del class Cylinder \n");};
};

// ЊҐв®¤л –€‹€Ќ„ђЂ
void Cylinder::Show()
{
  int prev_color=getcolor();
  setcolor(Color);
  ellipse(CenterX, CenterY, 0, 360, Radius, Radius/3);
  ellipse(CenterX, CenterY+h, 0, 360, Radius, Radius/3);
  line(CenterX+Radius, CenterY, CenterX+Radius, CenterY+h);
  line(CenterX-Radius, CenterY, CenterX-Radius, CenterY+h);
  setcolor(prev_color);
}


//Class Conus
class Conus: public Figure
  {
     private:
       int xRadius;
       int yRadius;
       int h;
     public:
       Conus (int iCenterX, int iCenterY, int xR, int yR, int ih ):
	 Figure (iCenterX, iCenterY)
	{
       xRadius=xR;
       yRadius=yR;
       h = ih;
	      strcat(s,"Create class Conus \n");
       }
      void ShowF ();
      virtual ~Conus ();
     {strcat(s, "Del class Conus\n")};
      };
//Metod Conus
       void Conus::ShowF ()
       {   int prev_color=getcolor();
	   setcolor(Color);
    ellipse(CenterX,CenterY+h/2,0,360,xRadius,yRadius);
    moveto(CenterX-xRadius,CenterY+h/2);
    linerel(xRadius,-h);
    linerel(xRadius,h);
    setcolor(prev_color);
    }


// Љ«*бб Њ“‹њ’€”€ѓ“ђЂ
class Comb: virtual public Cylinder, public Conus
{
public:
  Comb(int iCenterX, int iCenterY, int xRadius,int xR,int yR,int ih):
	Cylinder(iCenterX, iCenterY, xRadius),
	Conus (iCenterX, iCenterY, xR, yR,  ih )

  {
	Cylinder::SetNewColor(4);
	Conus::SetNewColor(2);
   strcat(s,"Create class Comb \n");
  }

// ЊҐв®¤л Њ“‹њ’€”€ѓ“ђ›
  void Show()
  {
	Cylinder::Show();
	Conus::ShowF();
  }
  void Hide()
  {
	Conus::Hide();
	Cylinder::Hide();
  }
  void Move(int DeltaX, int DeltaY)
  {
	Cylinder::Move(DeltaX, DeltaY);
	Conus::Move(DeltaX, DeltaY);
  }
  void SetNewColor(int NewColor)
  {
	Cylinder::SetNewColor(NewColor);
	Conus::SetNewColor(NewColor);
  }
	~Comb()
  {strcat(s, "Del class Comb \n");};

};


//Main Procedure
int main()
{ int num;
  int gdriver=DETECT, gmode, errorcode;
  initgraph(&gdriver, &gmode, "C:\\BORLANDC\\Bgi");
  errorcode=graphresult();
  if(errorcode!=grOk)
    {cerr<<"Graphics error"; exit(1);}

  Comb * F1;
 F1=new Comb(40,70,50,30,30,10);

  F1->Show();
getch();
  int maxcolor=getmaxcolor();
  int direction=1;
  for (int color=1; !kbhit();color++)
    { if (color>maxcolor)
	{ color=0; direction*=-1;};
    //  F1->SetNewColor(color);
      F1->Move(-10*direction,-5*direction);
      delay(100);
    };
  F1->Hide();
  delete F1;
  closegraph();
  /*‚лў®¤ Ї®б«Ґ¤®ў*⥫м*®бвЁ ўл§®ў®ў Є®*бв\¤Ґбв*/
  cout<<s;
  s[0]='\0';
  getch();
  cout<<"\n  End Program\n  Press any key...";
  getch();
  return 0;
}
xWoWx вне форума Ответить с цитированием
Старый 18.06.2013, 18:08   #32
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,429
По умолчанию

Код:
virtual ~Conus ()
{strcat(s, "Del class Conus\n");};
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
BDA на форуме Ответить с цитированием
Старый 18.06.2013, 18:23   #33
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Цитата:
Сообщение от BDA Посмотреть сообщение
Код:
virtual ~Conus ()
{strcat(s, "Del class Conus\n");};
Спасибо так она заработала. Получился результат. Вопрос, а как зделать так что бы конус был вписан в целиндр?
Код:
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
# include <stdio.h>
# include <dos.h>
# include <graphics.h>
# include <string.h>

char s[255] = "";

//Class Figure
class Figure
{ protected:
    int Color;
    int CenterX;
    int CenterY;
  public:
    Figure (int iCenterX, int iCenterY)
      {
       Color=RED;
       CenterX=iCenterX;
       CenterY=iCenterY;
    strcat(s, "Create class Figure \n");
      }
    void SetNewColor (int NewColor)
      {Hide(); Color=NewColor; Show();}
    virtual void Show () = 0;
    virtual void Hide ()
      {
      int prev_col=Color;
      Color=getbkcolor();
      Show();
      Color=prev_col;
      }
    void Move (int DeltaX, int DeltaY)
	 {
	  Hide();
	  CenterX+=DeltaX;
	  CenterY+=DeltaY;
	  Show();
	 }
    virtual ~Figure()
  {strcat(s, "Del class Figure \n");};
};


// Љ«*бб –€‹€Ќ„ђ
class Cylinder: public Figure
{
private:
  int Radius;//а*¤Ёгб н«ЁЇб* 1
  int h;
public:
  Cylinder(int iCenterX, int iCenterY, int iRadius) :
    Figure(iCenterX, iCenterY)
  {
     Radius = iRadius;
     h = iRadius;
   strcat(s,"Create class Cylinder \n");
  }
  void Show();
    virtual ~Cylinder()
  {strcat(s, "Del class Cylinder \n");};
};

// ЊҐв®¤л –€‹€Ќ„ђЂ
void Cylinder::Show()
{
  int prev_color=getcolor();
  setcolor(Color);
  ellipse(CenterX, CenterY, 0, 360, Radius, Radius/3);
  ellipse(CenterX, CenterY+h, 0, 360, Radius, Radius/3);
  line(CenterX+Radius, CenterY, CenterX+Radius, CenterY+h);
  line(CenterX-Radius, CenterY, CenterX-Radius, CenterY+h);
  setcolor(prev_color);
}


//Class Conus
class Conus: public Figure
  {
     private:
       int xRadius;
       int yRadius;
       int h;
     public:
       Conus (int iCenterX, int iCenterY, int xR, int yR, int ih ):
	 Figure (iCenterX, iCenterY)
	{
       xRadius=xR;
       yRadius=yR;
       h = ih;
	      strcat(s,"Create class Conus \n");
       }
      void ShowF ();
      virtual ~Conus ()
     {strcat(s, "Del class Conus\n");};
      };
//Metod Conus
       void Conus::ShowF ()
       {   int prev_color=getcolor();
	   setcolor(Color);
    ellipse(CenterX,CenterY+h/2,0,360,xRadius,yRadius);
    moveto(CenterX-xRadius,CenterY+h/2);
    linerel(xRadius,-h);
    linerel(xRadius,h);
    setcolor(prev_color);
    }


// Љ«*бб Њ“‹њ’€”€ѓ“ђЂ
class Comb: virtual public Cylinder, public Conus
{
public:
  Comb(int iCenterX, int iCenterY, int xRadius,int xR,int yR,int ih):
	Cylinder(iCenterX, iCenterY, xRadius),
	Conus (iCenterX, iCenterY, xR, yR,  ih )

  {
	Cylinder::SetNewColor(4);
	Conus::SetNewColor(2);
   strcat(s,"Create class Comb \n");
  }

// ЊҐв®¤л Њ“‹њ’€”€ѓ“ђ›
  void Show()
  {
	Cylinder::Show();
	Conus::ShowF();
  }
  void Hide()
  {
	Conus::Hide();
	Cylinder::Hide();
  }
  void Move(int DeltaX, int DeltaY)
  {
	Cylinder::Move(DeltaX, DeltaY);
	Conus::Move(DeltaX, DeltaY);
  }
  void SetNewColor(int NewColor)
  {
	Cylinder::SetNewColor(NewColor);
	Conus::SetNewColor(NewColor);
  }
	~Comb()
  {strcat(s, "Del class Comb \n");};

};


//Main Procedure
int main()
{ int num;
  int gdriver=DETECT, gmode, errorcode;
  initgraph(&gdriver, &gmode, "C:\\BORLANDC\\Bgi");
  errorcode=graphresult();
  if(errorcode!=grOk)
    {cerr<<"Graphics error"; exit(1);}

  Comb * F1;
 F1=new Comb(40,70,50,30,30,10);

  F1->Show();
getch();
  int maxcolor=getmaxcolor();
  int direction=1;
  for (int color=1; !kbhit();color++)
    { if (color>maxcolor)
	{ color=0; direction*=-1;};
    //  F1->SetNewColor(color);
      F1->Move(-10*direction,-5*direction);
      delay(100);
    };
  F1->Hide();
  delete F1;
  closegraph();
  /*‚лў®¤ Ї®б«Ґ¤®ў*⥫м*®бвЁ ўл§®ў®ў Є®*бв\¤Ґбв*/
  cout<<s;
  s[0]='\0';
  getch();
  cout<<"\n  End Program\n  Press any key...";
  getch();
  return 0;
}
Изображения
Тип файла: jpg 14.jpg (79.6 Кб, 120 просмотров)
xWoWx вне форума Ответить с цитированием
Старый 18.06.2013, 19:11   #34
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,429
По умолчанию

На этот вопрос я не могу ответить, так для него нужно разбираться в коде, что мне совершенно не хочется делать.
Поиграйте с параметрами создания Comb, чтобы понять, как они взаимосвязаны.
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
BDA на форуме Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
написание программы в С++ 1apre Помощь студентам 0 13.04.2013 15:21
Написание программы Bond21 Фриланс 3 07.03.2012 16:05
Написание программы. AllowFrosty Софт 6 23.02.2012 11:00
Написание программы Dj Troy Общие вопросы C/C++ 1 17.04.2011 16:19