Introduction1、 编译方式参考截图命令行输入 make 完成编译2、 运行方式参考截图命令行输入./ShopList3、 测试例子说明顺序以及每步的操作意义参考截图文件名大致过程,在list中添加item 2个 apple,然后再添加3个apple,然后添加第二种物品egg(单位:dozen),然后添加第三种物品egg(单位:box),然后删除4个apple,然后删除1个apple,最后退出设计思路要点:Item类:构造函数:除了含有参数的构造函数外,为了能让List中能够用new开辟动态数组,所以需要写一个无参数的构造函数重载==:用来判断是否是同种物品,判断的依据是:物品名,单位,单价均相同,因为有可能物品名相同但单位不同,也可能物品名单位均相同,但单价不同,这两种情况其实都是不同的物品,所以要判断三个量都要相同Add,Remove:用来在物品数量少进行加减,主要是用来配合List中的Add和Remove,其中加(Add)没有返回值,减(remove)有一个布尔值的返回值,返回真(true)表示减完之后还有剩余数量,返回假(false)表示减完之后没有剩余数量(就是指全部删完)Copy:用来将某一个Item对象的属性复制到当前对象中,用来list中item对象的赋值以及大小调整时item数组的赋值操作。Print:对单个Item对象进行输出,用来配合list的整个Item数组的输出List类:Count表示实际存储的item对象的数量Size表示item动态数组开辟的空间(也就是最多存多少个item)Array用来存储item类的动态数组,但继续添加会导致Count大于size时需要重新开辟更大的空间并释放原来的空间构造函数:只需要一个无参数的构造函数,这里需要建立一个默认大小的动态数组,然后将Count的初值赋为0(因为一开始数组中并没有存储任何item)析构函数:需要手动释放array数组中的空间Add:添加item,需要在array中寻找是否有同类型的物品,如果有只要调用item类的add函数来修改数量,没有的话则需要在array数组中添加一个元素,这时需要判断count和size的关系,如果count会超过size,那么就表示动态数组的空间不够,那么就需要重新申请一个更大的空间,然后将现在array中的内容移到新的空间中,然后释放旧的array,用新的动态数组取代替arrayRemove:删除item,同样需要在array中寻找相同类型的物品,找到后调用item类的remove函数,这时如果将item的数量扣光,就表示这个物品已经没有了,那么需要将这个item从动态数组中移出,具体方法就是将数组后面的物品移到前面一位,然后count总数减一RequirementAssignment 2 –Arrays and ClassesYou will submit a reflections document with every assignment. This is you chance to explain whyyou did what you did. Or why something you tried didn’t work. You can explain what you did to testyour program to make sure it works. You can also document features or bugs that inhibit the programin some way.You need to design, implement, and test a grocery shopping list program. The program should maintainand display a list of items.You will use a class for the Items. The class should have data elements for the followinginformation: item name, unit (i.e. can, box, pounds, or ounces), number to buy, and unit price. Doyou need any functions other than the constructor(s)? How do you calculate the extended price for theitem (number to by times unit price? How do you print it to the screen?You will also need a List class. The List class will use a dynamic array to store Item objects. Aseach item is entered an Item object must created and added to the array. What do you do if the array isfull? One List object will have many Item objects. Do you need a print function in this class?Your program must perform. the following activities: create a list, add items, remove items, anddisplay the shopping list. To add an item you should prompt the user to enter the name, unit of sale, thenumber needed, and the unit price. The display should show: for each item in the list, the number ofitems, the unit of sale, the unit price, the extended price for each item. Then the total price for all items.Oregon doesn’t have a sales tax so you can ignore that. J Debug and test your program.Once you have the List and Item classes workiC++代写 Assignment 1代做留学生Matlab实验作业ng correctly, test if an item is already in your List beforeadding it. Overload the == operator to perform. the test. There is a simple example to overload thisoperator in the book. Keep it simple. How will you compare items? You can assume that the user willtype the information in correctly. If the item is already in the list give the user the option to add the newquantity to the existing Item object.You must create a design document. It should include the design of the classes and how you will use theclasses. Remember to free memory if no longer used. Figure that out, before you start coding. If youdo the design properly the coding should be easier.Your reflections document should include the design document, the testing results, and describe anychanges you made to your original design.You will provide a simple test plan. Since this is a program with input and output you should not needany driver functions. You do NOT need to test for every possible item in a grocery store, just areasonable number or varying lengths. How do you handle spaces in names? Are the extended pricescalculated correctly? Is the total amount correct?NOTE: For testing please keep your array small, maybe only 4-5 elements. There is no orderingrequirement so if you can ad 2-3 Items and remove one there is not much more to test. To test resizingyou (and the grader) will need to insert only a few items into the list. It saves time for everyone! JNOTE: Please use incremental development! Start with the List class and maybe a simplified Itemclass (only the item name?). If you’re not comfortable with dynamic arrays start with a static array. Justremember to replace it later. Plan this out as part of your design. You will probably need to print thelist early on so you can see what’s going on inside the list and the items. When you have a (partial)program that compiles and runs properly save a copy!You must include a makefile and put all files for your assignment in a zip file. If you do not do thisassignment will NOT be graded.Grading:• programming style. and documentation (10%)• create the list class and object (15%)• create the item class and objects (10%)• add and remove items to the list (10%)• you properly manage memory, i.e. NO leaks (5%)• when adding a duplicate item you offer to combine the quantities(5%)• your array resizes properly (5%)• Display the list to include the following: item name, unit for purchase, price perunit, number to buy, extended price for that item. Then at the bottom of thedisplay indicate the total cost for that trip to the store. (15%)• overload the equality operator (==) to prevent including duplicate items in theshopping list (10%)• reflections document to include the design description, test plan, test results, andcomments about how you resolved problems while designing and implementingyour program (15%)转自:http://ass.3daixie.com/2019030627560473.html
讲解:C++ Assignment 1Matlab
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- By clicking to agree to this Schedule 2, which is hereby ...
- 方法一 我们在文件管理器窗口中打开有问题的盘,然后点击上面的“查看”菜单 在打开的查看工具栏上点击“选项”按钮 这...