
Висновки
В курсовій роботі було розроблено програму на мові програмування С++. Програма розроблена з використанням компілятора Borland C++ 3.1 за методами об’єктно-орієнтованого програмування. Вона використовує такі принципи ООП, як інкапсуляція, наслідування, дружні функції, скритність даних і т. ін. Було розроблено алгоритм розв’язання поставленої в завданні задачі, інтерфейс програми тощо.
Список літератури
1. Б.В. Керниган, Д. М. Ритчи, “Язык С”.
2. Б’ярн Страустрап, “Введения в язык Си++”, 1995 р.
3. Громов Ю.Ю., Титаренко С.І., “Программирование на языке С”, учебное пособие. – Тамбов, 1995 р.
4. Джесс Либерти “Освой самостоятельно С++ за 21 день.”
Додаток
Лістинг “New@.cpp”
#include <fstream.h>
#include <math.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <stdio.h>
class point
{int x,y;
public:
point (){};
point (int setX,int setY){x=setX;y=setY;};
void SetX(int setX){x=setX;};
void SetY(int setY){y=setY;};
int GetX(){return x;};
int GetY(){return y;};};
class Line
{point A;
point B;
double a,b,c;
public:
Line(){};
void SetLine(point setA,point setB){A=setA;B=setB;SetABC();};
double Length(void);
int GetXA(){return A.GetX();}
int GetYA(){return A.GetY();}
int GetXB(){return B.GetX();}
int GetYB(){return B.GetY();}
void SetABC();
double GetA(){return a;}
double GetB(){return b;}
double GetC(){return c;}
int Peresech(Line L);};
double Line::Length(void)
{double dX=B.GetX()-A.GetX();
double dY=B.GetY()-A.GetY();
return(sqrt(dX*dX+dY*dY));}
void Line::SetABC()
{a=B.GetY()-A.GetY();
b=A.GetX()-B.GetX();
c=B.GetX()*A.GetY()-A.GetX()*B.GetY();}
int Line::Peresech(Line L)
{if((GetA()*L.GetXA()+GetB()*L.GetYA()+GetC()>0&&
(GetA()*L.GetXB()+GetB()*L.GetYB()+GetC()<0))||
((GetA()*L.GetXA()+GetB()*L.GetYA()+GetC()<0)&&
(GetA()*L.GetXB()+GetB()*L.GetYB()+GetC()<0)))
return 1;
else return 0;}
class Treangle
{Line AB;
Line BC;
Line AC;
int color;
public:
Treangle(){};
Treangle(point setA,point setB,point setC);
int GetColor(){return color;}
void SetColor(int setColor){color=setColor;}
int Ravnobedrenost(void);
double Square(void);
void Draw(void);
int Peretin(Treangle T);};
Treangle::Treangle(point setA,point setB,point setC)
{AB.SetLine(setA,setB);
BC.SetLine(setB,setC);
AC.SetLine(setA,setC);}
Treangle::Ravnobedrenost(void)
{if(AB.Length()==BC.Length()||
BC.Length()==AC.Length()||
AB.Length()==AC.Length())
return(1);
else
return(0);}
double Treangle::Square(void)
{double p=(AB.Length()+BC.Length()+AC.Length())/2;
return(sqrt(p*(p-AB.Length())*(p-BC.Length())*(p-AC.Length())));}
int Treangle::Peretin(Treangle T)
{Line X,Y;
for (int storona=0;storona<3;storona++)
{if (storona==0) X=AB;
else if(storona==1) X=BC;
else if(storona==2) X=AC;
for (int storona2=0;storona2<3;storona2++)
{if (storona2==0) Y=T.AB;
else if (storona2==1) Y=T.BC;
else if (storona2==2) Y=T.AC;
if (X.Peresech(Y)==1&&Y.Peresech(X)==1)
return 1;}}
return(0);}
void Treangle::Draw(void)
{setcolor(GetColor());
line(AB.GetXA(),AB.GetYA(),AB.GetXB(),AB.GetYB());
line(BC.GetXA(),BC.GetYA(),BC.GetXB(),BC.GetYB());
line(AC.GetXA(),AC.GetYA(),AC.GetXB(),AC.GetYB());
// closegraph();}
int KolichestvoTreugolnikov(void)
{char *FileName="a:\\trea.TXT";
char buf;
int kolichTochek=0;
int kolichTreugolnikov;
ifstream f(FileName);
if(f==0)
{ cout << "File not found " << FileName << endl;
getch();
return(0);}
do{
buf=f.get();
if(buf=='(') kolichTochek++;
} while(f.eof()==0);
f.close();
return (kolichTochek/3);}
int main (void)
{clrscr();
int kolichTreugolnikov=KolichestvoTreugolnikov();
Treangle *tre=new Treangle[kolichTreugolnikov];
int i,j,maxI,maxJ;
double maxSquare;
int gdriver = DETECT,gmode;
int kordinatsX[1000],kordinatsY[1000];
char *FileName="a:\\trea.TXT";
ifstream ff(FileName);
for (i=0;i<kolichTreugolnikov*3;i++)
{ff.ignore(50,'('); ff >> kordinatsX[i];
ff.ignore(50,','); ff >> kordinatsY[i];}
initgraph(&gdriver,&gmode,"\\");
for (i=0;i<kolichTreugolnikov;i++)
{point A(kordinatsX[3*i],kordinatsY[3*i]);
point B(kordinatsX[3*i+1],kordinatsY[3*i+1]);
point C(kordinatsX[3*i+2],kordinatsY[3*i+2]);
tre[i]=Treangle(A,B,C);}
for (i=0;i<kolichTreugolnikov;i++)
{tre[i].SetColor(1);
for (j=i+1;j<kolichTreugolnikov;j++)
{if(tre[i].Square()+tre[j].Square()>maxSquare&&tre[i].Peretin(tre[j])==1)
{maxSquare=tre[i].Square()+tre[j].Square();
maxI=i;
maxJ=j;}}
if (tre[i].Ravnobedrenost()==1)
tre[i].SetColor(2);
cout <<tre[i].Square()<<endl;}
tre[maxI].SetColor(3);
tre[maxJ].SetColor(3);
cout <<endl<<tre[maxI].Square()<<endl;
cout <<tre[maxJ].Square();
for (i=0;i<kolichTreugolnikov;i++)
{tre[i].Draw();}
getch();
return (0);}
Лістинг “menu.cpp”
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<process.h>
#define LEFT 75
#define RIGHT 77
#define DOWN 13
class Button
{int x1;
int y1;
int x2;
int y2;
char str[80];
public:
void setparam(int xx1,int yy1,int xx2,int yy2,char *sstr);
virtual void run(void)=0;
void show(int tcolor, int bcolor);};
void Button::setparam(int xx1,int yy1,int xx2,int yy2,char *sstr)
{x1=xx1;
y1=yy1;
x2=xx2;
y2=yy2;
strcpy(str,sstr);}
void Button::show(int tcolor,int bcolor)
{textcolor(tcolor);
textbackground(bcolor);
window(x1,y1,x2,y2);
clrscr();
gotoxy(1,1);
printf("%s",str);};
class Button1:public Button
{public:
virtual void run(void);};
class Button2:public Button
{public:
virtual void run(void);};
class Button3:public Button
{public:
virtual void run(void);};
class Button4:public Button
{public:
virtual void run(void);};
class Button5:public Button
{public:
virtual void run(void);};
void Button1::run(void)
{char str[80];
FILE *fin=fopen("About.txt","r");
textbackground(0);
window(17,6,50,19);
clrscr();
textbackground(11);
textcolor(15);
window(15,5,48,18);
clrscr();
for(int i=0;i<11;i++)
{fgets(str,80,fin);
gotoxy(1,1+i);
cputs(str);}
getch();
textbackground(0);
clrscr();
fclose(fin);};
void Button2::run(void)
{spawnl(P_WAIT,"\\NEW@.exe","Program",NULL);}
void Button3::run(void)
{spawnl(P_WAIT,"c:\\BC\\BIN\\bc.exe","BC","\\NEW@.cpp",NULL);}
void Button4::run(void)
{spawnl(P_WAIT,"a:\\notepad.exe","notepad","\\trea.txt",NULL);}
void Button5::run(void)
{textbackground(0);
window(1,1,80,25);
clrscr();
exit(0);}
class Menu
{int x,y;
Button *mas[5];
Button1 butt1;
Button2 butt2;
Button3 butt3;
Button4 butt4;
Button5 butt5;
int numberAct;
int ActTcolor,ActBcolor,PasTcolor,PasBcolor;
void onLEFT(void);
void onRIGHT(void);
void onDOWN(void);
void show(void);
public:
Menu(int xx,int yy);
void getMessage(int msg);};
void Menu::onLEFT(void)
{numberAct=(numberAct==0)? 4:(numberAct-=1);};
void Menu::onRIGHT(void)
{numberAct=(numberAct==4)? 0:(numberAct+=1);};
void Menu::onDOWN(void)
{mas[numberAct]->run();};
void Menu::show(void)
{window(1,1,80,1);
textbackground(11);
clrscr();
for(int i=0;i<5;i++)
if (i==numberAct)
mas[i]->show(ActTcolor,ActBcolor);
else
mas[i]->show(PasTcolor,PasBcolor);
window(1,2,80,24);
textbackground(1);
clrscr();
textbackground(11);
textcolor(0);
window(1,25,80,25);
clrscr();
gotoxy(3,1);
textcolor(15);};
void Menu::getMessage(int msg)
{switch(msg)
{case LEFT:
onLEFT();
show();
break;
case RIGHT:
onRIGHT();
show();
break;
case DOWN:
onDOWN();
show();}};
Menu::Menu(int xx,int yy)
{x=xx;
y=yy;
numberAct=0;
mas[0]=&butt1;
mas[1]=&butt2;
mas[2]=&butt3;
mas[3]=&butt4;
mas[4]=&butt5;
ActTcolor=15;
ActBcolor=0;
PasTcolor=0;
PasBcolor=11;
FILE *fin=fopen("\\menuab.dat","r");
char str[80];
for(int i=0;i<5;i++)
{fgets(str,80,fin);
mas[i]->setparam(x,y,x+strlen(str),y+2,str);
x+=strlen(str)+1;}
fclose(fin);
show();};
void main()
{textbackground(0);
clrscr();
Menu mnu(3,1);
while(1)
mnu.getMessage(getch());};
Результат виконання «New@.exe»