Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Problem Set 2 – Method, Method Calling, Class, Constructor

1. You have been given a flat carboard of area, say, 70 squares inches, to make an open box by
cutting a square from each corner and folding the sides. Your objective is to determine the
dimension, that is, the length and width, and the side of the square to be cut from the corners so
that the resulting box is of maximum volume. Calculate your answer to three decimal places.
Your program must contain a function that takes as input the length and width of the cardboard
and returns the side of the square that should be cut to maximize the volume. The function also
returns the maximum volume.

2. A power station is on one side of a river that is one half mile wide, and a factory is 8 miles
downstream on the other side of the river. It costs Php. 315 per foot to run power lines overland
and Php. 405 per foot to run them underwater.

Your objective is to determine the most economical path to lay the power line. That is,
determine how long the power line should run underwater and how long should it run over land,
to achieve the minimum total cost of laying the power line.

Write a program that prompts the user to enter

a. The width of the river


b. The distance of the factory downstream on the other side of the river
c. Cost of laying the power line underwater
d. Cost of laying the power line overland.

The program then outputs the length of the power line that should run underwater and the
length that should run over land, so the cost of constructing the power line is at the minimum.
The program should also output the total cost of constructing the power line.

3. If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the
estimated population at the end of the year is given by the formula:

P + (B*P)/100 – (D*P)/100

The population growth rate is given by the formula:

B-D

Write a program that prompts the user to enter the starting population, birth and death rates,
and n, the number of years. The program should then calculate and print the estimated
population after n years. Your Program must consist of the following methods.
a. growthRate – This methods takes as its parameters the birth and death rates, and it returns
the population growth rate.
b. estimatedPopulation – This method takes as its parameters the current population,
population growth rate, and n, the number of years. It returns the estimated population
after n years.

You might also like