Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 10th, 2013  |  syntax: None  |  size: 5.54 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. INSTRUCTIONS
  2. In this assignment you will create and use a set of classes to draw basic shapes for a quiz on area and
  3. perimeter. You will implement these classes:
  4.  
  5. • QuizShape
  6.  
  7. o Members
  8.  
  9. ▪ A border character, a char
  10.  
  11. ▪ An inner character, a char
  12.  
  13. ▪ A quiz label, a string
  14.  
  15. • Rectangle
  16.  
  17. o A Rectangle is a QuizShape
  18.  
  19. o Members
  20.  
  21. ▪ A quiz label
  22.  
  23. ▪ A border character
  24.  
  25. ▪ An inner character
  26.  
  27. ▪ Height, an integer
  28.  
  29. ▪ Width, an integer
  30.  
  31. •   Height and width must both be greater than 3 or greater. If a value less than 3 is passed in,
  32. set to 3.
  33.  
  34. •  Square
  35.  
  36. o A Square is a Rectangle
  37. o Members
  38.  
  39. ▪ A border character
  40.  
  41. ▪ An inner character
  42.  
  43. ▪ A quiz label
  44.  
  45. ▪ A Height and Width.
  46.  
  47. •   Remember, a square must always be square. The height and width should always be equal. Never
  48. allow a square with unequal sides. You will need to address this in the constructor.
  49.  
  50.  
  51. • DoubleSquare
  52.  
  53. o A DoubleSquare is a Square
  54. ▪ Two squares of the same size are drawn separated by spaces. See the sample run.
  55.  
  56. o Members
  57. ▪ A border character
  58.  
  59. ▪ An inner character
  60.  
  61. ▪ A quiz label
  62.  
  63. ▪ A Height and Width.
  64.  
  65. •   Both squares use the same height and width values
  66.  
  67. •   Remember, a square must always be square. The height and width should always be equal. Never
  68. allow a square with unequal sides. You will need to address this in the constructor.
  69.  
  70. Use the principles of inheritance to minimize the amount of code you actually write. If a base
  71. class already does something, the derived class should not reinvent the wheel. Each class should
  72. define or have access to:
  73.  
  74. •   One constructor has parameters for every member variable the class can access. Call parent
  75. constructors when appropriate.
  76.  
  77. •   void draw();
  78.  
  79. o The shape is drawn using its border character and its inner character. For example, a rectangle
  80. with a width of 10, a height of 5, and a border character ‘+’, and a inner character ‘.’ would be
  81. drawn like this:
  82.  
  83. ++++++++++
  84. +........+
  85. +........+
  86. +........+
  87. ++++++++++
  88. o Note: when drawing a square, it won’t look like a square due the font in the window uses
  89. when you run your program. As long as it has the correct number of border characters and
  90. inner characters, we are going to call it a square.
  91.  
  92. •  int getArea();
  93.  
  94. o Returns the area of the shape
  95.  
  96. • getPerimeter();
  97.  
  98. o returns the perimeter of the shape
  99. •   getters for each data member the class knows about
  100.  
  101.  
  102. Setting up your code.
  103.  
  104. •   In shape.h, define the classes and the prototypes for all methods and constructors in each
  105. class.
  106.  
  107. o The order in which you define the classes will matter
  108.  
  109. o IMPORTANT: Add these three lines, exactly as written, to the public section of the QuizShape
  110. class:
  111.  
  112. virtual void draw( ) = 0;
  113. virtual int getArea( ) = 0;
  114. virtual int getPerimeter( ) = 0;
  115.  
  116. •   In shape.cpp, implement all the methods and constructors that are defined in shape.h
  117.  
  118. o IMPORTANT: Do not write any code in shape.cpp for draw( ), getArea ( ), and getPerimeter ( ) for
  119. the QuizShape class.
  120.  
  121. o Implement for draw( ), getArea ( ), and getPerimeter ( ) for Rectangle, Square, and DoubleSquare
  122. as needed.
  123.  
  124. o Implement getters as needed in all classes
  125. •   In pass7.cpp
  126.  
  127. o Implement the following function
  128.  
  129. void quizUser (QuizShape &shape);
  130.  
  131. This function should display the label of the shape, draw it, and have the user guess its area and
  132. perimeter. Tell them if they are correct or if they need to work on their geometry skills (in a
  133. polite way, of course)
  134.  
  135. o main()
  136.  
  137. ▪ Main should create a sample of each shape and pass it to the quizUser() function.
  138.  
  139. ▪ When creating the labels for each shape, add the dimensions to the label name. For example, the
  140. label for a Rectangle that is 10 height and 5 wide would be “5x10 Rectangle”
  141.  
  142. ▪ Do not cout anything in main(). It should just create shapes and pass them to quizUser().
  143.  
  144. Notes
  145.  
  146. •   It is ok to define multiple classes in one .h file. Programmers often do this to group related
  147. classes.
  148. Same goes for .cpp files.
  149.  
  150. •  No main() in shape.cpp.
  151.  
  152. •  The lines like this:
  153.  
  154. virtual void draw( ) = 0;
  155.  
  156. are how we define “pure virtual functions”.  This is C++’s way of saying a class knows about a
  157. function, without the function actually existing. See section 15.7 in the book and be sure to ask
  158. your instructor for tips and clarification.
  159.  
  160. Think of it this way: What is the area and perimeter of a QuizShape? Not a Rectangle, or Square,
  161. but a QuizShape? There isn’t one, is there. A QuizShape is a basic idea, an abstract idea. A
  162. Rectangle is a concrete idea. A QuizShape can define the fact that all shapes have an area and a
  163. perimeter, and can be drawn, but it can’t actually do any of that itself. Pure virtual functions
  164. are what allow us to accomplish this in C++.
  165.  
  166. Sample Run
  167. Your output should look similar to the following. Things in bold are typed by the user.
  168.  
  169. Welcome to the Shape Quiz The Shape: 5x7 Rectangle
  170. +++++++
  171. +.....+
  172. +.....+
  173. +.....+
  174. +++++++
  175. What is the total area? 35
  176. Congratulations! You are correct What is the total perimeter? 24
  177. Congratulations! You are correct
  178.  
  179.  
  180.  
  181. The Shape: 4x4 Square
  182. ****
  183. *--*
  184. *--*
  185. ****
  186. What is the total area? 16
  187. Congratulations! You are correct What is the total perimeter? 12
  188. Sorry :-( The correct answer is 16 The Shape: Two 3x3 Square
  189. +++   +++
  190. +.+   +.+
  191. +++   +++
  192.  
  193.  
  194. What is the total area? 9
  195. Sorry :-( The correct answer is 18 What is the total perimeter? 24
  196. Congratulations! You are correct
  197. Thanks for quizzing with us!
clone this paste RAW Paste Data