c++ polygon user manual

Upload: talibhsn9

Post on 04-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 C++ Polygon User Manual

    1/16

    OBJECT ORIENTED EMBEDDED

    SYSTEM PROGRAMMING

    LANGUAGES (IMOP 6061)

    POLYGON C++ LIBRARY

    Developed By: Talib Hussain

    User Manual

  • 8/13/2019 C++ Polygon User Manual

    2/16

    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

  • 8/13/2019 C++ Polygon User Manual

    3/16

    Requirements of assignment

    Instructions for Assignment

    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)

    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.

    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;

    Chapter

    1

  • 8/13/2019 C++ Polygon User Manual

    4/16

    filehandle Point;

    filehandle >> PolygonObject;

    PolygonObject1 = PolygonObject2 - Point;

  • 8/13/2019 C++ Polygon User Manual

    5/16

    Introduction

    Basic information

    The C++ STL (Standard Template Library) is a powerful set of C++ template classes to

    provide general-purpose templatized classes and functions that implement manypopular 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 Description

    Containers 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.

    AlgorithmsAlgorithms act on containers. They provide the means by which you willperform initialization, sorting, searching, and transforming of the contentsof containers.

    IteratorsIterators are used to step through the elements of collections of objects.These collections may be containers or subsets of containers.

    Chapter

    2

  • 8/13/2019 C++ Polygon User Manual

    6/16

    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

    Polygon library user

    Add 3D

    coordinates in

    Polygon

    Add Polygon in

    other Polygon

    Remove 3D

    coordinates inPolygon

    Display 3D

    Coordinates in

    Polygon

    Write all 3D

    coordinates from

    Polygon to file

    Read all 3D

    coordinates from

    Polygon in file

    uses

    uses

    uses

    uses

    uses

    uses

  • 8/13/2019 C++ Polygon User Manual

    7/16

    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.

  • 8/13/2019 C++ Polygon User Manual

    8/16

    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 classesdefined (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

    +Point()()

    +Point( double, double, double)()

    +operator==(Point &)() : bool

    +operator!=(Point &)() : bool

    +operator++( int )()

    +friend ostream & operator( istream &, Point &)()

    +friend void operator>>(ifstream &, Point &)()

    +friend void operator

  • 8/13/2019 C++ Polygon User Manual

    9/16

    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

    inputFile.open("3dPolygon.txt")

    void operator

  • 8/13/2019 C++ Polygon User Manual

    10/16

    Using Polygon C++ library

    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

    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()()

    +Point( double, double, double)()

    +Set( double, double, double)()

    +operator==(Point &)() : bool

    +operator!=(Point &)() : bool

    +operator++( int )()

    +friend ostream & operator( istream &, Point &)()

    +friend void operator>>(ifstream &, Point &)()

    +friend void operator

  • 8/13/2019 C++ Polygon User Manual

    11/16

    When #include Polygon.his 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.

  • 8/13/2019 C++ Polygon User Manual

    12/16

    How to use members & methods in Polygon

    class?

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

    diagram.

    +Polygon()()

    +Polygon(Point)()

    +AddPoint(Point)() : void

    +Size()() : int+GetPoint(int)() :

    +RemovePoint(int)() : void

    +friend ostream & operator(ifstream &, Polygon &)()

    +friend void operator

  • 8/13/2019 C++ Polygon User Manual

    13/16

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

    be executed.

  • 8/13/2019 C++ Polygon User Manual

    14/16

    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:

  • 8/13/2019 C++ Polygon User Manual

    15/16

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

    code will be executed.

  • 8/13/2019 C++ Polygon User Manual

    16/16

    16