Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Ошибки в образце
Форум программистов > Системное программирование > C, С++ и С Builder > Общие вопросы по С и С++
Дьяк
Препод дал программу, но я не могу её откомпилировать что бы на её основе составить свою. Ошибок много. Исправьте плиз.
Или я что-то не понимаю объясните (программировать начал 5 дней назад, так что не критикуйте)
Текст первоначального варианта программы с заданными классами
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <graphics.h>
#include <string.h>

// Класс ФИГУРА
class Figure
{
protected:
  int Color;
  int CenterX;
  int CenterY;

public:
  Figure(int iCenterX, int iCenterY)
  {
    Color = RED;
    CenterX = iCenterX;
    CenterY = iCenterY;
  }
  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()
  {};
};

// Класс ОКРУЖНОСТЬ
class Circle: public Figure
{
private:
  int Radius;
public:
  Circle(int iCenterX, int iCenterY, int iRadius) :
    Figure(iCenterX, iCenterY)  
  {
     Radius = iRadius;
  }
  void Show();
};

// Класс ПРЯМОУГОЛЬНИК
class Rectangle: public Figure
{
private:
  int h; // Высота
  int w; // Ширина
public:
  Rectangle(int iCenterX, int iCenterY, int ih, int iw) :
    Figure(iCenterX, iCenterY)
  {
     h = ih;
     w = iw;
  }
  void Show();
};

// Класс СООБЩЕНИЕ
class Message: public Figure
{
private:
  char* String;
public:
  Message(int iCenterX, int iCenterY, char* Msg) :
    Figure(iCenterX, iCenterY)
  {
     String = new char [strlen(Msg)+1];
     strcpy(String, Msg);
  }
  void Show();
  ~Message()
  {
     delete String;
  }
};

// Методы ОКРУЖНОСТИ
void Circle::Show()
{
  int prev_color=getcolor();
  setcolor(Color);
  circle(CenterX, CenterY, Radius);
  setcolor(prev_color);
}

// Методы ПРЯМОУГОЛЬНИКА
void Rectangle::Show()
{
  int prev_color=getcolor();
  setcolor(Color);
  rectangle(CenterX, CenterY, CenterX+w, CenterY+h);
  setcolor(prev_color);
}

// Методы СООБЩЕНИЯ
void Message::Show()
{
  int prev_color=getcolor();
  setcolor(Color);
  outtextxy(CenterX, CenterY, String);
  setcolor(prev_color);
}

// Головная функция
int main()
{
  int gdriver = DETECT, gmode, errorcode;
  initgraph(&gdriver, &gmode,
     "c:\\progra~1\\borlandc\\bgi");
  errorcode = graphresult();
  if (errorcode != grOk)
  {
     cerr<<"Graphics error";
     cerr<<grapherrormsg(errorcode);
     exit(1);
  }

  Circle F1(10,10,10);
  Figure *F2;
  Message F3(0,0, "Hallo!");
  F2 = new Rectangle(0,0,20,20);

  F1.Show();
  F2->Show();
  F3.Show();

  getch();
  int maxcolor = getmaxcolor();
  int direction = 1;
  for (int color = 0; !kbhit(); color++)
  {
     if (color>maxcolor)
       {color=0; direction*=-1;}

     F1.Move(0, 10*direction);
     F1.SetNewColor(color);

     F2->Move(10*direction,0);
     F2->SetNewColor(color);

     F3.Move(10*direction,10*direction);
     F3.SetNewColor(color);

     delay(100);
  }
  F1.Hide();
  F2->Hide();
  F3.Hide();
  delete F2;
  closegraph();
  cout<<"Конец программы";
  return 0;
Дьяк
Разобрался.. Исправил все работает. Ошибка у меня была, не была прописана директория. unsure.gif
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2008 IPS, Inc.