Course Work  · Web viewCourse Work. Software Developing Principals

36
Course Work Software Developing Principals Software Developin g Principal s STU ID: 2010100 STU Name: A.V.S. Sandaruwan Batch 2014

Transcript of Course Work  · Web viewCourse Work. Software Developing Principals

Page 1: Course Work  · Web viewCourse Work. Software Developing Principals

Course Work

Software Developing Principals

Software Developing Principals

STU ID 2010100STU Name AVS SandaruwanBatch 2014

ACKNOWLEDGEMENT

First of all I would like to thank our two lecturers Mrs Udayangi Perera and Miss Hiranya Mudunkotuwa who helped us to do this assignment successfully and who

gave valuable lecture notes which made the course work and for helping us from the beginning of the course work Because of these reasons this course work became

successful and efficient

I want to thank my family members who supported me and gave a biggest strength to do the course work and the report

Last but not least I would like to thank my friendrsquos milinda chathura Dhanuska vinuri dharaka sudam Hemika sahan Damith and my all the friends for helping me during when I was stuck and helped me to complete this course work with my very

best

i

EXECUTIVE SUMMARY

In this report I have given an introduced the code for the program that we had to do And screen shots explanations about the course work

I have analyzed the program using the test data as much as I can According to the course work specification I also entered a test data prototype code before finishing

the main code

Finally I have entered a table of test data and the answers actual answers for the program

ii

CONTENT OF TABLE

1 Introduction

2 Methodoody and problem I Faced

3 Flow Chart

4 Polygon Length Program (Source Code)

5 Test Plan 6 Screen Shots

7 Test Program

71 Line Test Data

72 Point Test Data

8 Conclusion

9 Reference

iii

INTRODUCTION

Our lecturers Miss Hiranya Mudunkotuwa and MRS Udayangi assigned us with an individual task of programming software which also include some testing programs This

course work was based on our studies

The aim of this assignment is that it is part of the modulersquos coursework which provide us with an opportunity of understanding how Classes Structures Pointers and many more

things that we learned during our lecture sessions In this particular course work we individual improve the ability to analyze design and implement a program And according to

the given architectural how to do the program and the report

In this report I have provided the code for the main program that we had to do Which include three implementation files and tow header files I also include the two testing

programs that was asked by our course work specification I include flow chart to the main program test plan to show each path of the code works and a little description about my

work throughout the programming

I have referred to the lecture notes given by our lecturer and also references using the internet

1

Methodology and Problems I faced

I use the method call top bottom to deign my program It was easier than bottom up method First I look what are the categories that given to us by our lecture which we must include to our program So according to those needs first I build the platform of the program Then I design a flow chart by using the platform I break the design and according to that I coded my source code for each code of each member function and I gradually code the main function and test the each code At the end I assemble the whole code

While coding this program I faced many difficulties The main problem was how to find intersecting lines Finlay surfing through the internet I found a way And one other main problem was how to apply the test code for the main program code I follow the steps again and again and add the new functionalities as I design earlier

2

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 2: Course Work  · Web viewCourse Work. Software Developing Principals

ACKNOWLEDGEMENT

First of all I would like to thank our two lecturers Mrs Udayangi Perera and Miss Hiranya Mudunkotuwa who helped us to do this assignment successfully and who

gave valuable lecture notes which made the course work and for helping us from the beginning of the course work Because of these reasons this course work became

successful and efficient

I want to thank my family members who supported me and gave a biggest strength to do the course work and the report

Last but not least I would like to thank my friendrsquos milinda chathura Dhanuska vinuri dharaka sudam Hemika sahan Damith and my all the friends for helping me during when I was stuck and helped me to complete this course work with my very

best

i

EXECUTIVE SUMMARY

In this report I have given an introduced the code for the program that we had to do And screen shots explanations about the course work

I have analyzed the program using the test data as much as I can According to the course work specification I also entered a test data prototype code before finishing

the main code

Finally I have entered a table of test data and the answers actual answers for the program

ii

CONTENT OF TABLE

1 Introduction

2 Methodoody and problem I Faced

3 Flow Chart

4 Polygon Length Program (Source Code)

5 Test Plan 6 Screen Shots

7 Test Program

71 Line Test Data

72 Point Test Data

8 Conclusion

9 Reference

iii

INTRODUCTION

Our lecturers Miss Hiranya Mudunkotuwa and MRS Udayangi assigned us with an individual task of programming software which also include some testing programs This

course work was based on our studies

The aim of this assignment is that it is part of the modulersquos coursework which provide us with an opportunity of understanding how Classes Structures Pointers and many more

things that we learned during our lecture sessions In this particular course work we individual improve the ability to analyze design and implement a program And according to

the given architectural how to do the program and the report

In this report I have provided the code for the main program that we had to do Which include three implementation files and tow header files I also include the two testing

programs that was asked by our course work specification I include flow chart to the main program test plan to show each path of the code works and a little description about my

work throughout the programming

I have referred to the lecture notes given by our lecturer and also references using the internet

1

Methodology and Problems I faced

I use the method call top bottom to deign my program It was easier than bottom up method First I look what are the categories that given to us by our lecture which we must include to our program So according to those needs first I build the platform of the program Then I design a flow chart by using the platform I break the design and according to that I coded my source code for each code of each member function and I gradually code the main function and test the each code At the end I assemble the whole code

While coding this program I faced many difficulties The main problem was how to find intersecting lines Finlay surfing through the internet I found a way And one other main problem was how to apply the test code for the main program code I follow the steps again and again and add the new functionalities as I design earlier

2

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 3: Course Work  · Web viewCourse Work. Software Developing Principals

EXECUTIVE SUMMARY

In this report I have given an introduced the code for the program that we had to do And screen shots explanations about the course work

I have analyzed the program using the test data as much as I can According to the course work specification I also entered a test data prototype code before finishing

the main code

Finally I have entered a table of test data and the answers actual answers for the program

ii

CONTENT OF TABLE

1 Introduction

2 Methodoody and problem I Faced

3 Flow Chart

4 Polygon Length Program (Source Code)

5 Test Plan 6 Screen Shots

7 Test Program

71 Line Test Data

72 Point Test Data

8 Conclusion

9 Reference

iii

INTRODUCTION

Our lecturers Miss Hiranya Mudunkotuwa and MRS Udayangi assigned us with an individual task of programming software which also include some testing programs This

course work was based on our studies

The aim of this assignment is that it is part of the modulersquos coursework which provide us with an opportunity of understanding how Classes Structures Pointers and many more

things that we learned during our lecture sessions In this particular course work we individual improve the ability to analyze design and implement a program And according to

the given architectural how to do the program and the report

In this report I have provided the code for the main program that we had to do Which include three implementation files and tow header files I also include the two testing

programs that was asked by our course work specification I include flow chart to the main program test plan to show each path of the code works and a little description about my

work throughout the programming

I have referred to the lecture notes given by our lecturer and also references using the internet

1

Methodology and Problems I faced

I use the method call top bottom to deign my program It was easier than bottom up method First I look what are the categories that given to us by our lecture which we must include to our program So according to those needs first I build the platform of the program Then I design a flow chart by using the platform I break the design and according to that I coded my source code for each code of each member function and I gradually code the main function and test the each code At the end I assemble the whole code

While coding this program I faced many difficulties The main problem was how to find intersecting lines Finlay surfing through the internet I found a way And one other main problem was how to apply the test code for the main program code I follow the steps again and again and add the new functionalities as I design earlier

2

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 4: Course Work  · Web viewCourse Work. Software Developing Principals

CONTENT OF TABLE

1 Introduction

2 Methodoody and problem I Faced

3 Flow Chart

4 Polygon Length Program (Source Code)

5 Test Plan 6 Screen Shots

7 Test Program

71 Line Test Data

72 Point Test Data

8 Conclusion

9 Reference

iii

INTRODUCTION

Our lecturers Miss Hiranya Mudunkotuwa and MRS Udayangi assigned us with an individual task of programming software which also include some testing programs This

course work was based on our studies

The aim of this assignment is that it is part of the modulersquos coursework which provide us with an opportunity of understanding how Classes Structures Pointers and many more

things that we learned during our lecture sessions In this particular course work we individual improve the ability to analyze design and implement a program And according to

the given architectural how to do the program and the report

In this report I have provided the code for the main program that we had to do Which include three implementation files and tow header files I also include the two testing

programs that was asked by our course work specification I include flow chart to the main program test plan to show each path of the code works and a little description about my

work throughout the programming

I have referred to the lecture notes given by our lecturer and also references using the internet

1

Methodology and Problems I faced

I use the method call top bottom to deign my program It was easier than bottom up method First I look what are the categories that given to us by our lecture which we must include to our program So according to those needs first I build the platform of the program Then I design a flow chart by using the platform I break the design and according to that I coded my source code for each code of each member function and I gradually code the main function and test the each code At the end I assemble the whole code

While coding this program I faced many difficulties The main problem was how to find intersecting lines Finlay surfing through the internet I found a way And one other main problem was how to apply the test code for the main program code I follow the steps again and again and add the new functionalities as I design earlier

2

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 5: Course Work  · Web viewCourse Work. Software Developing Principals

INTRODUCTION

Our lecturers Miss Hiranya Mudunkotuwa and MRS Udayangi assigned us with an individual task of programming software which also include some testing programs This

course work was based on our studies

The aim of this assignment is that it is part of the modulersquos coursework which provide us with an opportunity of understanding how Classes Structures Pointers and many more

things that we learned during our lecture sessions In this particular course work we individual improve the ability to analyze design and implement a program And according to

the given architectural how to do the program and the report

In this report I have provided the code for the main program that we had to do Which include three implementation files and tow header files I also include the two testing

programs that was asked by our course work specification I include flow chart to the main program test plan to show each path of the code works and a little description about my

work throughout the programming

I have referred to the lecture notes given by our lecturer and also references using the internet

1

Methodology and Problems I faced

I use the method call top bottom to deign my program It was easier than bottom up method First I look what are the categories that given to us by our lecture which we must include to our program So according to those needs first I build the platform of the program Then I design a flow chart by using the platform I break the design and according to that I coded my source code for each code of each member function and I gradually code the main function and test the each code At the end I assemble the whole code

While coding this program I faced many difficulties The main problem was how to find intersecting lines Finlay surfing through the internet I found a way And one other main problem was how to apply the test code for the main program code I follow the steps again and again and add the new functionalities as I design earlier

2

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 6: Course Work  · Web viewCourse Work. Software Developing Principals

Methodology and Problems I faced

I use the method call top bottom to deign my program It was easier than bottom up method First I look what are the categories that given to us by our lecture which we must include to our program So according to those needs first I build the platform of the program Then I design a flow chart by using the platform I break the design and according to that I coded my source code for each code of each member function and I gradually code the main function and test the each code At the end I assemble the whole code

While coding this program I faced many difficulties The main problem was how to find intersecting lines Finlay surfing through the internet I found a way And one other main problem was how to apply the test code for the main program code I follow the steps again and again and add the new functionalities as I design earlier

2

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 7: Course Work  · Web viewCourse Work. Software Developing Principals

Flow Chart

3

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 8: Course Work  · Web viewCourse Work. Software Developing Principals

4

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 9: Course Work  · Web viewCourse Work. Software Developing Principals

5

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 10: Course Work  · Web viewCourse Work. Software Developing Principals

6

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 11: Course Work  · Web viewCourse Work. Software Developing Principals

Functions

7

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 12: Course Work  · Web viewCourse Work. Software Developing Principals

8

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 13: Course Work  · Web viewCourse Work. Software Developing Principals

Polygon Length Program (Source Code)

Header files

Point header file

Progarm Name Header PointAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

int x Declaring and initilizing variablesint y Declaring and initilizing variablesvoid create(int nint m) Declaring and initilizing the function createvoid display() Declaring and initilizing the function display

endif POINT_H

Line Header file

Progarm Name Header Line fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 27th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

int point1x Declaring and initilizing variablesint point2x Declaring and initilizing variablesint point1y Declaring and initilizing variablesint point2y Declaring and initilizing variablesint point3y Declaring and initilizing variablesint point4y Declaring and initilizing variablesint point3x Declaring and initilizing variables

9

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 14: Course Work  · Web viewCourse Work. Software Developing Principals

int point4x Declaring and initilizing variablesdouble length Declaring and initilizing variablesdouble lengthOfLine Declaring and initilizing variables

public

double polyganLength() Declaring and initilizing functionvoid create(Points p1Points p2) Declaring and initilizing function createvoid display() Declaring and initilizing function displayvoid lengthFunc()function to calculate the length of two pointsint sameLine(Points p1 Points p2 Points p3)function that check collinear pointsint intersect(Points p1 Points p2 Points p3 Points p4)function to check about the intersecting lines

endif LINE_H

Point Implementation file

Progarm Name Point implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(int n int m)x=n initilizing the value in to xy=m initilizing the value in to x

void Pointsdisplay()coutltltCo-ordiante pointltltxltltltltyltltendlltltendl displaying the co-ordinates

Line Implementation file

Progarm Name Line Implementation fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude linesh Use of the header file lineshinclude ltmathhgt use of library class mathh

10

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 15: Course Work  · Web viewCourse Work. Software Developing Principals

using namespace std

int a1a2 Declaring and initilizing variable x from the co-ordinatesdouble beforeSquaring=00Declaring and initilizing variablesint b1b2Declaring and initilizing variable y from the co-ordinates

void Linescreate(Points p1 Points p2) Creating lines according to the input from the user

point1x=p1x assigning the value in to point1xpoint1y=p1y assigning the value in to point1ypoint2x=p2x assigning the value in to point2xpoint2y=p2y assigning the value in to point2y

void Linesdisplay() Dispalying the line start point and end pointcoutltltLine 1st end co-ordinatesltltpoint1xltltltltpoint1yltltendlcoutltltLine 2nd end co-ordinatesltltpoint2xltltltltpoint2yltltendl

void LineslengthFunc() calculating the length of a line

a1=point1x assigning the value in to a1b1=point1y assigning the value in to b1a2=point2x assigning the value in to a2b2=point2y assigning the value in to b2calculating the length of a linebeforeSquaring=(((a2 - a1)(a2 - a1)) + ((b2 - b1)(b2 - b1))) lengthOfLine=sqrt(beforeSquaring)

double fullLength=00double LinespolyganLength() calcuating the lengtyh of the polygan

fullLength += lengthOfLinereturn fullLength returning the length of the polygan

double m1=00double m2=00double v1=00 u1=00 u2=00 v2=00

int LinessameLine(Points p1 Points p2 Points p3)point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3y

v1=(point2y-point1y) assigning the value in to v1u1=(point2x-point1x) assigning the value in to u1if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

else

m1=(v1)(u1) calculating m1 v2=(point3y-point2y) assigning the value in to v2u2=(point3x-point2x) assigning the value in to u2

11

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 16: Course Work  · Web viewCourse Work. Software Developing Principals

if(u2==0)coutltltThis cannot be donensystem(pause)exit(0)

else

m2=(v2)(u2) calculating m2

if(m1==m2) return 1 passing the valueselse return 0

int Linesintersect(Points p1 Points p2 Points p3 Points p4)

point1x=p1x assigning the value in to point1xpoint2x=p2x assigning the value in to point2xpoint3x=p3x assigning the value in to point3xpoint1y=p1y assigning the value in to point1ypoint2y=p2y assigning the value in to point2ypoint3y=p3y assigning the value in to point3ypoint4x=p4x assigning the value in to point4xpoint4y=p4y assigning the value in to point4y

double cal1=00 Declaring and initilizing variable cal1double cal2=00 Declaring and initilizing variable cal2

validatingv1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y- point1y))

if(v1==0)coutltltThis cannot be donensystem(pause)exit(0)

u1=((point4y-point3y)(point2x-point1x)-(point4x-point3x)(point2y-point1y))

if(u1==0)

coutltltThis cannot be donensystem(pause)exit(0)

calculating

cal1=((point4x-point3x)(point1y-point3y)-(point4y-point3y)(point1x-point3x))v1

cal2=((point2x-point1x)(point1y-point3y)-(point2y-point1y)(point1x-point3x))u1

Comparing and returning the answersif(cal1gt00 ampamp cal1lt10 ampamp cal2gt00 ampamp cal2lt10)

return 1else

12

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 17: Course Work  · Web viewCourse Work. Software Developing Principals

return 0

Main file

Progarm Name Main fileAuthor AVS SandaruwanPurpose To do the Course WorkDateL 28th of Augest 2011

include ltiostreamgtinclude ltlimitsgtinclude lineshUse of the header file linesh

using namespace stdconst int MAX=6

void main()int max=0 Declaring and initilizing variablesint x=0Declaring and initilizing variablesint y=0Declaring and initilizing variablesdouble total=00Declaring and initilizing variablesPoints p[MAX] Using the pointer headerLines L Using the Line headercoutltlt=================================================ncoutltlt You can only enter SIX maximum number of pointsncoutltltYou must enter at least 3 points to create a polygonncoutltlt======================================================nncoutltltHow many co-ordinates do you want to entercingtgtmaxcoutltltendl

while(max || maxlt3 ||maxgt6) Validating the maxium numbers that user enter

coutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter how may points do you want entercingtgtmax

for(int i=0 iltmax i++)

coutltltPlease Enter the co-ordiante xcingtgtx

while(cin) Validating xcoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante xcingtgtx

coutltltPlease Enter the co-ordinate ycingtgty

13

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 18: Course Work  · Web viewCourse Work. Software Developing Principals

while(cin) Validating ycoutltltErrorncinclear()cinignore(numeric_limitsltstreamsizegtmax()n)coutltltPlease Enter the co-ordiante ycingtgty

p[i]create(xy)to create pointesp[i]display()to display the created pointers

to create a line and find the length of itfor (int i=0z=0 iltmax i++)

if(ilt(max-1)) Lcreate(p[i]p[i+1])

else

Lcreate(p[i]p[0])coutltltendlcoutltltLine ltlti+1ltltendlLdisplay()coutltltendlLlengthFunc() calculating a length of a linetotal=LpolyganLength() Initilizing the length of the polygon to the variable total

coutltltendlfor(int i=0 iltmax-2 i++) Checking the points lies on points

int v=LsameLine(p[i]p[i+1]p[i+2])if(v==1)

coutltlt----------------------------------------ncoutltltErrorncoutltltYour co-ordinates are worng Points lies on

pointsncoutltltPlease Start the program againncoutltlt-----------------------------------------nsystem(pause)exit(0)

else

for (int i=0 iltmax-3 i++) checking the line intersecting

v=Lintersect(p[i]p[i+1]p[i+2]p[i+3])if(v==1)

coutltlt----------------------------------------ncoutltltErrorn

coutltltYour Co-ordinates are wrong According to your points created lines intersectn

coutltltPlease Start the Program againn

14

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 19: Course Work  · Web viewCourse Work. Software Developing Principals

coutltlt----------------------------------------nsystem(pause)exit(0)

coutltlt=================================ncoutltltThe length of the Polygonltlttotalltltendlltltendl Displaying the length of the polygancoutltlt=================================n

system(pause)

Test Plan

1st Input

Test NO Input data Expected Value Actual Value OK1 2 Error

Please Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

2 8 ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

3 A ErrorPlease Enter how many points do you want enter

ErrorPlease Enter how many points do you want enter

OK

4 4 Asking for co-ordinatesPlease Enter the co-ordiante x

Asking for co-ordinatesPlease Enter the co-ordiante x

OK

2nd Input

5 P1=(00)P2=(40) 1047 104721 OK

15

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 20: Course Work  · Web viewCourse Work. Software Developing Principals

P3=(02)6 P1=(59)P2=(436)

P3=(84) P4=(63)8149 814942 OK

7 Intersecting P1=(87)P2=(32) P3=(26) P4=(52)

2204 22051 OK

8 P1=(00)P2=(11)P3=(22)

Error Error OK

9 ASdsadsad ErrorPlease Enter the co-ordiante x y

ErrorPlease Enter the co-ordiante x y

OK

10 User Enter similar co-ordinates

This cannot be done

This cannot be done

OK

11 P1=(1426) P2=(9541) P3=(6325) P4=(945)P5=(14523)

3401 340164 OK

12 If a point lies on a line

P1=(100)P2=(00)P3=(010)

This cannot be done

This cannot be done

OK

13 P1=(00)P2=(100)P3=(010)

34142 34142 OK

14 Some invalid inputs ErrorPlease Enter how may points do you want enter

ErrorPlease Enter how may points do you want enter

OK

15 If lines are intersecting

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

ErrorYour co-ordinates are worng points lies on pointsPlease Start the program again

OK

16 P1=(236) P2=(94102) P3=(369) P4=(2103)P5=(6941)P6=(30)

6477 647719 OK

16

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 21: Course Work  · Web viewCourse Work. Software Developing Principals

Screen Shots

Outputs according to the test plan

17

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 22: Course Work  · Web viewCourse Work. Software Developing Principals

18

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 23: Course Work  · Web viewCourse Work. Software Developing Principals

19

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 24: Course Work  · Web viewCourse Work. Software Developing Principals

Test Program

Line Test and Point Test Programs

For Both test program the header file implementation files are same only different is in main file

Header files1 Line Header file

Progarm Name Header Line file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header file of the line classinclude pointhifndef LINE_Hdefine LINE_H

class Linesprivate

double point1x Declaring and initilizing variablesdouble point2x Declaring and initilizing variablesdouble point1y Declaring and initilizing variablesdouble point2y Declaring and initilizing variablesdouble point3y Declaring and initilizing variablesdouble point3x Declaring and initilizing variablesdouble point11 Declaring and initilizing variablesdouble point22 Declaring and initilizing variablesdouble point1 Declaring and initilizing variablesdouble point2 Declaring and initilizing variables

publicvoid create(Points p1Points p2)void create(double x1double y1double x2double y2) Declaring and

initilizing function createvoid display() Declaring and initilizing function displaydouble length() Declaring and initilizing function that find the

length of a line

20

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 25: Course Work  · Web viewCourse Work. Software Developing Principals

endif LINE_H

2 Point header file

Progarm Name Header point file in testAuthor AVS SandaruwanPurpose To do the Course WorkDateL 26th of Augest 2011

Header File of the point classifndef POINT_Hdefine POINT_H

class Pointspublic

double x Declaring and initilizing variablesdouble y Declaring and initilizing variablesvoid create(double ndouble m) Declaring and initilizing the

function createvoid display() Declaring and initilizing the function display

endif POINT_H

Implementation files1 Line implementation

Progarm Name Line implementation file in testAuthor AVS SandaruwanPurpose To do the Course WorkDate 26th of Augest 2011

include ltiostreamgtinclude linehinclude ltmathhgt

using namespace std

double lengt=00 maxLen=00 Declaring and initilizing variables

void Linescreate(Points p1 Points p2) Use of the function create and creating points

point1x=p1x initilizing and assigning valuespoint2x=p2x initilizing and assigning values point1y=p1y initilizing and assigning valuespoint2y=p2y initilizing and assigning values

21

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 26: Course Work  · Web viewCourse Work. Software Developing Principals

double Lineslength() calculating the length of a line

lengt=(((point2x - point1x)(point2x - point1x)) + ((point2y - point1y)(point2y - point1y))) maxLen=sqrt(lengt)return maxLen

Use of the function create and creating points anothr wayvoid Linescreate(double x1 double y1 double x2 double y2)

point11=x1 initilizing and assigning valuespoint22=x2 initilizing and assigning valuespoint1=y1 initilizing and assigning valuespoint2=y2 initilizing and assigning values

void Linesdisplay() Displaying the linecoutltlt Line Start Pointltltpoint11ltltltltpoint1ltltendlcoutltlttttLine End Pointltltpoint22ltltltltpoint2ltltendl

2 Point Implementation

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhUse of the header file pointsh

using namespace std

void Pointscreate(double n double m)x=n initilizing the value in to xy=m initilizing the value in to y

void Pointsdisplay()coutltltxltltltlty displaying the co-ordinates

Line Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgt

22

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 27: Course Work  · Web viewCourse Work. Software Developing Principals

include linehusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Line Class ncout ltlt nn

Points p1p2Lines l1l2

creating pointsp1create(510)p2create(115)

l1create(p1p2)create a line using points p1 and p2coutltltlength of your line is ltltl1length()ltltendl Output of the length of the linecoutltltendl

Creating a linel2create(510115)coutltlt Yout two points are Output of the linel2display()coutltltendlcoutltltendlsystem(pause)

Line Test Data

23

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 28: Course Work  · Web viewCourse Work. Software Developing Principals

Line Output

Point Main file

Progarm Name Calculating the area distance of a polyAuthor AVS SandaruwanPurpose To do the Course WorkDateL26th of Augest 2011

include ltiostreamgtinclude pointhusing namespace std

void main()

cout ltlt ncout ltlt Test Program to the Point Class ncout ltlt nn

Points p1p2p3p4p5p6p7p8p9p10p11p12creating pointsp1create(55)p2create(5335)p3create(11)p4create(-16)p5create(-45-6)p6create(5-1)p7create(00)p8create(-10011001)p9create(11000)p10create(25-25)p11create(5454)p12create(125-125)

24

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 29: Course Work  · Web viewCourse Work. Software Developing Principals

display of pointscoutltlt Entered points arencoutltlt ===================n

coutltlt point 1 is ( p1display()cout ltlt )ncoutltlt point 2 is ( p2display()cout ltlt )ncoutltlt point 3 is ( p3display()cout ltlt )ncoutltlt point 4 is ( p4display()cout ltlt )ncoutltlt point 5 is ( p5display()cout ltlt )ncoutltlt point 6 is ( p6display()cout ltlt )ncoutltlt point 7 is ( p7display()cout ltlt )ncoutltlt point 8 is ( p8display()cout ltlt )ncoutltlt point 9 is ( p9display()cout ltlt )ncoutltlt point 10 is ( p10display()cout ltlt )ncoutltlt point 11 is ( p11display()cout ltlt )ncoutltlt point 12 is ( p12display()cout ltlt )n

coutltltendlsystem(pause)

Point Test Data

Point Output

25

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 30: Course Work  · Web viewCourse Work. Software Developing Principals

Conclusion

This program helps us to find a length of a polygon just using co-ordinates This creates a polygon according to the co-ordinates given by the user and calculates the length of it But we can create algorithms that can be use rather than the equations I used in this program Because it is more efficient But the time we got was low we had to use the equations

Before coding the main source code of the main program coding the test codes are very help full These test programs help us how to improve our main program and what are the functionalities that must be increased

Using Test data we can check the code So we can find bugs if there are logical errors

26

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION
Page 31: Course Work  · Web viewCourse Work. Software Developing Principals

References

Top Down Method httpenwikipediaorgwikiTop-down_and_bottom-up_designTop-down_approach20[Accessed202820August202011]

Line Intersecting methods To understand httpwwwmathopenrefcomcoordintersectionhtmlMethod I used httppaulbourkenetgeometrylineline2dAnother way doing this httpalienryderflexcomintersect

Lines Collinearhttpstackoverflowcomquestions7131372count-number-of-triples-in-an-array-that-are-collinear

We had to use class in coding So some describe about what are classhttpenwikipediaorgwikiC2B2B_classesPassing parameters to functionshttpwwwgoingwarecomtipsparametersparametershtml

Calling functionshttpwwwdaniwebcomsoftware-developmentcppthreads149366

Lecture notes

27

  • Acknowledgement
  • EXECUTIVE SUMMARY
  • Content of table
  • InTRODUCTION