CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 11 Introduction Due Date: Friday, April 23, 2021 before 11:55pm. Submission: Your final submission for each part of...

1 answer below »
Just the homework with some extra files



CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 11 Introduction Due Date: Friday, April 23, 2021 before 11:55pm. Submission: Your final submission for each part of the homework will be a single file: hw11A.cpp for part A and hw11B.cpp for part B. Each will be submitted on a different link on gradescope. Grading: Grading for this homework will be fully automatic through the tests on gradescope. Part A and Part B both have provided code with a section that cannot be modified. So the tests will first check that the file is not modified, and only if the main functions are unmodified will the tests run as normal. Some test results will not be shown to you in advance, and will only be revealed after the deadline. All tests, however, will only test the behavior that is described in this document - So if you solve the problem described here you should be fine. Instructions: This is an individual homework assignment. There are two problems, each worth 20 points. Solve the problem below by yourself (unlike the labs, where you work collaboratively), and submit the solution as a C++ source code file. Some Rules/guidelines: 1. This is an individual assignment Unlike the lab assignments, this is not collaborative. You must design, implement, and test the solution to each problem on your own without substantial assistance from anyone other than the course instructor or TAs. 2. You may not include code, solutions, or portions of solutions from any external source. You are only allowed to use sources that are part of class: examples from the textbook, lectures, or code you and your partner write to solve lab problems. Using code obtained in other ways, or letting others view or use your code is considered academic misconduct. For more information, see the collaboration rules file on the class website, or ask the instructor or TAs if you have any questions on what is and is not allowed. 3. Because this homework is submitted and tested electronically, and automatically, the fol- lowing are more important than in a typical class. Failure to follow these instructions can result in a grade of 0. • Follow the naming conventions mentioned at the end of the problems. • Files must be submitted before the deadline or they will not be accepted. • Files must be submitted to gradescope. Emailing the course staff will generally not count as a submission. (although this is an OK way to request assistance if gradescope is refusing to accept your files) • The input and output formats listed in the problem description, and demonstrated in the examples, are not suggestions. Follow the provided input and output format exactly, and to the letter. (Remember that spaces and end-of-lines count as letters too!) 1 • Regardless of how or where you develop your solutions, we expect your programs to compile and execute on gradescope. It is not enough for them to run on your computer. Course staff can help you test in more detail if you have errors on gradescope, but no errors on your computer. • The problem descriptions will usually show at least one test case and the resulting correct output. However, you should test your program on other test cases (that you make up) as well. Making up good test cases is a valuable programming skill, and is part of ensuring your code solution is correct. 2 Problem A: Grocery shopping (20 points) In this program you will be building a GroceryList class that simulates checking out at a grocery store. Your class will support adding items to the grocery list (think of scanning an item at the checkout), as well as a function that will get a receipt (an array of strings listing each distinct item that was checked out, and how many times that specific item was added.) Start with the checkout.cpp file provided on canvas. Without changing the provided main function, write a c++ class that works with the existing main() function that simulates checking out at a grocery store. You will want to carefully consider what functions are needed for the provided main class to work. Ensure that you class makes the provided main() output match the examples ex- actly. The add() function should add a checkout item to the items being bought, either increasing the amount by one if the item is already present or adding it to the list if it is new. You may directly compare strings when adding, thus if the string is different at all it can be treated as a new item. The checkout() function should return a list of all items and their quantities, along with a final additional line saying how many items were bought. Note that the item bought is the sum of the quantities, not the amount of different types of items on the list. The order that you display the items is not important (but the order the examples use is probably the easiest to do). Some assumptions you can make to simplify this problem: 1. You can assume fewer than 200 items will be checked out. 2. You shouldn’t need to implement a destructor, copy constructor, or assignment operator for this assignment. (one or more non-dynamic arrays will be sufficient) Hints • There are several ways to make the GroceryList class work. • You do not need to limit yourself to only the functions, methods, and classes required to make main work. Writing some helper functions, or even a helper class, can make this problem easier to solve. • An easy way to make a string piece by piece in C++ (such as the receipt string, which contains multiple pieces of information) is to use the overloaded + or += string operators. These operators, with strings, allow you to combine strings. To add a number into a string you will first need to use the to_string function to convert that number into a string. (This function should exist for any reasonably up-to-date C++ version) Example: string x = ""; x += to_string (2); x += "x Apples"; cout < x;="" shows="" "2x="" apples"="" 3="" examples="" example="" 1="" apple="" banana="" apple="" !checkout="" receipt:="" 2x="" apple="" 1x="" banana="" ---------="" total="" items:="" 3="" example="" 2="" apple="" banana="" apple="" checkout="" !checkout="" receipt:="" 1x="" apple="" 1x="" banana="" 1x="" apple="" 1x="" checkout="" -----------="" total="" items:="" 4="" 4="" example="" 3="" pasta="" milk="" pasta="" milk="" rice="" milk="" rice="" milk="" !checkout="" receipt:="" 2x="" pasta="" 4x="" milk="" 2x="" rice="" --------="" total="" items:="" 8="" submission="" when="" you="" are="" done,="" name="" the="" source="" code="" file="" hw11a.cpp.="" then="" log="" into="" gradescope="" and="" upload="" your="" file="" for="" the="" “homework="" 10a”="" submission.="" if="" you="" name="" your="" file="" incorrectly="" it="" will="" be="" unable="" to="" compile="" and="" run="" your="" code,="" so="" you="" will="" fail="" all="" test="" cases.="" you="" may="" submit="" cpp="" files="" as="" many="" times="" as="" you="" want="" until="" the="" deadline="" to="" try="" and="" fix="" the="" code="" if="" you="" fail="" a="" test="" case.="" following="" rigorous="" naming="" conventions="" and="" using="" test="" cases="" are="" something="" computer="" programmers="" often="" must="" do="" in="" “real="" life”="" programming,="" and="" so="" submitting="" your="" program="" with="" the="" correct="" name="" and="" functionality="" is="" part="" of="" doing="" this="" assignment="" correctly.="" 5="" problem="" b:="" spring="" break="" streaming="" in="" this="" program="" we="" will="" build="" a="" simplified="" item="" crafting="" processor.="" this="" might="" be="" helpful="" in="" games="" like="" astroneer="" or="" satisfactory="" where="" basic="" items="" can="" be="" combined="" to="" make="" more="" advanced="" items="" (which="" themselves="" may="" be="" used="" to="" make="" further,="" more="" advanced="" items="" in="" a="" complicated="" technology="" tree)="" your="" program’s="" interaction="" with="" the="" user="" is="" simple,="" first="" it="" should="" prompt="" the="" user="" for="" a="" file,="" then="" it="" should="" read="" the="" file="" itself,="" then="" it="" should="" output="" the="" price="" of="" each="" item.="" the="" real="" work,="" however,="" is="" in="" reading="" the="" file.="" the="" file="" your="" program="" will="" read="" will="" contain="" three="" commands:="" •="" item:="" –="" this="" command="" is="" used="" to="" add="" a="" new="" item="" to="" a="" list.="" it="" will="" provide="" both="" the="" item="" name="" and="" the="" price="" of="" this="" item.="" •="" recipe:="" –="" this="" command="" defines="" an="" item="" that="" is="" built="" from="" other="" basic="" items.="" the="" price="" of="" this="" item="" will="" be="" the="" sum="" of="" the="" individual="" components="" to="" make="" the="" item.="" it="" will="" be="" a="" list="" of="" names="" of="" other="" items="" (already="" defined)="" that="" it="" is="" made="" from.="" •="" change:="" –="" this="" will="" change="" price="" of="" an="" already="" defined="" item="" using="" the="" item:="" command.="" it="" will="" not="" be="" used="" to="" redefine="" recipes.="" this="" will="" provide="" both="" the="" name="" of="" the="" item="" being="" redefined="" and="" the="" new="" price.="" after="" all="" the="" items="" have="" been="" entered,="" for="" each="" “item”="" and="" “recipe”="" show="" the="" price="" to="" get="" this="" item.="" the="" price="" changes="" from="" the="" “change”="" command="" should="" be="" reflected="" on="" both="" the="" simple="" “item”="" and="" in="" the="" “recipes”="" that="" use="" the="" item.="" in="" other="" words,="" the="" change="" in="" the="" price="" should="" effect="" all="" products.="" i="" recommend="" at="" this="" point="" downloading="" the="" provided="" example="" files="" from="" canvas="" and="" reading="" over="" them,="" make="" sure="" you="" understand="" the="" format="" and="" are="" able="" to="" perform="" this="" computation="" on="" your="" own.="" (it’s="" not="" a="" terribly="" complicated="" computation="" for="" small="" files,="" but="" you="" will="" want="" a="" more="" organized="" computation="" to="" allow="" you="" to="" perform="" this="" computation="" for="" big="" files)="" some="" assumptions="" you="" can="" make="" to="" simplify="" this="" problem:="" 1.="" recipes="" will="" only="" be="" used="" from="" simple="" “items”="" (instead="" of="" more="" complex="" “recipes”.="" 2.="" item="" names="" will="" be="" single="" words.="" 3.="" one="" command="" per="" line.="" 4.="" commands="" will="" be="" for="" mated="" as="" in="" the="" file="" (space="" after="" command="" and="" no="" trailing="" space).="" 5.="" “recipes”="" will="" only="" use="" “items”="" that="" have="" already="" been="" defined.="" 6.="" “change”="" will="" only="" modify="" “items”="" that="" have="" already="" been="" defined.="" 7.="" recipes="" will="" not="" be="" more="" than="" 50="" items.="" 8.="" there="" will="" not="" be="" more="" than="" 500="" commands="" in="" the="" file.="" 9.="" products="" (both="" “items”="" and="" “recipes”="" are="" unique.="" in="" other="" words,="" there="" will="" never="" be="" two="" products="" with="" the="" same="" name.="" 6="" hints="" •="" it="" might="" be="" useful="" to="" think="" about="" how="" you="" want="" to="" store="" data="" and="" handle="" changes="" efficiently="" before="" starting="" this="" part.="" •="" one="" change="" command="" may="" alter="" the="" cost="" of="" many="" items.="" good="" use="" of="" indirection="" (of="" any="" sort)="" can="" make="" this="" easy="" to="" implement.="" not="" having="" a="" plan="" for="" this,="" or="" having="" a="" plan="" that="" makes="" incorrect="" assumption="" about="" how="" variables="" work="" in="" c++,="" will="" make="" this="" problem="" impossible.="" •="" the="" string="" processing="" is="" a="" secret="" hard="" part="" of="" this="" program:="" –="" the="" best="" way="" to="" read="" the="" commands="" file="" is="" line-by-line="" using="" the="" getline="" command,="" this="" is="" because="" (if="" you="" read="" word="" by="" word)="" it’s="" hard="" to="" know="" when="" the="" command="" is="" over.="" –="" you="" will="" probably="" need="" a="" way="" to="" process="" a="" string="" word-by-word.="" one="" way="" is="" to="" use="" the="" istringstream="" class="" (which="" lets="" you="" read="" from="" a="" string="" the="" same="" way="" you="" read="" from="" a="" file.="" example:="" #include=""> #include #include using namespace std; int main() { istringstream line("Recipe: shuriken tape nail nail nail nail"); string command , name , part; line >> command >> name
Answered 2 days AfterApr 21, 2021

Answer To: CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 11 Introduction...

Kshitij answered on Apr 23 2021
144 Votes
c++ 2 assignment apple/1.cpp
c++ 2 assignment...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here