Модификация эталонного проекта «Выпуклая оболочка»

Автор работы: Пользователь скрыл имя, 04 Декабря 2010 в 12:58, курсовая работа

Описание

В данной курсовой работе требуется модифицировать текст эталонного проекта «Выпуклая оболочка» таким образом, чтобы индуктивно определить, количество рёбер выпуклой оболочки, параллельных оси ординат. Программа написана на языке C++.

Содержание

Введение.......................................................................................................................................................4

1.Теоретическая часть
1.Описание Выпуклой оболочки......................................................................................................5
2.Описание алгоритма программы...................................................................................................6
2.Проектная часть.....................................................................................................................................7
1.Описание структуры программы..................................................................................................7
2.Описание класса R2Point...............................................................................................................7
1.Назначение............................................................................................................................7
2.Описание данных..................................................................................................................7
3.Описание методов................................................................................................................7
1.Описание конструктора R2Point()................................................................................7
2.Описание метода dist.....................................................................................................7
3.Описание метода area....................................................................................................7
4.Описание метода equal..................................................................................................8
5.Описание метода isTriangle...........................................................................................8
6.Описание метода inside.................................................................................................8
7.Описание метода light...................................................................................................8
8.Описание метода test.....................................................................................................8
3.Описание класса Deq......................................................................................................................8
1.Назначение............................................................................................................................8
2.Описание данных..................................................................................................................8
3.Свойства Deq........................................................................................................................9
4.Описание методов класса Deq.............................................................................................9
4.Описание класса Figure..................................................................................................................9
1.Назначение............................................................................................................................9
2.Описание методов................................................................................................................9
5.Описание класса Polygon.............................................................................................................10
1.Описание данных..................................................................................................................10
2.Описание методов................................................................................................................10
1.Описание конструктора Polygon ().............................................................................10
2.Описание метода add...................................................................................................10
3.Описание метода grow.................................................................................................10
4.Описание метода count................................................................................................11
6.Описание класса Segment.............................................................................................................11
1.Назначение..........................................................................................................................11
2.Описание данных................................................................................................................11
3.Описание методов..............................................................................................................11
1.Описание метода add...................................................................................................11
2.Описание метода count................................................................................................11
7.Описание класса Point..................................................................................................................12
1.Назначение..........................................................................................................................12
8.Описание класса Void...................................................................................................................12
1.Назначение..........................................................................................................................12
9.Описание класса Convex..............................................................................................................12
1.Назначение..........................................................................................................................12
2.Описание данных................................................................................................................12
10.Описание функции main....................................................................................................12
3.Испытательная программа..................................................................................................................14
Заключение.................................................................................................................................................16

Список литературы....................................................................................................................................17

Приложение 1. Примеры работы программы…………………………………………………………..18

Приложение 1. Текст программы………….…………………………………………………………….20

Работа состоит из  1 файл

Курсач1.doc

— 389.00 Кб (Скачать документ)

       {

       return (++index <16 ? index : 0);

       };

      int backward (int index)

       {

       return (--index >=0 ? index : 15);

       };

       public: Deq (int razmer)

       {

       size=head=0;

       tail=15;

       };

       public: Deq()

       {

       size=head=0;

       tail=15;

//  this(DEFSIZE);

       };

       public: int length()

       {

       return (size);

       };

       public: void pushFront(R2Point p)

       {

       array[head=backward(head)]=p;

       size +=1;

       };

       public: void pushBack(R2Point p)

       {

      array[tail=forward(tail)]=p;

       size +=1;

       };

       public: R2Point popFront()

       {

       R2Point p=front();

       head=forward(head);

       size -=1;

       return (p);

       };

       public: R2Point popBack()

       {

       R2Point p=back();

       tail=backward(tail);

       size -=1;

       return (p);

       };

       public: R2Point front()

       {

       return (array[head]);

       };

       public: R2Point back()

       {

       return (array[tail]);

       };

}; 

//Klass, zadaushiy novyi tip - Figure

class Figure

{

      public: virtual double area()

                  {return (0.0);};

      public: virtual double perimeter()

                  {return (0.0);};

      public: virtual Figure *add(R2Point p)

                  {return this;};

      public: virtual int count ()

                  {return (0);}

}; 

//Klass "mnogo-ugolnik"

class Polygon: public Figure, public Deq

{

      double s,p;

        int k; 

      private: void grow(R2Point a, R2Point b, R2Point t)

       {

      p -= a.dist(a,b);

       s += fabs(t.area(a,b,t));

         k-=a.test(a,b);

       }; 

      public: Polygon (R2Point a, R2Point b, R2Point c)

                  {

     pushFront(b);

    if (b.light(a,c))

           {

                  pushFront(a); pushBack(c);

           }  else

              {

              pushFront(c); pushBack(a);

              };

       p=a.dist(a,b) + b.dist(b,c) + c.dist(c,a);

       s=fabs(a.area(a,b,c));

            k=a.test(a,b)+b.test(b,c) + c.test(a,c);

       };

 

      public: double area()

       {

       return s;

       };

      public: double perimeter()

       {

       return p;

       };

      public: int count ()

            {

            return (k);

            };

//////////////////////////////

      public: Figure *add(R2Point t)

      {

       int i;

//Ischem osveschennye rebra

       for (i=length(); i>0 && !t.light(back(),front()); i--)

               pushBack(popFront());

//UTVERGDENIE: libo rebro [back(),front()); osvesheno iz t,

//             libo osveshennych reber net sovsem.

//

               if (i>0) {

                R2Point x;

                grow(back(),front(),t);

           // Udalaem vse osveshennye rebra iz nachala deka

                for (x=popFront(); t.light(x,front()); x=popFront())

                        grow(x,front(),t); 

                pushFront(x);

           //Udalaem vse osveshennye rebra iz konca deka

                for (x=popBack(); t.light(back(),x); x=popBack())

                        grow(back(),x,t); 

                pushBack(x);

          //Zavershaem obrabotku dobavlaemoi tochki

                p+=t.dist(back(),t)+t.dist(t,front());

                        k=k+t.test(back(),t)+t.test(t,front());

                pushFront(t);  

                };

       return this;

       };

}; 

//Klass - "Dvu-ugolnik"

class Segment: public Figure

{

      R2Point p,q;

      public: Segment(R2Point a, R2Point b)

       {

       p=a; q=b;

       };

      public: double area()

       {

       return 0.0;

       };

      public: double perimeter()

       {

       return 2.0*p.dist(p,q);

       };

      public: Figure *add(R2Point r)

            {

       if (p.isTriangle(p,q,r)) {

               Polygon *u; u=new Polygon(p,q,r);

               return (u);

                                                };

       if (q.inside(p,r)) q=r;

       if (p.inside(r,q)) p=r;

       return this;

       };

                  int count()

                  {return (p.test(p,q));}

}; 

//Klass - " odnougolnik", realizuiushii interface figury

class Point: public Figure

{

      R2Point p;

      public: Point(R2Point q)

       {

       p=q;

       };

      public: double area()

       {

       return 0.0;

       };

      public: double perimeter()

       {

       return 0.0;

       };

      public: int count()

            {

            return (0);

            }

      public: Figure *add(R2Point q)

                  {

            if (!p.equal(p,q))

                  {Segment *u; u=new Segment(p,q); return (u);}

            else return (this);

                  };

}; 

//klass "nul-ugolnik", realizuiushiiinterface figury

class Void: public Figure

{

      public: double area()

       {

       return 0.0;

       };

      public: double perimeter()

       {

       return 0.0;

       };

      public: Figure *add(R2Point p)

       {

          Point *u;

          u = new Point(p);

        return (u);

       };

            int count()

            {return(0);}

}; 

//Klass - "vypuklaia obolochka"

class Convex

{

      public: Figure *fig;

      public: Convex()

      {

          fig = new Void;

      };

      public: double area()

      {

      return fig->area();

                  };

      public: double perimeter()

      {

      return fig->perimeter();

      };

      public: int count ()

            {

            return (fig->count());

            };

      public: void add(R2Point p)

      {

      fig=fig->add(p);

      };

}; 

//Test dla vypukloi obolochki

void main()

{ 

      Convex convex;

       while (1)

        {

            double mx,my;

            cout<<"Vvedite koordinaty tochki"<<endl;

            cin>>mx; if (mx==-100) break;

            cin>>my; if (my==-100) break;

            R2Point m(mx,my);

        convex.add(m);

          cout<<"Perimeter= "<<convex.perimeter()<<endl;

            cout<<"Ploschad=  "<<convex.area()<<endl;

            cout<<"Kolichestvo="<<convex.count()<<endl;

        };

} 
 
 
 
 

Информация о работе Модификация эталонного проекта «Выпуклая оболочка»