Sei sulla pagina 1di 8

List of variable created:

No
Variable
Line

In function

Description

main ( )& getChoice( )

To hold the value of choice input by the user.

20, 79

int choice

20

int z

22

double wRiver

22

double dFactory

24

double cUnderWater

24

double cOverLand

24&172

double mCost

main ( )& miniTotalcost ( )

To represent the minimum total cost overall.

24&172

double tCost

main ( )& miniTotalcost ( )

To compare and get the minimum total cost.

24&172

double y

conversionFunc ( )

To store the distance in feet.

10

24&172

double x

conversionFunc ( )

To store the distance in feet.

11

26&199

dFunction ( )

To store the inclined distance (Y).

12

26&199

dFunction ( )

To store the horizontal distance (x).

13

27

double h1

pipeline ( )

To store the width of pipe hallway (AB).

14

27

double h2

pipeline ( )

To store the width of pipe hallway (BC).

double
underWaterLength
double
overLandLength

main ( ) &
miniTotalCost ( ) & dFunction ( )
main ( )& inputFunc ( ) &
miniTotalcost ( ) &dFunction ( )
main ( )& inputFunc ( ) &
miniTotalcost ( ) &dFunction ( )
main ( )& costInput( ) & miniTotalcost
( )
main ( )& costInput( ) & miniTotalcost
( )

To hold the missing distance over land.


To store the value of width after conversion.
To store the value of distance after conversion.
To represent the cost under water.
To represent the cost over land.

15

27&220

double length

pipeline ( )

To store the overall length of pipe.

16

27&245

double longest

Pipeline ()

To hold the value of total longest pipeline

17

216

double width1

Width1_Input ()

To hold the value of width input by the user

18

225

double width2

Width2_Input ()

To hold the value of width 2 input by the user

19

245

doube ab

pipeline ()

To store the result of AB

20

245

double bc

pipeline ()

To store the result of BC

21

245

double longest2

Pipeline ()

To find the longest pipeline

22

245

int angle

Pipeline ()

To hold the value of angle

No

Line

Functions

Description

16

int main()

This function is the most important function used to receive all functions.

66

displayMenu()

To display the menu for the user with no return value.

77

getChoice()

To receive the input choice from user and return the value of choice to the main
function
To promote the user to enter the width of river and distance on the other side of the
factory and return those values to the main with reference variable as it is more than

91

inputFunc()

one value and we cannot return more than one value without reference variable.
Otherwise we would need one function for every input variable and this way will
make the code more difficult for user to understand it.
To promote the user to enter the cost under water as well as overland and return
those values to the main with reference variable as it is more than one value and we

122

costInput()

cannot return more than one value without reference variable. Otherwise we would
need one function for every input variable and this way will make the code more
difficult for user to understand it.
To take the values from main as arguments and convert those values from mile to

136

conversionFunc()

feet. After conversion we need to return the values to the main so that we used
reference variables.

170

miniTotalCost()

To transfer the variables from main to the function as argument with 5 parameter
then we used for loop to get the minimum cost , the value of z (missing distance) ,

cost of lying the power under water and over land where the cost is minimum.
8

10

197

dFunction()

211

Width1_Input()

225

Width2_Input ()

Accept variables as arguments, calculate the distance under water and overland
separately and return the distance as total where the cost is minimum.
To promote the user to enter the width of vertical hallway and return the value
entered to the main
To promote the user to enter the width of horizontal hallway and return the value
entered to the main
To receive both width as argument from the main function and calculate the longest

10

243

pipeline()

pipeline as well as the total length of the pipeline and return the total length of the
pipeline.

Section D: output
I.

Menu

II.

Power station: (choice 1)

III. Pipe Line (choice 2)

IV.

Quit (choice 3)

Overall output

V. Section E: Difficulties and Personal improvements:


In our way doing the project we faced a lot of difficulties. First of all, the formula of getting
the minimum cost of the power station question then we decide to solve it manually based on
our experience in mathematics and hydraulic issues. Next, we solve the program without
functions and we use for loop to get the minimum cost then we compared the output of the
program with the result from manual calculation. After that, we convert it to functions as we
study in class but we didnt get the correct answer, because the function cannot return more
than one value to the main. So we decide to find reference book from internet then we found
C++ programming from problem analysis to program design. In chapter 7 page (368)
Because a reference parameter receives the address (memory location) of the actual
parameter, reference parameters can pass one or more values from a function and can change
the value of the actual parameter.
Reference parameters are useful in three situations:
When the value of the actual parameter needs to be changed
When you want to return more than one value from a function
When passing the address would save memory space and time relative to copying a large
amount of data
For pipeline question there are no difficulties except the value of angle so we used for loop to
find the angle where the length of AC is minimum.

Potrebbero piacerti anche