Objective



Assignment 6 – April 14, 2021 at 11:59pmThis assignment must be done individually.ObjectiveThe goal of this assignment is to get practice using files and implementing a class. You will be helping Farmer Jessie summarize the raw data about her crop harvests and the profits she made from them. You will create a Ledger class that will store the profits and the types of crops, and will generate a separate file that will give some stats about the information in her record books.Prerequisites:To complete this assignment, you should be familiar with the following concepts:Files and streamsLoopsArraysCreating/implementing classes (object oriented programming)2. Description of Required MethodsDefault Constructor (provided)Parameters: noneInitialize all of the attributes (or instance variables) of the class: set elements of the two arrays to empty strings, and set the number of crops to zero.Copy ConstructorParameters: the Ledger object to copy fromSet all attributes (or instance variables) in the class equal to the variables of the Ledger object passed inDestructorParameters: noneSince there is no dynamic memory associated with the Ledger class, the destructor will not have anything in it. However, good coding convention dictates that we still include it to get in the habit for bigger projects where we do need to deallocate the memory once we’re done with it so that we don’t end up with a memory leak!printContents (provided)Parameters: noneReturns: nothingPrint out the contents of the Ledger instancereadFileParameters: a string that contains the filename that will be readReturns: nothingOpen the file with the pass-by-value string filename and populate the two arrays (amounts and crops) with the data. When you’re reading in the data, you should ensure that good data was stored in Farmer Jessie’s record books. Validate the profit with validAmount (see method G) and validate the crop name with validCrop (see method H). If either the profit or the crop name is invalid, do not add it to the arrays.*Remember to close your file once you have finished reading from it!generateStatsParameters: a string that contains the filename that will be writtenReturns: nothingCreates a new file named by the pass-by-value string filename. Save information about Farmer Jessie’s farm including her average profit by using calculateAverage (see method I) and the number of each of the crops she harvested with countCrops (see method J) into this file. You should also print how many fields are available to plant (take the maximum number of crops allowed and subtract the number of crops planted to find the number of fields available).*Remember to close your file once you have finished writing to it!validAmountParameters: a float that contains an amountReturns: true if the pass-by-value amount is between [1000…2500], false if notThis function ensures that the profit is a valid amount no less than $1000 and no more than $2500. It should be called when the user is reading in the information from the file.validCropParameters: a string that contains the name of a cropReturns: true if the pass-by-value crop name is one of the four possible crops (Potato, Beet, Pumpkin, or Wheat), false if the crop name is anything elseThis function ensures that valid crop names are saved in Farmer Jessie’s record books. If the saved name is not one of the four expected crop names, return false.calculateAverageParameters: noneReturns: a number representing the average profit of the numbers stored in Farmer Jessie’s ledgersThis function will calculate the average profit held in the amounts array of each of her crops.countCropsParameters: four integers to hold the counts of each of the crops, pass-by-referenceReturns: nothingThis function will count the number of each type of crop in the crops array. The parameters are passed in by reference to hold this data.Your choice! Design and test TWO methods of your own that you believe would add value to this Ledger class. Perhaps you want Farmer Jessie to be able to add an additional crop of Pumpkins after last Halloween’s harvest was so profitable. Perhaps there was a typo in one of the profits that needs to be edited to reflect the correct price. Perhaps Youngster James trampled the crops while playing with his pet cat and that entry needs to be voided. These are just some example ideas and you are welcome (and encouraged!) to come up with your own!Before you get started you must download and use the starter code for this project.InstructionsFirst copy and/or download the starter code and run it. You should not get any errors. It should compile and quit. To copy all the files, login to turing and do the following sequence of commands:create a directory for this homework e.g., mkdir hw6move into that directorye.g., cd hw6copy all the files for the starter code to your current directory (called ‘.’)e.g., cp ~sgauch/public_html/2004/S21/hw/hw6/* .make a copy of the starter code to work with, called hw6.cppe.g., cp hw6_start.cpp hw6.cppOr download the files onto your local computer using the link on the website. Make a copy of the starter code to work with and call that new file hw6.cpp.Your next step is to implement the Ledger class using the descriptions of the expected methods above. Once you have implemented each method, write the code to test your new method. Use an abundance of debugging statements (cout information so that you can see what your code is doing). Pay attention to which variables are pass-by-reference and which ones are pass-by-value. You should also take care to notice which methods change variables in the object (aka the class) and which do not (you should use “const” in the method headers of your accessor methods!).3. ImplementationYou should incrementally implement each method of the Ledger class one at a time, compiling, running, and testing each method before continuing onto the next step. After you implement a method, call it in the main program to test it. Begin by testing the given sample code which contains the default constructor and print method.Your main program will probably be pretty short. It should create a new Ledger object, read the data in from the file (readFile), print the contents of the populated array to the screen (printContents), and create a text file containing information about Jessie’s profits and the numbers of each crop she planted (generateStats). You should use “JessiesAccount.txt” as your example file as you are implementing this class. Note that there are two entries in it that will not be added to the class when the file is read (lines 7 and 10) due to invalid input.Please note that you will receive more credit for a subset of the methods that work correctly rather than for code that attempts all methods but is poorly implemented.4. TestingYour program must run using g++ on Turing. Test your program with a variety of inputs to check that it operates correctly for all of the requirements.OnlineGDBIf you would like to design and implement your code on OnlineGDB first, you can create multiple files by clicking the upper left hand button on the screen and providing the name of the file. You will need to create three files in addition to your main.cpp file (Ledger.h, Ledger.cpp, and JessiesAccount.txt). When you run your code on OnlineGDB, pressing the green run button will compile all files at one time.If you aren’t sure how to compile or execute your code, go the class website -> Lab Assignments -> Online GDB Tutorial for help.You must be able to run your code on Turing, so you will need to transfer your files from your local computer to Turing. There are a few ways to accomplish this. First, log into Turing using:ssh username@turing.csce.uark.eduChoose one of the following options. There are more details available in the technology guide linked from the class website.Copy and pasteSecure copy using the scp command (Linux and macOS only)File transfer using software like FileZillaTuringIf you would like to work directly on Turing, you will need to create and edit multiple files (you can use “vi”, “emacs”, or “nano” for editing). Make sure that all of your files reside in the same directory. You will need to specify every file name that you want to compile in the same g++ statement.To compile:g++ -Wall hw6.cpp Ledger.cpp -o hw6.exeTo run:./hw6.exeTypescriptYou must submit a typescript of your project running on Turing. A typescript is a log file that contains a copy of all of your terminal text that demonstrates your program running. You will type “script” to start the typescript, and “exit” to finish. The following will generate a typescript of your program outputs, including a look into what is printed into your output file:username@turing:~$ script homework6.txtusername@turing:~$ g++ -Wall hw6.cpp Ledger.cpp -o hw6.exeusername@turing:~$ ./hw6.exeusername@turing:~$ more stats.txt (<-- this will be whatever the name of your output file is)username@turing:~$ exitYou can transfer your files (.cpps, .h, and typescript) from Turing to your local computer using one of the techniques mentioned above. 5. 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 files. For full credit, you need to submit the following items:Two C++ (.cpp) files: One for the Ledger class implementation and one for the main methodPlease do not submit code in .docx, .txt, or any other format aside from .cpp!One Header (.h) file: the file that declares all private and public variables and methods for the Ledger class.A project report in .docx or .pdf format following the template on the course website.One typescript file that includes the compilation of your .cpp files, as well as running the program with multiple tests (if necessary).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.Sample Output – stats.txt fileCongrats Farmer Jessie - your farm is doing fantastically!Your average profit is $1562.20And you planted the following:Potato:2Beet:3Pumpkin:2Wheat:3You can still plant 5 fields for more profit! ................
................

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

Google Online Preview   Download