Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. BIT 2400 Sample Midterm
  2. Unfortunately I don't have a sample midterm that I can just use this term. Thus I need to frantically create one myself. Fortunately, I don't have to worry about cascading errors on a sample midterm (on an exam, I can't have you lose all your points for a small mistake at the beginning) and thus I don't need to give a ton of sample code.
  3.  
  4. The questions are representative, it is designed to take approximately 80 minutes, and it covers most course content. However, since I couldn't use existing sample exams....well it looks terrible. You'll have to supply your own paper.
  5. Hard rule: study and THEN do the sample exam. Do not study based on the sample exam. The questions will be different, even if the spirit of the questions is the same.
  6. Questions should be answered on paper not on a computer. Human memory and learning is correlation based. If you study on paper; you have an easier time answering on paper (seriously. It's called associative memory and state dependent memory). I had a batch of students screw up their exams one year because they only typed the entire term and then had to write with a pen. It's not just hand cramps; you won't work at 100%.
  7. Give approximately 1 minute per point.
  8. Your job is not to be right; it's to communicate how right you are. Thus show your work.
  9. Time yourself and do this under exam conditions to make sure you are ready.
  10. For the love of all that's holy: read the questions. I will warn you now: the actual exam requires you to read a lot (since I have to provide some code to simplify problems)
  11.  
  12. Question 1: Class Definition (20 points)
  13. Define a class Grocery that represents items you can pick up at the grocery store.
  14. Each item has a char * name, an integer number of units and a price per unit (float).
  15. All member variables should be private and you need to write getter and setter methods for each variable.
  16. You should also make a Grocery constructor and destructor. The non-empty constructor (if you make more than one) should take in the item's name and price as parameters.
  17. Example: you might pick up a can of soup (3.99 and 4 boxes of cereal at 4.99 each (I have an obsession).
  18. Your Grocery class should also implement a function "totalPrice" that calculates the total price for buying that item. The cereal would return 19.96.
  19. Implement a printInfo function that has a void return method and prints out information about the item (name, the units, price per unit, and total cost.
  20.  
  21. Question 2: Tests and Taxes (20 points)
  22. Write a function (groceryTax) that takes an array of Grocery object pointers and the array size as parameters. The function will then calculate the total taxes. Let's presume the tax rate is 15%. You would need to find the total cost of all groceries and then the taxes would be 15% of that amount.
  23. Declare an array of Grocery objects (this may include GroceryW objects from the next section) to test.
  24. Write a series of at least 3 tests to evaluate if groceryTax works as expected. Tests could be asserts or they could be something like "bool test1 = (groceryTax(groceryArray) == 49.52564)".....don't worry about the basic math. So (0.15 * 157) would be ok for the expected taxes on a $157 grocery bill.
  25. Question 3: Gaining Weight (20 pts)
  26. Next, extend the Grocery class by making a child class called GroceryW. The W stands for weighed. This would be items like bananas or deli items. A GroceryW object "number of units" (from the main Grocery class) is always 1 but a GroceryW has a float weight member variable. Thus bananas might have a weight (pounds) of 2.1 and the price would be per pound. Also notice that I need new getter and setter functions plus printInfo and totalPrice also need to change.
  27.  
  28.  
  29. Question 4: Debugging (15 pts)
  30. The code below defines the ShoppingCart class (defined in-file rather than using a .h and a .cpp) The code contains at least 3 errors (bugs, memory leaks, logic errors, not error checking etc). Some of the problems are very sneaky and are not visible on the page. Think about how ShoppingCart would be used.
  31.  
  32. Circle each error you find and then annotate (write next to the error) what the fix would be.....please ignore my lack of comments. This was done in a rush. All my functions should have a function header.
  33.  
  34. /*
  35. The ShoppingCart class allows you to group all your groceries together
  36. For this simple example you just store all the groceries up to size 40;
  37. */
  38. class ShoppingCart
  39. {
  40. // Since each Grocery item can have a unit number or weight, numUnique
  41. // is the number of elements in the Grocery array
  42. Grocery* a_groceries;
  43. int numUnique;
  44. int maxElements;
  45.  
  46. ShoppingCart()
  47. {
  48. maxElements = 40;
  49. a_groceries = new Grocery *[maxElements];
  50. numUnique = 0;
  51. }
  52.  
  53. int addItem(Grocery* groc)
  54. {
  55. a_groceries[numUnique] = groc;
  56. numUnique++;
  57. return numUnique;
  58. }
  59.  
  60. Grocery* getItem(int idx)
  61. {
  62.  
  63. return a_groceries[idx];
  64. }
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement