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

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

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

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

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

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

Цитата:
Сообщение от BDA Посмотреть сообщение
Реализацию метода Show() не нужно было удалять.
Код:
void Conus::Show()
{
  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);
}
Спасибо все заработало.
xWoWx вне форума Ответить с цитированием
Старый 18.06.2013, 08:19   #22
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Задам вопрос тут же, что бы новую тему не создавать. как сюда вместо куба конус вписать?
Цитата:
# 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;
int h;
public:
Cylinder(int iCenterX, int iCenterY, int iRadius) :
Figure(iCenterX, iCenterY)
{
Radius = iRadius/1.42;
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 Cube: public Figure
{
private:
int h;
public:
Cube (int iCenterX, int iCenterY, int ih ):
Figure (iCenterX, iCenterY)
{
h = ih;
strcat(s,"Create class Cube \n");
}
//Metod Cube
void ShowF ()
{ int prev_color=getcolor();
setcolor(Color);
line (CenterX-h/1.77, (CenterY+h/7.5), (CenterX+h/3.34), (CenterY+h/5));
line (CenterX+h/3.34, (CenterY+h/5), (CenterX+h/1.77), (CenterY-h/7.5));
line ((CenterX+h/3.34), (CenterY+h/5), (CenterX+h/3.34), CenterY+h/0.83);
line ((CenterX+h/3.34), (CenterY+h/0.83), (CenterX-h/1.77), CenterY+h/0.88);
line ((CenterX+h/3.34), CenterY+h/0.83, (CenterX+h/1.77), (CenterY+h/1.15));
line ((CenterX-h/1.77), CenterY+h/0.88, (CenterX-h/1.77), (CenterY+h/7.5));
line ((CenterX-h/1.77), (CenterY+h/0.88), (CenterX-h/5), (CenterY+h/1.28));
line ((CenterX+h/1.77), (CenterY+h/1.15), (CenterX+h/1.77), (CenterY-h/7.5));
line ((CenterX+h/1.77), (CenterY+h/1.15), (CenterX-h/5), (CenterY+h/1.28));
line ((CenterX-h/5), (CenterY-h/4.7), (CenterX-h/5), (CenterY+h/1.28));
line ((CenterX-h/5), (CenterY-h/4.7), (CenterX+h/1.77), (CenterY-h/7.5));
line ((CenterX-h/5), (CenterY-h/4.7), (CenterX-h/1.77), (CenterY+h/7.5));


setcolor(prev_color);
}
void Hide()
{
int prev_col=getcolor();
Color=getbkcolor();
setcolor(Color);
ShowF();
setcolor(prev_col);
}
void Move(int DeltaX, int DeltaY)
{
CenterX+=DeltaX;
CenterY+=DeltaY;
Color=2;
ShowF();
}


~Cube()
{strcat(s, "Del class Cube \n");};
};

class Comb: virtual public Cylinder, public Cube
{
public:
Comb(int iCenterX, int iCenterY, int xRadius):
Cylinder(iCenterX, iCenterY, xRadius),
Cube(iCenterX, iCenterY, xRadius)
{
Cylinder::SetNewColor(4);
Cube::SetNewColor(2);
strcat(s,"Create class Comb \n");
}

void Show()
{
Cylinder::Show();
Cube::ShowF();
}
void Hide()
{
Cube::Hide();
Cylinder::Hide();
}
void Move(int DeltaX, int DeltaY)
{
Cylinder::Move(DeltaX, DeltaY);
Cube::Move(DeltaX, DeltaY);
}
void SetNewColor(int NewColor)
{
Cylinder::SetNewColor(NewColor);
Cube::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(350,150,100);

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, 09:48   #23
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Вписал в этот код код конуса код цилиндра оставил без изменения. выдали ошибки
Изображения
Тип файла: jpg 12.jpg (166.2 Кб, 143 просмотров)
Вложения
Тип файла: txt CONCIL.txt (3.8 Кб, 151 просмотров)

Последний раз редактировалось xWoWx; 18.06.2013 в 09:51.
xWoWx вне форума Ответить с цитированием
Старый 18.06.2013, 13:49   #24
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Программный код после небольших ихменений выглидит так
Цитата:
# 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/1.42;
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");};
};
//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):
Cylinder(iCenterX, iCenterY, xRadius),
Conus(iCenterX, iCenterY, xRadius)
{
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(350,150,100);

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, 14:44   #25
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,429
По умолчанию

Отвечаю по коду 23 сообщения:
1) на 94 строке закройте код конструктора класса конуса
2) на 96 строке virtual ~Conus()
3) 117 строка - 3 параметра, а нужно 5
4) на 120 строке непонятно откуда взявшийся Cube - замените на Conus (если у него есть подходящий метод)
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
BDA вне форума Ответить с цитированием
Старый 18.06.2013, 14:44   #26
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,429
По умолчанию

<дабл пост>
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )

Последний раз редактировалось BDA; 18.06.2013 в 14:52.
BDA вне форума Ответить с цитированием
Старый 18.06.2013, 17:01   #27
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Цитата:
Сообщение от BDA Посмотреть сообщение
Отвечаю по коду 23 сообщения:
1) на 94 строке закройте код конструктора класса конуса
2) на 96 строке virtual ~Conus()
3) 117 строка - 3 параметра, а нужно 5
4) на 120 строке непонятно откуда взявшийся Cube - замените на Conus (если у него есть подходящий метод)
Заменил, Получилось две ошибки.
# 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(350,150,100,50,60);

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 13.jpg (147.2 Кб, 133 просмотров)
xWoWx вне форума Ответить с цитированием
Старый 18.06.2013, 17:20   #28
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,429
По умолчанию

1 ошибка - скорее всего, virtual ~Conus() (96 строка), нужно убрать лишнюю ';'
2 ошибка - в 162 строке вызов Comb с 5 параметрами, а у него их 6
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
BDA вне форума Ответить с цитированием
Старый 18.06.2013, 17:27   #29
xWoWx
Пользователь
 
Регистрация: 03.04.2012
Сообщений: 34
По умолчанию

Цитата:
Сообщение от BDA Посмотреть сообщение
1 ошибка - скорее всего, virtual ~Conus() (96 строка), нужно убрать лишнюю ';'
2 ошибка - в 162 строке вызов Comb с 5 параметрами, а у него их 6
поправил теперь ошибка в 97 строчке Declaration terminated incorrectly
xWoWx вне форума Ответить с цитированием
Старый 18.06.2013, 17:39   #30
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,429
По умолчанию

Приведите получившийся код.
Не забывайте использовать кнопочку Решетка # для оформления кода.
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
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