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

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

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

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

Ответ
 
Опции темы Поиск в этой теме
Старый 13.01.2011, 14:14   #1
AlexRedWolf
Новичок
Джуниор
 
Регистрация: 13.01.2011
Сообщений: 2
По умолчанию Классы на C

Ребят, помогите переписать код.
Тут движение квадрата по синусоиде из верхнего левого угла экрана в нижний правый, а мне необходимо движение полукруга по кромке экрана.
У самого не получается. Постоянно ругается на что-нибудь.

Код:
#include <conio.h>
#include <graphics.h>
#include <iostream.h>
#include <process.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <stdlib.h>
#define pi 3.14

class graphworld
  {int driver,mode,grerror,colb,bkcl;
   char path[80];
   public:
     graphworld();
     void closegraphworld();
  };

graphworld::graphworld()
  {strcpy(path,"c:\\borlandc\\bgi");
   driver=0;
   initgraph(&driver,&mode,path);
   grerror=graphresult();
   if(grerror!=grOk)
     {cout<<"\n Error";
      abort;
     }

   setcolor(2+rand()%15);
   setbkcolor(BLACK);
   cleardevice();
  }

void graphworld::closegraphworld()
     {cleardevice();
      closegraph();
     }
class location
   {protected:
      int x,y;
    public:
      location(int initx,int inity);
      int getx();
      int gety();
   };

location::location(int initx, int inity)
  {x=initx;
   y=inity;
  }

int location::getx()
  {return x;
  }

int location::gety()
  {return y;
  }

class point:public location
  {protected:
     int visible;
     void setvisible(int pr);
   public:
     point(int initx,int inity);
     ~point();
     virtual void show();
     virtual void hide();
     int getvisible();
     void moveto(int nx,int ny);
   };

point::point(int initx,int inity):location(initx,inity)
       {
       }

point::~point()
       {hide();
       }

void point::moveto(int nx,int ny)
     {hide();
      x=nx;
      y=ny;
      show();
     }

void point::setvisible(int pr)
     {visible=pr;
     }

void point::show()
     {putpixel(x,y,getcolor());
      setvisible(1);
     }

void point::hide()
     {putpixel(x,y,getbkcolor());
      setvisible(0);
     }

class pramoug:public point
   {int dx,dy;
    public:
      pramoug(int initx,int inity,int initdx,int initdy);
     ~pramoug();
     void show();
     void hide();
   };

pramoug::pramoug(int initx,int inity,int initdx,int initdy): point(initx,inity)
     {dx=initdx;
      dy=initdy;
     }

void pramoug::show()
     {rectangle(x,y,x+dx,y+dy);
     }

void pramoug::hide()
     {int r;
      setcolor(getbkcolor());
      rectangle(x,y,x+dx,y+dy);
      setcolor(2+rand()%15);
     }

pramoug::~pramoug()
     {hide();
     }

void main(void)
{graphworld world;
 int x = 0,
     y = 0;
 getch();
 cleardevice();
 pramoug pt(x,y,20,20);
 delay(50);
 pt.show();
 do{
	y=sin(x)*55+x*(getmaxy\getmaxx);
	pt.moveto(x,y);
	delay(50);
	x+=6;
	if (y > getmaxy()) x=0;
    }
 while(!(kbhit()));
 getch();
 world.closegraphworld();
}
AlexRedWolf вне форума Ответить с цитированием
Старый 13.01.2011, 14:38   #2
NiCola999
Не
Участник клуба
 
Регистрация: 29.10.2009
Сообщений: 1,456
По умолчанию

дык выкладывайте ошибки

Цитата:
Классы на C
в С нет классов
NiCola999 вне форума Ответить с цитированием
Старый 13.01.2011, 15:54   #3
Matou
 
Регистрация: 12.01.2011
Сообщений: 6
По умолчанию

Я так понимаю ошибок нету, просто человек хочет чтобы за него лабу написали.
Matou вне форума Ответить с цитированием
Старый 13.01.2011, 18:21   #4
AlexRedWolf
Новичок
Джуниор
 
Регистрация: 13.01.2011
Сообщений: 2
По умолчанию

Цитата:
Сообщение от Matou Посмотреть сообщение
Я так понимаю ошибок нету, просто человек хочет чтобы за него лабу написали.
я вообще-то сам стараюсь написать. переписал код, но не могу понять, как сделать полукруг... может круг как-то закрыть квадратом цветом фона?

Код:
#include <conio.h>
#include <graphics.h>
#include <iostream.h>
#include <process.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <stdlib.h>

class graphworld
  {int driver,mode,grerror,colb,bkcl;
   char path[80];
   public:
     graphworld();
     void closegraphworld();
  };

graphworld::graphworld()
  {strcpy(path,"C:\\Dev-Cpp\\include");
   driver=0;
   initgraph(&driver,&mode,path);
   grerror=graphresult();
   if(grerror!=grOk)
     {cout<<"\n Error";
      abort;
     }

   setcolor(2+rand()%15);
   setbkcolor(BLACK);
   cleardevice();
  }

void graphworld::closegraphworld()
     {cleardevice();
      closegraph();
     }

class location
   {protected:
      int x,y;
    public:
      location(int initx,int inity);
      int getx();
      int gety();
   };

location::location(int initx, int inity)
  {x=initx;
   y=inity;
  }

int location::getx()
  {return x;
  }

int location::gety()
  {return y;
  }

class point:public location
  {protected:
     int visible;
     void setvisible(int pr);
   public:
     point(int initx,int inity);
     ~point();
     virtual void show();
     virtual void hide();
     int getvisible();
     void moveto(int nx,int ny);
   };

point::point(int initx,int inity):location(initx,inity)
       {
       }

point::~point()
       {hide();
       }

void point::moveto(int nx,int ny)
     {hide();
      x=nx;
      y=ny;
      show();
     }

void point::setvisible(int pr)
     {visible=pr;
     }

void point::show()
     {putpixel(x,y,getcolor());
      setvisible(1);
     }

void point::hide()
     {putpixel(x,y,getbkcolor());
      setvisible(0);
     }

class krug:public point
   {int dx,dy;
    public:
      krug(int initx,int inity,int initdx,int initdy);
     ~krug();
     void show();
     void hide();
   };

krug::krug(int initx,int inity,int initr): point(initx,inity)
     {r=initr;
     }

void krug::show()
     {
      circle(x,y,r);
     }

void krug::hide()
     {int r;
      setcolor(getbkcolor());
      circle(x,y,r);
      setcolor(2+rand()%15);
     }

krug::~krug()
     {hide();
     }

void main(void)
{graphworld world;
 int x = r,
     y = r;
     r = 30;
 getch();
 cleardevice();
 krug pt(x,y,r);
 delay(50);
 pt.show();
 do {
    setcolor(GREEN);
    for (x=r; x<=getmaxx-r; x++)
    {
        pt.moveTo(x,y);
        delay(50);
    }
    for (y=r; y<=getmaxy-r; y++)
    {
        pt.moveTo(x,y);
        delay(50);
    }
    for (x=getmaxx-r; x>=r; x--)
    {
        pt.moveTo(x,y);
        delay(50);
    }
    for (y=getmaxy-r; y>=r; y--)
    {
        pt.moveTo(x,y);
        delay(50);
    }
    }
 while(!(kbhit()))
 getch();
 world.closegraphworld();
}
AlexRedWolf вне форума Ответить с цитированием
Старый 13.01.2011, 23:11   #5
NiCola999
Не
Участник клуба
 
Регистрация: 29.10.2009
Сообщений: 1,456
По умолчанию

Код:
for(phi = 0; phi < PI; phi += 0.1)
    lineTo( cos(phi), sin(phi) );
NiCola999 вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Классы ymanety Общие вопросы C/C++ 2 09.11.2010 22:13
Классы в Си Defa4ka Помощь студентам 6 01.03.2010 00:57
Классы. MAKEDON Общие вопросы C/C++ 1 24.07.2009 18:35
СИ++ Классы mikl9 Помощь студентам 2 17.06.2009 21:49