Comp 220 ilab 7 of 7
Upcoming SlideShare
Loading in...5
×
 

Comp 220 ilab 7 of 7

on

  • 143 views

This lab introduces students to the concepts of polymorphism, early binding, late binding, abstract classes, and virtual class functions. This will be done in the context of performing calculations on ...

This lab introduces students to the concepts of polymorphism, early binding, late binding, abstract classes, and virtual class functions. This will be done in the context of performing calculations on basic geometrical shapes. Polymorphism is a very powerful extension of inheritance, and by using pointers to the base class, it allows access to derived class objects and their functions based on the context that they are called in.
The lab will require the creation of a base geometric class, called Shape, and two sub classes, Circle and Rectangle, that are derived public from the class Shape. From there, objects of both the Circle and the Rectangle classes will be created, as will an array of pointers to the base class Shape. By using the instantiated objects and the object pointers, both static and dynamic binding will be demonstrated.
Deliverables
1. Submit a single NotePad file containing the source code for all the lab files to the Week 7 Dropbox. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_Lab5.txt.
Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes.

Statistics

Views

Total Views
143
Views on SlideShare
143
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Comp 220 ilab 7 of 7 Comp 220 ilab 7 of 7 Document Transcript

  • HELPIDO.COMCLICK HERE TO GET THE SOLUTION !!!!!!!!COMP/220 iLab 7 of 7 - C++ CourseiLab 7 of 7: PolymorphismiLAB OVERVIEWScenario and SummaryThis lab introduces students to the concepts of polymorphism, early binding, late binding, abstractclasses, and virtual class functions. This will be done in the context of performing calculations onbasic geometrical shapes. Polymorphism is a very powerful extension of inheritance, and by usingpointers to the base class, it allows access to derived class objects and their functions based on thecontext that they are called in.The lab will require the creation of a base geometric class, called Shape, and two sub classes, Circleand Rectangle, that are derived public from the class Shape. From there, objects of both the Circleand the Rectangle classes will be created, as will an array of pointers to the base class Shape. Byusing the instantiated objects and the object pointers, both static and dynamic binding will bedemonstrated.Deliverables1. Submit a single NotePad file containing the source code for all the lab files to the Week 7Dropbox. Your source code should use proper indentation and be error free. Be sure that your lastname and the lab number are part of the file name: for example, YourLastName_Lab5.txt.Each program should include a comment section that includes, at a minimum, your name, the laband exercise number, and a description of what the program accomplishes.2. Submit a lab report (a Word document) containing the following information to the Week 7Dropbox.o Include your name and the lab or lab exercise number.o Specification: Include a brief description of what the program accomplishes, including itsinput, key processes, and output.o Test Plan: Include a brief description of the method you used to confirm that your programworked properly. If necessary, include a clearly labeled table with test cases, predicted results, andactual results.
  • o Summary and Conclusions: Write a statement summarizing your predicted and actual output,and identify and explain any differences. For conclusions, write at least one nontrivial paragraph thatexplains, in detail, either a significant problem you had and how you solved it or, if you had nosignificant problems, something you learned by doing the exercise.o A UML Diagram: This should show all the classes, class members, access specifiers, datatypes, and function arguments, along with all of the class-to-class relationships.o Answers to Lab Questions: Include the answers to all the lab questions that are asked in thelab steps.Each lab exercise should have a separate section in the lab-report document.Your lab grade is based upon1. the formatting of your source code;2. the use of meaningful identifiers;3. the extent of the internal documentation;4. the degree to which an exercises specifications are met; and5. the completeness of your lab report.iLAB STEPSSTEP 1: Create a New Multifile ProjectCreate a new multifile project with three classes: the base class Shape, the class Circle (derivedpublic from Shape), and the class Rectangle (derived public from Shape). The classes will have thefollowing requirements.1. The class Shape should be an abstract class with the following pure virtual functions.a. area()b. perimeter()2. The class Circle should be derived public from the class Shape and override both the area()and the perimeter() functions.a. The perimeter() function should correctly calculate the circumference of a circle, given aradius.b. The area() function should correctly calculate the area of a circle, given a radiusc. Include all the necessary accessor and mutator functions to accomplish the requirements ofthe class.3. The class Rectangle should be derived public from the class Shape and override both thearea() and the perimeter() functions.a. The perimeter() function should correctly calculate the circumference of a rectangle, given itsdimensions.
  • b. The area() function should correctly calculate the area of a rectangle, given its dimensions.c. Include all the necessary accessor and mutator functions to accomplish the requirements ofthe class.STEP 2: Create the Test FunctionInstantiate at least one object of each of the Circle and the Rectangle classes. Provide appropriateconstructors for both that will accept the necessary initialization arguments to provide theinformation required for all the class member functions. Exercise and test each member function ofboth classes for correct calculations and output.STEP 3: Add a Base Class Pointer Array and an Additional FunctionAdd to the test function a base class array of pointers of the same dimension as the total number ofCircle and Rectangle objects that were created in the previous step. Use this pointer array to accessthe Circle and the Rectangle objects to call a new, nonclass member function that will display all theinformation about each object.1. Circle objects should display radius, circumference, and area.2. Rectangle objects should display dimensions, perimeter. and area.The information-display function should accept as its calling parameter a pointer of the class Shape.Run the test function to demonstrate static (early) binding using the derived class objects callingtheir member functions, and run the test function to demonstrate dynamic (late) binding using theassigned Shape class pointers to call the nonclass, member-display-information function.CLICK HERE TO GET THE SOLUTION !!!!!!!!