讲解:C++ Assignment 1Matlab

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! JNOTE: 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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,294评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,493评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,790评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,595评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,718评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,906评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,053评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,797评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,250评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,570评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,711评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,388评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,018评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,796评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,023评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,461评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,595评论 2 350

推荐阅读更多精彩内容