Project: Planting Schedules

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.

planting planting2

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 bettwer 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:

One problem that occurs when you decide to begin a home garden is when and how often to plant the variety of plants, fruits, and vegetables on your list. 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

This project will provide you with an introduction to the fundamentals of structure types and file I/O in C++. In this project, you will…

  • Develop code to read data from the standard input and produce data to the standard output.
  • Develop code to read data from a text file and write data in a prescribed format to a text file.
  • 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.
  • Declare, define, and initialize one-dimensional, simple data type arrays of a fixed size.
  • Demonstrate the ability to read from and write to an arbitrary array element using array indices.
  • Demonstrate an ability to process the entire array, one element at a time, performing both read and write operations.

As always, be sure to properly document your code. Consult the C++ Coding Guidelines document for proper coding standards. Use good design principles and design the solution before attempting to write code.

Exercise #1: Create a program called Planting.cpp to produce a planting schedule for a given fruit or vegetable. Your program should have the following inputs:

  • The name of the plant variety (a 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).

Your program should receive these inputs and produce a planting schedule. Please note the final planting and its maturity date should not run into the fall frost date; give yourself at least two weeks between the final maturity date and the fall frost date.

Your program must validate all integer input. A structure type must be used to store the user input, and an array should contain the planting schedule information. This array must be used to produce the user output (a post-processing step – in other words, completely fill the array with the planting dates, and then produce the screen report using the array). Your program should make use of multiple functions besides main() (use the input/process/output cycle as your guide). Think about how each problem actually involves more than one subproblem. At a minimum, you must construct functions aligned with the input-process-output steps.

A Date type will be provided by the instructor; further details will be given in class.

The following test cases are provided for you to verify the accuracy of your results. You are encouraged to come up with your own test cases as well to help add to your confidence in your program code:

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

Planting Schedule for Green Beans
=================================
Planting #1: 05/01/2015
Planting #2: 05/11/2015
Planting #3: 05/21/2015
Planting #4: 05/31/2015
Planting #5: 06/10/2015
Planting #6: 06/20/2015
Planting #7: 06/30/2015
Planting #8: 07/10/2015
Planting #9: 07/20/2015

Press any key to continue...

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

Planting Schedule for Melons
=================================
Planting #1: 05/01/2015
Planting #2: 05/22/2015
Planting #3: 06/12/2015
Planting #4: 07/03/2015

Press any key to continue...

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

Planting Schedule for Melons
=================================
Planting #1: 05/01/2015
Planting #2: 06/12/2015
Planting #3: 07/24/2015

Press any key to continue...

Exercise #2: Copy Planting.cpp as Planting2.cpp. Modify Planting2.cpp to read the input data from a text file and to produce the output to a text file. Your program should have the following screen-based inputs:

  • The name of input file (a string);
  • The name of output file (a string).

Your program should then input the data from the input file and produce the output to the given output file. Remove all input validation code, and test your program thoroughly using the prior test case data (i.e. put the “test data” input into a text file. For example, an input file called input.txt might look like this:

Melons
05 1 2015
70
21
10 1 2015

And an output file produced from that input data would look like this:

You entered:
    Plant Variety? Melons
    Start Date? 05/01/2015
    Days Until Maturity? 70
    Days Between Plantings? 21
    Fall Frost Date? 10/1/2015

Planting Schedule for Melons
=================================
Planting #1: 05/01/2015
Planting #2: 05/22/2015
Planting #3: 06/12/2015
Planting #4: 07/03/2015

Deliverables

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

Powered by WordPress. Designed by WooThemes

Skip to toolbar