The United Nations (UN) has set forth 17 goals for sustainable development. Goal 11 is designed to “Make cities inclusive, safe, resilient and sustainable.” Cities are often overpopulated, which puts strain on the resources and quality of life available in that location. Increased population leads to a need for more services (e.g. transportation, energy consumption) which can cause increased amounts of pollution and limitations on the available financial resources for many municipal projects.
In this project, we will consider one aspect of sustainable development: the creation of sustainable, public gardens and greenspace in urban areas. This will be the first in a set of two projects which revolve around this concept.
Sustainable Planting and Farming
Home gardens are experiencing a renaissance of sorts as people become aware of the benefits associated with local planting and farming. Planting trees, for example, helps to reduce air pollution and soil erosion, while growing food in a home garden limits exposure to pesticides and reduces the need for non-sustainable farming methods.
Urban areas have been promoting the idea of creating gardens and green space areas on tops of buildings, in parks, and in common areas as a way to promote better quality of life and to reduce stress among citizens. Consider the following video, which discusses a sustainable farming initiative in Sand Diego, CA:
As an alternative situation, the following video describes the use of vacant/abandoned urban land in Detroit as sustainable farming area:
Sustainable urban farming requires knowledge of the growth patterns involved with specific plants, fruits, and vegetables. One problem that occurs when you decide to begin a garden is when and how often to plant. Suppose you wanted to plant a large garden, with many different vegetables and fruits. Often, multiple “plantings” of the same seeds occur to allow for a consistent schedule of available food. How would know how best to stagger your plantings? It turns out, it involves some simple math.
C++ Project: Planting Schedules (Functions)
This project will provide you with an introduction to the fundamentals of user-defined functions in C++. 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.
- Select and implement the appropriate control structure(s) for this problem.
- Decompose the given problem into a sequence of single-purpose functions that are highly cohesive and loosely coupled.
Before you begin, it is recommend that you explore the content found in the Functions in C++ electronic resource. This resource includes code examples, exercises, video discussions of C++ concepts, and a vocabulary list.
As you write your 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.
Exercise #1: With this project, we will begin to create a simple program which will produce a planting schedule for a given plant, fruit, or vegetable. Create a project called Planting
in your C++ development environment. Download these files from your Canvas module:
Date.h
Date.cpp
DateUnitTest.cpp
The Date.h
and Date.cpp
files are necessary to create a user-defined data type called Date
. This is a C++ struct
type that will be used by our project. While we will cover structs in more depth in class, for now you should understand that it is a data type comprised of multiple declarations; a variable of this type is treated as one variable with multiple parts.
For this exercise, place the files into the folder of your C++ project, add the files to your project, and make sure that everything compiles and builds. Run the application, and you should see the following output:
Test Case #1
CREATE: date1: should be 01/01/1900, it is 01/01/1900 date2: should be 11/16/2014, it is 11/16/2014 COPY: date1: should be 11/16/2014, it is 11/16/2014 date2: should be 11/16/2014, it is 11/16/2014 ADD DAYS: date2: should be 12/16/2014, it is 12/16/2014 SET DATE: date1: should be 01/30/2016, it is 01/30/2016 CREATE: date3: should be 02/23/2015, it is 02/23/2015 LESS THAN: date2: 12/16/2014 is less than date1: 01/30/2016 GREATER THAN: date3: 02/23/2015 is greater than date2: 12/16/2014 EQUAL TO: date4: 02/23/2015 is equal to date3: 02/23/2015 |
Once you see the output above, remove the DateUnitTest.cpp
file from the C++ project and continue on to the next exercise.
Exercise #2: Create a program file called Planting.cpp
in your C++ project. This will be the file we will work in for the remainder of this project. The planting schedule will wish to create will be based on the following user inputs:
- The name of the plant variety (a multi-word
string
); - The start planting date (a
Date
); - The number of days until maturity (an
int
> 0); - The number of days between plantings, i.e. the interval (an
int
> 0); - The fall frost date (a
Date
).
Create six (6) functions in your file besides main.
Five (5) of these functions will performs the necessary input operations (prompt, input, validate if requested) for the inputs above – one function per input. The sixth function will be used to echo-print the input values (nicely formatted) back to the user:
Remember to add prototypes to your code file. These prototypes should appear after the #include section and before the main
function. Once the functions are created, test them out by adding code to your main
function to call these new functions.
Here are a few sample tests you can run to check if your program is working correctly; your prompts and error messages should appear exactly as shown here, and you can type in the listed input values when prompted. Make sure the format and text of your output matches the examples below:
Test Case #1
Please input the plant variety: Green Beans Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): -1 *** ERROR! The input value must be an integer > 0. Please try again. Please enter the number of days until maturity (an integer > 0): 55 Please enter the number of days between plantings (an integer > 0): -1 *** ERROR! The input value must be an integer > 0. Please try again. Please enter the number of days between plantings (an integer > 0): 10 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Green Beans Start Date? 05/01/2015 Days Until Maturity? 55 Days Between Plantings? 10 Fall Frost Date? 10/1/2015 |
Test Case #2
Please input the plant variety: Melons Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): 70 Please enter the number of days between plantings (an integer > 0): 21 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Melons Start Date? 05/01/2015 Days Until Maturity? 70 Days Between Plantings? 21 Fall Frost Date? 10/1/2015 |
Test Case #3
Please input the plant variety: Squash Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): 48 Please enter the number of days between plantings (an integer > 0): 42 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Squash Start Date? 05/01/2015 Days Until Maturity? 48 Days Between Plantings? 42 Fall Frost Date? 10/1/2015 |
Your program is now “complete”; we will extend this program in our next project. The next project will utilize C++ arrays to produce a planting schedule, based on the input data provided by the user. Now that we have the input mechanism complete, our focus will turn to the computations necessary to transform the input data into meaningful information.
Deliverables
See the instructor for submission instructions and due date(s).