Sie sind auf Seite 1von 16

OBJECT ORIENTED EMBEDDED SYSTEM PROGRAMMING LANGUAGES (IMOP 6061)

POLYGON C++ LIBRARY


Developed By: Talib Hussain

User Manual

Table of Contents
Requirements of assignment ............................................................................ 3

Instructions for Assignment ............................................................. 3

Solution for Assignment must have ................................................. 3

Introduction ....................................................................................................... 5

Basic information............................................................................. 5

Use Case diagram for Polygon ....................................................... 6

Class diagram for Polygon .............................................................. 7

Polygon sequence diagram ............................................................. 8

Using Polygon C++ library .............................................................................. 10

How to use members & methods in Point class? .......................... 10

How to use members & methods in Polygon class? ..................... 12

1
Requirements of assignment
Instructions for Assignment
The header file/files for the library must also be part of the delivery. A user manual/user description on how to use the newly created library.

Chapter

A small C++ library must be created. A library in this context is a set of classes. The library must be handed in as a collection of C++ files that in a real setting

should be compiled into a .lib or a .lib and a .dll file. (Just the C++ files is sufficient for this task)

Sample code that demonstrates the use of the library, must accompany the

delivery, either as separate files or as part of the user manual.

Solution for Assignment must have


The library has to be able to store and aid in the handling of specific information.

The following is a minimum:


A class to store 3D points (Just the coordinates) A class to store a list of such coordinates (A polygon) The polygon must be able

to store an arbitrary amount of points.


Operators to manipulate objects of these classes. Operations like this must be possible PolygonObject = Point1 + Point2; PolygonObject3 = PolygonObject1 + PolygonObject2; PolygonObject1 = PolygonObject2 + Point;

filehandle << Point; filehandle << PolygonObject; filehandle >> Point; filehandle >> PolygonObject; PolygonObject1 = PolygonObject2 - Point;

2
Introduction
Basic information

Chapter

The C++ STL (Standard Template Library) is a powerful set of C++ template classes to provide general-purpose templatized classes and functions that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, and stacks. Polygon library is based on C++ STL (Standard Template Library) in order to meet the requirements of the assignment. At the cores of the C++ Standard Template Library are following three well-structured components:
Component Containers Description Containers are used to manage collections of objects of a certain kind. There are several different types of containers like deque, list, vector, map etc. Algorithms act on containers. They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers. Iterators are used to step through the elements of collections of objects. These collections may be containers or subsets of containers.

Algorithms

Iterators

All the three components have a rich set of pre-defined functions which help us in doing complicated tasks in very easy fashion. Furthermore, Vector container is selected for Polygon library which is similar to an array with an exception that it automatically handles its own storage requirements in case it grows and vector also combines the advantages of both the static and the dynamic array because it takes a non-const size parameter such as the dynamic one and automatically deletes the used memory like the static one.

Use Case diagram for Polygon


Add 3D coordinates in Polygon

uses uses

Remove 3D coordinates in Polygon

uses Add Polygon in other Polygon uses Polygon library user uses uses Write all 3D coordinates from Polygon to file Display 3D Coordinates in Polygon

Read all 3D coordinates from Polygon in file

Let consider the use case Write all 3D coordinates in Polygon. This use case may be describes as follows: Use Case name: Write all 3D coordinates from Polygon in specified output file. Short description: Library user wishes to save all the 3D coordinates in the specific Polygon in his output file. Actors: Library user Pre conditions: The library is ready to use. Scenario: 1. The Library user requests the display of 3D coordinates in specific Polygon. 2. Output file is opened for further operation. 3. Write every 3D coordinate from Polygon. 4. Close the opened file. 5. Return to instruction next to the called instruction. Post conditions: All 3D coordinates have been written into the specified output file and the library user may see all the 3D coordinates when specified file is opened.

Class diagram for Polygon


The class diagram is a static diagram. It represents the static view of an application. Class diagram is not only used for visualizing, describing and documenting different aspects of a system but also for constructing executable code of the software application.

The class diagram describes the attributes and operations of a class and also the constraints imposed on the system. The class diagrams are widely used in the modelling of object oriented systems because they are the only UML diagrams which can be mapped directly with object oriented languages and thus widely used at the time of construction. The class diagram shows a collection of classes, interfaces, associations, collaborations and constraints. It is also known as a structural diagram. There are two classes defined (Point & Polygon) in the Polygon library. Each class has its attributes (properties) and operations (methods) as you can see in class diagram in the following page. Furthermore, both classes are associated and have multiplicity in relationship for instance vector in the polygon may have or not any 3D coordinates points.
cd: Class Diagram Polygon -vector<Point> Points_Vector_List : Point +Polygon()() +Polygon(Point)() +AddPoint(Point)() : void +Size()() : int +GetPoint(int)() : <unspecified> +RemovePoint(int)() : void +friend ostream & operator<<( ostream &, const Polygon &)() +friend void operator>>(ifstream &, Polygon &)() +friend void operator<<(ofstream &, Polygon &)() +operator+(Polygon &)() : Polygon +operator+(Point &)() : Polygon +operator-(Point &)() : Polygon

Point -x : double = 0.0 -y : double = 0.0 -z : double = 0.0 +Point()() +Point( double, double, double)() +operator==(Point &)() : bool +operator!=(Point &)() : bool +operator++( int )() +friend ostream & operator<<( ostream &, const Point &)() +friend istream & operator>>( istream &, Point &)() +friend void operator>>(ifstream &, Point &)() +friend void operator<<(ofstream &, Point &)()

Polygon sequence diagram


A sequence Diagram illustrates how objects interact with each other in time. The diagram focuses on which messages the objects exchange and when this is done. Horizontally on the top of the diagram we find objects depicted as rectangles. The time axis extends vertically downwards in the diagram. The further down a message is initiated the later in time this is. The time span where the objects are alive is represented by dotted lines extending downwards from the objects (lifelines).

A horizontal line at some point in time from one objects lifeline to another objects lifeline represent a message being sent at that point in time. This is how the communication from one object to another is represented. The direction of the arrow indicates the direction of the interaction. The arrow may have a name indicating which method in the receiving object is being called. The diagram will normally show the complete interactions involved in a scenario or sub-scenario in case of a complex use case description. The following figure gives an example on how a sequence diagram from the world of lifts may look like. The use case being represented is the Ride Lift use case. The sequence of events starts with the passenger selecting the destination floor by pressing a push button.

: Library user

: Ofstream

: Polygon

: Point

void operator<<( ofstream &inputFile, Polygon &poly) inputFile.open("3dPolygon.txt")

loop

[ i<poly.Size() ]
inputFile<<poly.GetPoint(i)<<endl

inputFile<<poly.GetPoint(i)<<endl

inputFile.close()

3
Using Polygon C++ library

Chapter

The Polygon C++ library consists of 4 files; Point.h (header file and declarations of members and methods for Point class), Point.cpp (header file and definitions of members and methods for Point class), Polygon.h (header file and definition of members and methods for Polygon class) and Polygon.cpp (header file and declarations of members and methods for Polygon class). Please include all above mentioned 4 files in your project. However only #include Polygon.h is required beneath the instruction #include <iostream> the where you want to use the Polygon C++ library.

How to use members & methods in Point class?


All 3 coordinates of every 3D Point has been designed to accept any number with decimal point for more accuracy. The members & methods of Point class are mentioned in the following Point class diagram.

Point -x : double = 0.0 -y : double = 0.0 -z : double = 0.0 +Point()() +Point( double, double, double)() +Set( double, double, double)() +operator==(Point &)() : bool +operator!=(Point &)() : bool +operator++( int )() +friend ostream & operator<<( ostream &, const Point &)() +friend istream & operator>>( istream &, Point &)() +friend void operator>>(ifstream &, Point &)() +friend void operator<<(ofstream &, Point &)()

When #include Polygon.h is mentioned as per given statement, then instance of Point class can be easily created and initialized with given values for 3D coordinates in Point Object as mentioned in the below mentioned code.

Instance takes three parameters; first parameter is for x coordinate, second parameter is for y coordinate and third parameter is for z coordinate for any 3D point. When above mentioned will be executed then output will be similar to the below mentioned screen snapshot.

How to use members & methods in Polygon class?


The Polygon class has following members & methods shown in the below Polygon class diagram.

Polygon -vector<Point> Points_Vector_List +Polygon()() +Polygon(Point)() +AddPoint(Point)() : void +Size()() : int +GetPoint(int)() : <unspecified> +RemovePoint(int)() : void +friend ostream & operator<<( ostream &, const Polygon &)() +friend void operator>>(ifstream &, Polygon &)() +friend void operator<<(ofstream &, Polygon &)() +operator+(Polygon &)() : Polygon +operator+(Point &)() : Polygon +operator-(Point &)() : Polygon

Similarly members and methods in Polygon class can be accessed in similar fashion and source is given below.

Output will be similar to the following screen snapshot when above mentioned source code will be executed.

Furthermore, file I/O operation to from file can be done for Point object has file name 3dPoint.txt and 3dPolygon.txt for Polygon objects. Source code is given as:

Output will be similar to the following screen snapshot when above mentioned source code will be executed.

16

Das könnte Ihnen auch gefallen