C++ Project: Water Catchment Systems

The United Nations (UN) has set forth 17 goals for sustainable development. Goal 6 is designed to “Ensure access to water and sanitation for all”. Access to clean water is necessary for good health, agriculture, and quality of life, and is necessary for consumption, laundry, sanitation, hygiene, and other basic activities. Recent clean water-related concerns such as the lead contamination in Flint, MI or the ongoing drought issues in California underscore the importance of this vital resource as well as the consequences of poor water quality and scarcity.

In this project, we will consider water catchment systems as one means of preventing water scarcity and providing for basic needs.

What is a Water Catchment System?

Water catchment systems are a critical source of water in many parts of the world. These systems collect rainwater and distribute it to a house, lodging, or neighborhood using a series of gravity-propelled plumbing. Such systems can also act as a reservoir by which local populations can “fill up” containers and transport the water to other locations. The following video provides a brief description of these benefits and how to create a water catchment system:

Measuring the Water Output

Suppose we wanted to use a water catchment tank for various household uses, such as watering an outdoor garden or washing the car. Assuming we have a full water catchment tank, shaped like a cylinder, one essential question to ask would be: How long would it take to empty that cylinder, if we “unscrewed” an output nozzle on the bottom? Determining the rate at which the cylinder would empty out would require knowledge of the height of the tank, the radius of the tank, and the radius of the output nozzle. Once we had these three pieces of information, we could apply a few simple math equations to get an approximate answer.

Assuming a constant flow, the volume of water in the tank will decrease to zero over time (i.e. the tank will be empty). Here are some formulas you could use to determine the change in volume over time:

  • Initial Volume of a Cylinder (i.e. the water tank): V = πr2h
  • Velocity of Outward Flow Through the Nozzle: velocity = 8.02 * (current height of the water in the tank)
  • Volume Lost From a Cylinder At Time t: Volume Lost = velocity * (4π) * t
  • Height of Water in the Cylindrical Tank at Time t: h = (current volume at time t) / (πr2)

These formulas assume the tank is initially full with water and that the output nozzle is 2 inches in diameter. The constant 8.02 (ft/sec) represents the rate at which an object drops one foot based on gravitational force.

C++ Project: Water Catchment Tanks

This project will provide you with an introduction to the fundamentals of conditional repetition in C++. The focus of this project is on how to solve problems using the C++ “while” or “do-while” statements. In this project, you will…

  • Develop code to read data from the standard input and produce data to the standard output.
  • Write code that conforms to a programming style specified by the instructor.
  • Translate given mathematical expressions into equivalent syntactically correct programming statements.
  • Select and implement the appropriate conditional repetition control structure(s) for this problem.

Before you begin, it is recommend that you explore the content found in the While Loops in C++ electronic resource. This resource includes code examples, exercises, video discussions of basic C++ concepts, and a vocabulary list.

As you write code, be sure to properly document your code. Consult the C++ Coding Guidelines document (provided by the instructor) for style expectations. Well-written code is easier to debug, easier to maintain over time, and easier to extend as new requirements arise. Use good design principles and design the solution before attempting to write code.

Exercise #1: Create a program called WaterCatchment.cpp. This program will simulate the draining of a cylindrical water catchment tank. Your program inputs are as follows:

  • The height of the cylindrical tank, in inches (a double value, 72-240 inches inclusive)
  • The radius of the cylindrical tank, in inches (a double value, 2-36 inches inclusive)
  • The number of time steps, in seconds (an int value, 1-100 inclusive)

As a first step, add code to your program which prompts the user for these three inputs and stores them in local variables. Once the input is complete, your program should echo-print the input values and end the program.

All floating-point output values should be precise to two decimal places. Validate all inputs using the rules mentioned above (one validation loop for each input, i.e. three separate loops). Here are few sample tests you can run to check if your program is working correctly; your prompts should appear exactly as shown here, and you can type in the listed input values when prompted:

Test Case #1

Enter the height of the cylindrical tank, in inches: 240
Enter the radius of the cylindrical tank, in inches: 12
Enter the number of time steps, in seconds: 5

You entered a height of 240.00 inch(es).
You entered a radius of 12.00 inch(es).
You entered 5 second(s).

Test Case #2

Enter the height of the cylindrical tank, in inches: 36
ERROR: The height must be in the range [72-240]. Please try again.

Enter the height of the cylindrical tank, in inches: 128
Enter the radius of the cylindrical tank, in inches: 40
ERROR: The radius must be in the range [2-36]. Please try again.

Enter the radius of the cylindrical tank, in inches: 22
Enter the number of time steps, in seconds: 0
ERROR: The number of time steps must be in the range [1-100]. Please try again.

Enter the number of time steps, in seconds: 18

You entered a height of 128.00 inch(es).
You entered a radius of 22.00 inch(es).
You entered 18 second(s).

Exercise #2: Next, you will add code to your program to display the initial volume (in gallons) and compute the volume lost over time. Your output will consist of the time elapsed (in seconds), the volume lost at that time step (in gallons), and the height of the water in the catchment tank at that time step (in inches).

Note that you will first need to calculate the volume of the cylinder when it is full (the initial volume), and output it to the screen. After this point, your code should enter a while loop to simulate the time steps. For each time step (i.e., each time through the loop), you will first need to calculate the velocity of flow. Once the velocity is calculated, you then need to calculate the volume lost during this time step. The volume lost is then subtracted from that current volume (in the first loop iteration, this is the initial or “full” volume). Afterwards, the new height of the water can be calculated from this “new” current volume. When the volume in the tank reaches zero (or less) OR you have completed your user-defined number of time steps, your program should stop its calculations. Some important considerations:

  • Your program should use 3.14159265 as the value of PI (π) for testing purposes.
  • The given formulas produce volumes in cubic inches. You will want to output the volume(s) in gallons; to perform the conversion, multiply the value in cubic inches by 0.004329. Do this only for output, not for computations. 

The following partial flowchart depicts the logic used for the loop and its iterations. The flowchart assumes input has already been performed, and all variables have been initialized appropriately:

WaterCatchmentFlowchart

Here are few sample tests you can run to check if your program is working correctly:

Test Case #3

Enter the height of the cylindrical tank, in inches: 240
Enter the radius of the cylindrical tank, in inches: 12
Enter the number of time steps, in seconds: 5

You entered a height of 240.00 inch(es).
You entered a radius of 12.00 inch(es).
You entered 5 second(s).

The initial volume is 470.02 gallon(s).
After 5 second(s):
   The volume lost at this time step is 31.34 gallon(s). 
   The water height at this time step is 190.36 inch(es).

Test Case #4

Enter the height of the cylindrical tank, in inches: 84
Enter the radius of the cylindrical tank, in inches: 2.5
Enter the number of time steps, in seconds: 5

You entered a height of 84.00 inch(es).
You entered a radius of 2.50 inch(es).
You entered 5 second(s).

The initial volume is 7.14 gallon(s).
After 5 second(s):
   The water catchment tank is empty.

Test Case #5

Enter the height of the cylindrical tank, in inches: 72
Enter the radius of the cylindrical tank, in inches: 8
Enter the number of time steps, in seconds: 1

You entered a height of 72.00 inch(es).
You entered a radius of 8.00 inch(es).
You entered 1 second(s).

The initial volume is 62.67 gallon(s).
After 1 second(s):
   The volume lost at this time step is 3.70 gallon(s). 
   The water height at this time step is 67.75 inch(es).

Your program is now complete.

Exercise #3: Now that your program is complete, let’s use it to experiment a bit. Suppose we have a garden hose with which to water an outdoor garden. This hose is connected to a water catchment system. We want to know how long we can water the garden before the water catchment system runs dry.

Let’s assume the diameter of the garden hose is the same as the output nozzle of the tank, and that we will water the garden for 10 minutes each day (i.e. 600 seconds). Given the following scenarios, how long will it take each of these tanks to run dry?

  • Scenario #1: Height = 240, Radius = 36
  • Scenario #2: Height = 240, Radius = 18
  • Scenario #3: Height = 120, Radius = 36
  • Scenario #4: Height = 120, Radius = 14
  • Scenario #5: Height = 73.50, Radius = 18.75

Place your answers (in whole-number days; round partial values up) in an MS Word document, properly labeled with the scenario number. Don’t forget to include your name in the document.

Deliverables

See the instructor for submission instructions and due date(s).

Powered by WordPress. Designed by WooThemes

Skip to toolbar