1. Objective



Assignment 1 – Tuesday, Jan. 26, 2021 at 11:59pmThis assignment must be done individually.1. ObjectiveIn this assignment, you will perform two tasks: (1) Have the user input the dimensions of a farm. Then do calculations to find the maintenance cost and how many pumpkins can be grown on the land. (2) Calculate the net profit of the crop by factoring in transportation and maintenance costs, with gross sales. 2. DescriptionFarmer Jessie decided he wanted to try out a new crop this year – pumpkins! He has a lot of land and can set aside a rectangular plot to grow his new crop. The farmer wants to know how many pumpkins he can grow based on the size of his plot. Jessie, of course, needs to sell these pumpkins to make money. Jessie has a trailer and needs to bring these pumpkins to market. He needs help calculating how many trips it will take in his truck to move all of his pumpkins to the market. All of the growing and transportation of the crop makes the farmer incur some cost. Write a program to help Jessie figure out the net profit he can make selling pumpkins off his plot.Part 1The pumpkin patch will be a rectangular plot of land. First, you will need to ask the user to input the width and the length of the plot in feet. Then, calculate the area of the plot and print the area to the console. Remember to use good variable names to keep track of all the data being entered and calculated.Maintaining fertile land isn’t free – every square foot of land costs $0.06 to maintain. Use the area we calculated above to determine the plot’s maintenance cost. Print the maintenance cost to the console. (Note: We should format money properly, so check REF _Ref61564083 \h Cout Precision below for details on how to achieve this)It’s time to grow some crops! Pumpkins take a 4ft x 4ft square to grow. Calculate how many whole pumpkins can fit on this plot. Print the pumpkin capacity of the plot to the console. (Note: If the user inputs 3 ft x 16 ft plot of land, 0 pumpkins can grow here because no pumpkins have a proper 4 x 4 plot.)Hints: Create an int variable, pumpkinsPerWidth, that calculates how many pumpkins can fit length wise.Create an int variable, pumpkinsPerLength, that calculates how many pumpkins can fit width wise.Then, multiply these together to get the number of whole pumpkins that can fit in the plot.Part 2Would you look at that! The crops Jessie grew are perfectly spherical pumpkins with a radius of 1 foot! Calculate the volume, in cubic feet, of all the pumpkins grown and print this to the console. (Use the pi approximation π = 3.14 in the volume of a sphere equation)Fitting these pumpkins in the trailer was a bit tricky, but we have found a way to stack the pumpkins so we can utilize 100% of the volume in the trailer! The dimensions of the trailer are: 8 ft width, 14 ft length and 6 ft height. Using the volume of all the pumpkins and the volume of the trailer, calculate how many trips it would take for Jessie to bring all the pumpkins to market and print this to the console. (Note: We need our trips to be whole integers. Ex: If this calculation brings us to 4.5 trips, we need to round up to 5 trips. Look at REF _Ref61564007 \h Rounding below to see how this is done.)Lugging all of these pumpkins to market can be a real gas guzzler, each trip costs $33.63 in gas. Calculate the cost of gas and print this to the console.Yay! The farmer’s market has come, and Jessie ready to sell his produce! Pumpkin prices are good this year at $5.25 for a single pumpkin. Assuming he can sell all of the pumpkins he grows, calculate his gross profit and print this to the console. (Note: Ensure this is a printed to console in a proper dollar amount. Check REF _Ref61564203 \h 4. Testing: below for some sample output).Finally, with all the hard work over its time to see how much money he gets to take home. Find the farmer’s net profit by subtracting the transportation and maintenance costs from the gross profit. Print the net profit to the console.3. ImplementationSince you are starting with a "blank piece of paper" to implement this project, it is very important to develop your code incrementally writing comments, adding code, compiling, debugging, a little bit at a time. This way, you always have a program that "does something" even if it is not complete.As a first step, it is always a good idea to start with an empty main function, and add the code to read input data from the user, and then simply print these values back out again. Once this part is working, you can start performing calculations with the input data.Cout PrecisionWhen displaying dollar amounts, we typically limit them to two decimal points to represent cents. So how do we achieve this in C++? First you should include the library for Input/Output Manipulation:#include <iomanip>Now, you can use the setprecision function to modify the decimal length outputs. The value that you put in the parentheses indicates how many significant figures you want to use to display the number.By default, the number of significant figures includes digits before and after the decimal place. However, if we set the fixed flag first, then cout will use “fixed precision.” This means that the number passed to setprecision indicates how many significant figures after the decimal are included. Here is an example:float a = 12.34567;cout << a << endl;// prints 12.34567cout << setprecision(3) << a << endl; // prints 12.3cout << fixed << setprecision(2) << a << endl;// prints 12.34 , great for $ valuesNote that since setprecision only modifies the output stream, the number stored in memory is still 12.34567. Also, note that C++ takes care of rounding the output appropriately. RoundingIn C++, rounding down can be achieved by taking a floating-point number and storing it as an integer. This chops off all of the decimal points. But how do we round to the nearest integer? The easiest approach is to add 0.5 to the value and then truncate.e.g., int Integer;Integer = 13.0/5.0; //calculates the value 2.6 then the assignment to Integer truncatescout << Integer; //you will see the value 2, the int value after truncating 2.6 Integer = 13.0/5.0 + 0.5; //calculates 2.6 + 0.5 = 3.1 then the assignment to an int truncatescout << Integer; //you will see the value 3, the int value after truncating 3.1This will round 2.6 to 3! The rounding approach above will round 2.6 to 3.??But, it will round 2.2 to 2. E.g., 2.2?+ 0.5 =? 2.7 which would then be truncated to 2 when assigned to an integer variable.??So, with this approach, each float value is rounded to the?nearest?integer value.What if we want to map floating point values to the?next largest?integer?? i.e., we want 2.2 to become 3, not 2.? ?We need the ceiling function.To do this, first you should include the C++library for math:?#include <cmath>??? Now you can use the?ceil?function to round any floating-point number up to its nearest whole integer.?float b = 2.2;int Integer;Integer = ceil(b); // Integer equals 3StyleYou should use great variables and constants. For example, use a named constant for PI (const int PI = 3.14), the space a pumpkin takes to grow (e.g., const int PUMPKIN_SPACE = 4), the sizes of the pumpkins, trailers, etc. Choose good names for your variables, use good indentation, and add a few comments in for the major steps (e.g., // Calculating the number of pumpkins Jesse can grow)4. TestingYour program must run in OnlineGDB or by using g++ on Turing. Test your program with a variety of inputs to check that it operates correctly for all of the requirements listed above. Once your program is running correctly, you should run it several times with boxes of the same size but different orientations to see what orientation gives the highest space utilization. For example, using 16” by 15” by 22” instead of 15” by 16” by 22”. Include the results of your experiments in your project report. Also, try invalid inputs such as -1 and 0. Your program is not required to work properly with string (e.g., “hello”) or character (e.g., ‘C’) input.You are NOT required to add error checking in this program, but it is always good to test a program to see what happens to your program if the user inputs unexpected data (like “Hello mom!”). You should copy/paste these results into your project report to document what your program does in these cases. If you aren’t sure how to compile or execute your code, go the class website -> Lab Assignments -> Online GDB Tutorial for help.Sample Output #1Enter Width: 74Enter Length: 132.5The area of the farm is: 9805 sq ftThe farm's maintenance cost is: $588.30The farm's pumpkin capacity is: 594The volume of all the pumpkins is: 2486.88 cu ftThe total trips to market will be: 4The transportation cost is: $134.52The gross profit is: $ 3118.50The farmer's net profit is: $2395.68Sample Output #2Enter Width: 3Enter Length: 16The area of the farm is: 48 sq ftThe farm's maintenance cost is: $2.88The farm's pumpkin capacity is: 0The volume of all the pumpkins is: 0.00 cu ftThe total trips to market will be: 0The transportation cost is: $0.00The gross profit is: $ 0.00The farmer's net profit is: $-2.885. DocumentationWhen you have completed your C++ program, write a short report using the “Programming Project Report Template” describing what the objectives were, what you did, and the status of the program. Does your program work properly for all test cases? Are there any known problems? Save this project report in a separate document to be submitted electronically.6. Project SubmissionIn this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic plagiarism analysis of all programs that are submitted. When you have completed the tasks above go to Blackboard to upload your documentation (a single .docx or .pdf file), and your C++ program (a single .cpp file). Do NOT upload an executable version of your program.The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:10% off if less than 1 day late,20% off if less than 2 days late,30% off if less than 3 days late,no credit if more than 3 days late. You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended. 7. Academic Honesty StatementStudents are expected to submit their own work on all programming projects, unless group projects have been explicitly assigned. Students are NOT allowed to distribute code to each other, or copy code from another individual or website. Students ARE allowed to use any materials on the class website, or in the textbook, or ask the instructor and/or GTAs for assistance.This course will be using highly effective program comparison software to calculate the similarity of all programs to each other, and to homework assignments from previous semesters. Please do not be tempted to plagiarize from another student.Violations of the policies above will be reported to the Provost's office and may result in a ZERO on the programming project, an F in the class, or suspension from the university, depending on the severity of the violation and any history of prior violations. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download