|
|
Регистрация Восстановить пароль |
Повторная активизация e-mail |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
Опции темы | Поиск в этой теме |
19.03.2019, 20:09 | #1 |
Новичок
Джуниор
Регистрация: 19.03.2019
Сообщений: 1
|
Наследование классов от точки до антипризмы c++
Добрый день! Нужна помощь. Не получается отрисовать антипризму. Одно основание квадратное рисую методом drawpoly, из библиотеки graphics.h, а второе просто не отображается. Помогите исправить код.
Работаю в Borland C++ ......Код....... #include <graphics.h> #include <iostream.h> #include <conio.h> #include <math.h> #include <dos.h> class Point // объявление класса Point { protected: int X; int Y; int Color; public: Point(int, int, int); int GetX(); int GetY(); int GetC(); void PutX(int); void PutY(int); void PutColor(int); void Show(); void Hide(); void MoveTo(int, int); }; class Line: public Point //Класс Линия { protected: int Length; double Fi; public: Line(int, int, int, int, double); int GetLength(); void PutLength(int); void PutFi(double); void Draw(); void Clean(); void Move(int, int); void GoLength(int); void GetSpin(double); }; class Square: public Line //класс Квадрат { public: Square(int, int, int, int, double); void Draw(); void Clean(); void Move(int, int); void ChangeSize(int); void Rotate(double); int GetSquare(); }; class AntiP: public Square { protected: int h; public: AntiP(int,int,int,int,double, int); void PutH(int); int GetH(); void DrawP(); void Clean(); int GetV(); }; Point:: Point(int X, int Y, int Color) { this -> X=X; this -> Y=Y; this -> Color=Color; } int Point ::GetX() { return (X); } int Point ::GetY() { return (Y); } int Point ::GetC() { return (Color); } void Point ::PutX(int X) { this -> X=X; } void Point ::PutY(int Y) { this -> Y=Y; } void Point ::PutColor(int Color) { this -> Color=Color; } void Point:: Show() { putpixel(X, Y, Color); } void Point:: Hide() { putpixel(X,Y, getbkcolor()); } void Point ::MoveTo(int X, int Y) { Hide(); PutX(X); PutY(Y); Show(); } Line:: Line(int X, int Y, int Color, int Length, double Fi): Point(X, Y, Color) { this -> Length = Length; this -> Fi = Fi; } int Line ::GetLength() { return (Length); } void Line :: PutFi(double Fi) {this -> Fi = Fi;} void Line ::PutLength(int Length) { this -> Length=Length; } void Line:: Draw() { int TempColor; int X1, Y1, X2, Y2; int R = Length /2; TempColor=getcolor(); setcolor(Color); X1 = X + R * sin(Fi); Y1 = Y - R * cos(Fi); X2 = X + R * sin(Fi + M_PI); Y2 = Y - R * cos(Fi + M_PI); line(X1,Y1,X2,Y2); setcolor(TempColor); } void Line:: Clean() { int TempColor; TempColor=GetC(); PutColor(getbkcolor()); Draw(); PutColor(TempColor); } void Line:: Move(int X, int Y) { Clean(); PutX(X); PutY(Y); Draw(); } void Line:: GoLength(int NL){ Clean(); PutLength(NL); Draw(); } void Line :: GetSpin(double DFi){ Clean(); PutFi(Fi + DFi); Draw(); } Square:: Square (int X, int Y, int Color, int Length, double Fi): Line (X, Y, Color, Length, Fi){} void Square:: Draw() { int TempColor; TempColor=getcolor(); setcolor(Color); int Len = GetLength(); int X1, Y1, X2, Y2; int X3, Y3, X4, Y4; int R = (Len * sqrt(2))/2; X1 = X + R * sin(Fi); Y1 = Y - R * cos(Fi); X2 = X + R * sin(Fi + M_PI_2); Y2 = Y - R * cos(Fi + M_PI_2); X3 = X + R * sin(Fi + M_PI); Y3 = Y - R * cos(Fi + M_PI); X4 = X + R * sin(Fi + 3*M_PI_2); Y4 = Y - R * cos(Fi + 3*M_PI_2); line (X1,Y1,X2,Y2); line(X2,Y2,X3,Y3); line(X3,Y3,X4,Y4); line(X4,Y4,X1,Y1); setcolor(TempColor); } void Square:: Clean() { int TempColor; TempColor=GetC(); PutColor(getbkcolor()); Draw(); PutColor(TempColor); } void Square:: Move(int X, int Y) { Clean(); PutX(X); PutY(Y); Draw(); } void Square:: ChangeSize(int NS){ Clean(); PutLength(NS); Draw(); } void Square :: Rotate(double Dfi){ Clean(); PutFi(Fi+Dfi); Draw(); } int Square::GetSquare(){return (Length * Length);} AntiP::AntiP (int X, int Y, int Color, int Length, double Fi, int h): Square (X,Y,Color,Length,Fi) {this -> h = h;} void AntiP :: PutH(int h) {this -> h = h;} void AntiP:: DrawP() { int TempColor; TempColor=getcolor(); setcolor(Color); int Len = GetLength(); int X1, Y1, X2, Y2, X3, Y3, X4, Y4; int X5, Y5, X6, Y6, X7, Y7, X8, Y8; int R = (Len * sqrt(2))/2; X1 = X + R * sin(Fi); Y1 = Y - R * cos(Fi); X2 = X + R * sin(Fi + M_PI_2); Y2 = Y - R * cos(Fi + M_PI_2); X3 = X + R * sin(Fi + M_PI); Y3 = Y - R * cos(Fi + M_PI); X4 = X + R * sin(Fi + 3*M_PI_2); Y4 = Y - R * cos(Fi + 3*M_PI_2); X5 = X + R * sin(Fi); Y5 = (Y - h) - R * cos(Fi); X6 = X + R * sin(Fi + M_PI_2); Y6 = (Y - h) - R * cos(Fi + M_PI_2); X7 = X + R * sin(Fi + M_PI); Y7 = (Y - h) - R * cos(Fi + M_PI); X8 = X + R * sin(Fi + 3*M_PI_2); Y8 = (Y - h) - R * cos(Fi + 3*M_PI_2); int poly[10]; poly[0] = X1; poly[1] = Y1; poly[2] = X2; poly[3] = Y2; poly[4] = X3; poly[5] = Y3; poly[6] = X4; poly[7] = Y4; poly[8] = poly[0]; poly[9] = poly[1]; drawpoly(5,poly); int polyh[10]; polyh[0] = X5; polyh[1] = Y5; polyh[2] = X6; polyh[3] = Y6; polyh[4]= X7; polyh[5]= Y7; polyh[6]= X8; polyh[7]= Y8; polyh[8]=polyh[0]; polyh[9]=polyh[1]; drawpoly(5, polyh); setcolor(TempColor); } void AntiP:: Clean() { int TempColor; TempColor=GetC(); PutColor(getbkcolor()); Draw(); PutColor(TempColor); } int AntiP :: GetH(){return h;} int main() { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, "//tc//bgi"); errorcode = graphresult(); if (errorcode != grOk){ cout<< "Graphics error: "<< grapherrormsg(errorcode)<<endl; cout<<"Press ay key to halt:"<<endl; getch(); return(1); } setcolor(getmaxcolor()); Point P1(100,100, getcolor()); // создание объекта P1 класса Point P1.Show(); getch(); P1.MoveTo(150,150); getch(); P1.Hide(); Point P2 = Point(200,200,5); // создание объекта P2 класса Point P2.Show(); getch(); P2.Hide(); P2.PutX(360); P2.Show(); getch(); P2.Hide(); P2.PutY(250); P2.Show(); getch(); P2.Hide(); Line L1(295,100,12,100,90),L2(150,250,13 ,200, 90); // объекты C1 и C2 класса Line L1.Draw(); getch(); L1.Clean(); getch(); L2.Draw(); getch(); L2.Clean(); L2.PutX(360); L2.Draw(); getch(); L2.Move(400,300); getch(); L2.Clean(); getch(); L2.GoLength(100); L2.Draw();getch(); while(!kbhit()){ L2.GetSpin(0.1); delay(10); } L2.Clean(); Square S1(15, 15, 12, 20, 45), S2(120, 120, 13, 40, 45); S1.Draw(); getch(); S1.Clean(); getch(); S2.Draw(); getch(); S2.Clean(); S2.PutX(360); S2.Draw(); getch(); S2.Move(400,300); getch(); S2.Clean(); getch(); S2.ChangeSize(100); S2.Draw();getch(); while (!kbhit()){ S2.Rotate(0.5); delay(100); } S2.Clean();getch; AntiP A1 (350,350, 12, 40, 0, 200); A1.DrawP(); getch(); A1.Clean(); getch(); closegraph(); return(0); }; |
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
Наследование классов С++ | Dima_999 | Помощь студентам | 2 | 26.10.2017 18:49 |
Наследование классов | krasy | Помощь студентам | 0 | 24.04.2016 16:03 |
Наследование классов | Alexander_online | C# (си шарп) | 0 | 21.05.2013 15:50 |
Наследование классов | WebbMan | Общие вопросы C/C++ | 2 | 21.06.2012 12:39 |