CPSC 122 PA1 – Pet Store C++ Basics Refresher Learner solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

Objectives At the conclusion of this programming assignment, participants should be able to: ● Demonstrate understanding of C++ basics covered in CPSC 121 Prerequisites Before starting this programming assignment, participants should be familiar with C++ topics covered in CPSC 121 including (but not limited to): ● Basic Linux commands ● C++ basics (terminology, syntax, variables, etc.) ● Conditional statements ● Implement loops to repeat a sequence of C++ statements ● Define/call functions ● Perform file I/O ● Work with 1D and 2D arrays ● Include and use the String and Vector libraries ● Demonstrate the software development method and top-down design Overview and Requirements This program will read information about the “inventory” of a pet store from an input file, petstoredata.csv, and output a summary report to an output file, petreport.txt. This program will require reading in and storing the entire contents of the pet store inventory into Vectors, processing the data from those Vectors, and then generating an output text report. Your program will also be required to make use of functions to process the pet data and compute portions of the summary report. Input File Format The input file is in a CSV (comma-separated values) format. You are not allowed to modify the input file from the CSV format. The first line of the file contains the four (4) column header labels: Pet Store, Pet Name, Pet Type, Days at Store. You can assume that the input CSV file will -not- deviate from the 4 column format. Each following row contain data for each of the columns for a variable number of pets. You must be able to read and process ANY number of pets read from a file. That is, your program should work with any number of rows: 7 rows of data (1 row for the header, 7 rows of pet data) as in the example input file, 0 rows, 42 rows, etc. Note: when graded, your program will be tested with a different pet store input file that will follow the same format but will NOT have the same number of rows as the example input file. Required Variables I am not requiring specific variables but I am requiring that you make use of vectors in your solution. Arrays could work but you will need to handle an unknown number of records and we have not yet covered dynamic memory management. You will also need to make use of parallel vectors (see Gaddis Chapter 7.6 Focus on Software Engineering: Using Parallel Arrays ) in your solution. Reminder: you are not allowed to use global variables for your solution. All variables must be within scope of main() or your programmer-defined functions. With that said, here are a few suggested variables you may want to make use of: vector header; vector petStoreNames; vector petNames; vector petTypes; vector numDaysAtStore; vector lineParts; vector uniquePetStoreNames; vector uniquePetStoreNameCounts; stringstream lineToParse; //Hint: you can make use of stringstreams to parse strings based on a token – see the in-class example double averageDaysAtStore = 0; int daysAtStoreSum = 0; bool firstRow = true; bool matchFound = false; int storeMostPetsIndex = 0; int petOfTheMonthIndex = 0; Required Functions I am not requiring specific functions but you will be heavily penalized for not using top-down design (see Gaddis Chapter 1.6 The Programming Process and the Software Development Method sheet attached to this assignment) demonstrating modular programming with the use of functions (see Gaddis Chapter 6 Functions). Below are my suggestions for functions you might include in your top down design process. • Create one (1) function to open both of your input/output files. o I suggest you make it a predicate function which returns the success/failure status to the calling function. o Hint: you must use reference variables. • Alternately, create two (2) functions for opening your files, one for your input file and one for your output file. • Create one (1) function to read in all pet store information instead of having a loop read the data from main. o Hint: you must pass variables by reference (i.e., use “output parameters”). You cannot achieve this task with a return statement. o Hint: note the difference between passing a primitive data type (e.g., an integer) and an array by reference. o Tip: if you are struggling with this function, complete the program by reading the input file in main first and then (after making a backup copy) try to move the segment of code into a function. • Create one (1) function to write all of your data to your output file. o Hint: all of your data should be stored in a number of vectors, you should not be reading from the input file and writing to the output file at the same time. • Create functions for each of your calculations, e.g., one for calculating an average, one for determining which store has the most pets in the data set, one for randomly choosing a pet, etc. o Hint: recall – we strive for loosely cohesive and highly coupled functions, i.e., one task, one algorithm, one function! Specifications The input file pet information in the file consists of: 1. Store name (string: “Fur Get Me Not” is the name of the first pet in the example file below) 2. Pet name (string: “Chris P. Bacon” is the name of the first pet in the example file below) 3. Animal type (string: “pig” is the animal type of the first pet in the example file below) 4. Days in store location (integer: 1 is the number of days the first pet has been at this store in the example file below). o Days in store is guaranteed to be at least 1. o Pets are “moved to a different store” after 100 days.😥 The output of your program has two parts: 1. Status messages displayed to the console. These messages simply let the user know what the program is currently computing (e.g., Processed a pig, “Chris P. Bacon” … 1 day(s) on site at store “Fur Get Me Not”). See the example console output below for the required format and output messages. 2. Pet store summary information written to an output file. Name your output file petreport.txt. See the example output file below for the required format and data. Main tasks: 1. Read all pet inventory information from petstoredata.csv for an unknown number of pets and output the processing information as it is read in from the input file. a. Note that you cannot assume the input file contains a fixed number of records pets! b. You will need to use parallel vectors to keep track of each store name, pet name, pet type, and days at the store. c. Hint: read the input file line by line and then parse each line for the column data. I recommend using getline and stringstream to solve this problem (see in-class examples). 2. Keep track of the following information: a. Unique pet store names, e.g., in the example data we have Fur Get Me Not, Pick of the Litter, For Pet’s Sake. b. Total number of pets in the input file, e.g., in the example data we have 7. c. Pet store with the most pets, e.g., in the example data this is Fur Get Me Not with 3 pets (the remaining have 2 each). d. Number of pets at the store with the most pets, e.g., in the example data Fur Get Me not has 3 pets. e. Pet average days on site across all stores, e.g., in the example data this should calculate to 31. f. Employee pet of the month choice. This should be randomly chosen from all pet data, e.g., in the example data there are 7 pets so you would randomly choose one of the 7 pets. If there were 100 pets you would choose one out of that 100. 3. Write the summary at the end of your output file. Tip: I encourage you to use the software development method to plan out your algorithm to solve this problem and incrementally code-compile-test each portion of your program as you implement it! It may take a little longer at the start but I promise you that it will save you time and headache in the long run! Note: You should not need to use the string function stoi(), stod() or any variants for your solution. I am not going to forbid it but you need to be able to understand and apply techniques used to overcome the issue encountered when switching between the extraction operator ( >> ) and the string getline() function. Bonus (5 pts) Include and CLEARLY LABEL and complete -ALL- six software development (see the document attached to this assignment prompt) steps in your submission. Additionally, include a structure/hierarchy chart (see Gaddis section 1.6 The Programming Process) to your submission as part of step 3 of the software development method. It will be all or nothing extra credit! Incomplete SDM steps, and/or unreadable, incomplete, or missing charts will result in no extra credit. Use the “add another file” option on your submission to upload all additional files. Credit for this bonus requires you explicitly state that you attempted the extra credit. Submitting Assignments 1. Submit your assignment to the Canvas course site. You will be able to upload your three source files (two .cpp files and one .h file) to the PA assignment found under the Assignments section on Canvas. You are REQUIRED to use the three-file format for this submission. Use the “+ Add Another File” link to allow choosing of three files (see reference image below). 2. Your project must compile/build properly. The most credit an assignment can receive if it does not build properly is 65% of the total points. Make sure you include all necessary libraries, e.g. string, ctime, etc. (though this does not mean add every single library you’ve ever used!) 3. Your submission should only contain your three source files (plus any bonus submission files). You may submit your solution as many times as you like. The most recent submission is the one that we will grade. Remember to resubmit all three files if you submit more than once. 4. Submit your assignment early and often! You are NOT penalized for multiple submissions! We will grade your latest submission unless you request a specific version grade (request must be made prior to grading). 5. If you are struggling with the three-file format, I recommend you complete the program in one file and submit that (working) version first, then convert it to the three-file format. A working one-file format program is worth more points than a broken three-file format program! Note: By submitting your code to be graded, you are stating that your submission does not violate the CPSC 122 Academic Integrity Policy outlined in the syllabus. Grading Guidelines This assignment is worth 100 points. Your assignment will be evaluated based on a successful compilation and adherence to the program requirements. We will grade according to the following criteria: • 10 points for variable use and naming conventions • 10 points for demonstration of top-down design and modular programming using functions • 10 points for use of required vectors and random number generation • 10 points for properly reading in csv data • 15 points for correctly calculating main tasks stats • 10 points for correct console output • 10 points for correct file output • 10 points for using the three-file format and guard code • 15 pts for adherence to proper programming style and comments established for the class Example input file (petstoredata.csv) Pet Store,Pet Name,Pet Type,Days at Store Fur Get Me Not,Chris P. Bacon,pig,1 Pick of the Litter,Mary Puppins,dog,17 For Pet’s Sake,Jean-Clawed Van Damme,cat,60 Fur Get Me Not,Jack Meower,cat,24 Fur Get Me Not,Severus Snake,snake,12 For Pet’s Sake,Lame Duck,duck,5 Pick of the Litter,Barktholamew,dog,101 Expected Console Output Processed 4 header columns: Pet Store, Pet Name, Pet Type, Days at Store Processed a pig, “Chris P. Bacon” … 1 day(s) on site at store “Fur Get Me Not” Processed a dog, “Mary Puppins” … 17 day(s) on site at store “Pick of the Litter” Processed a cat, “Jean-Clawed Van Damme” … 60 day(s) on site at store “For Pet’s Sake” Processed a cat, “Jack Meower” … 24 day(s) on site at store “Fur Get Me Not” Processed a snake, “Severus Snake” … 12 day(s) on site at store “Fur Get Me Not” Processed a duck, “Lame Duck” … 5 day(s) on site at store “For Pet’s Sake” Processed a dog, “Barktholamew” … 101 day(s) on site at store “Pick of the Litter” All pet store data processed! Generating summary report… Done! Expected File Output (petreport.txt) NOTE: employee pet of the month choice is -randomly chosen- so your output will not always be the same on the last line. Pet Store CSV Summary Report —————————- Pet Stores: Fur Get Me Not, Pick of the Litter, For Pet’s Sake Total number of pets: 7 Pet store with the most pets: Fur Get Me Not Number of pets at Fur Get Me Not: 3 Pet average days on site across all stores: 31 Employee pet of the month choice: “Chris P. Bacon”