Assignment 6: Object-Oriented Programming with Shapes - Classes and Encapsulation, Study notes of Object Oriented Programming

Assignment 6 for the cosc 051 course, which focuses on object-oriented programming using classes to encapsulate shape data and methods. Students are required to refactor their software from assignment 5, providing functions to set shape properties, draw, and animate shapes. Classes should include appropriate comments, and methods must specify return types, inputs, outputs, and assumptions. Students must also provide a technique to copy one shape object to another, either through a copy constructor or overloading the = operator.

Typology: Study notes

2021/2022

Uploaded on 08/01/2022

fabh_99
fabh_99 🇧🇭

4.4

(53)

543 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1"
"
COSC$051$($Assignment$6$(Shapes$Option)$
Classes$and$Object$Oriented$Programming$
"
For"this"assignment"you"are"requested"to"refactor"the"software"you"wrote"for"Assignment"5.""
You"will"use"a"class"to"encapsulate"all"relevant"data"items"and"methods"that"represent"a"
shape"(line"and"circle)."""
$
In"general,"your"class"definition"should"include"all"of"the"functions"that"set"shape"
properties,"drew,"and"animated"your"shapes"in"the"previous"project.""Your"class"definition"
should"include"appropriate"comments.""At"a"minimum,"the"comments"must"specify"the"
following:"
"
C The"return"type"for"each"method"
C Input(s),"output(s),"and"any"assumptions"for"each"method"
C A"description"of"the"class'"public"interface"
"
Any"class"methods"that"do"not"modify"internal"class"variables"must"be"defined"as"const"
methods."
"
All"class"data"members"must"be"private.""Consequently,"only"class"methods"can"modify"class"
data"members."
"
Your"program"must"provide"a"technique"to"copy"one"shape"object"to"another"shape"object"
of"the"same"class.""One"way"to"accomplish"this"is"with"a""copy"constructor";"so"you"must"
provide"one"in"your"classes.""The"coding"fragment"below"demonstrates"how"a"copy"
constructor"can"be"used"in"your"program."
"
CircleType myCircle2(myCircle1);
"
This"example"assumes"that"CircleType"is"the"class"name"and"that"myCircle1"is"a"
previously"instantiated"CircleType"object.""The"declaration"of"myCircle2"as"shown"
above"will"instantiate"a"new"CircleType"object"with"data"values"copied"from"
myCircle1."
"
Additionally,"and"for"extra"credit,"you"may"overload"the"="operator"to"work"as"follows:"
"
CircleType myCircle1;
// do stuff here to set center coordinates
//and radius for myCircle1
CircleType myCircle2;
myCircle2 = myCircle1; //copies myCircle1 data to myCircle2"
"
" "
pf2

Partial preview of the text

Download Assignment 6: Object-Oriented Programming with Shapes - Classes and Encapsulation and more Study notes Object Oriented Programming in PDF only on Docsity!

COSC 051 -­‐ Assignment 6 (Shapes Option) Classes and Object Oriented Programming For this assignment you are requested to refactor the software you wrote for Assignment 5. You will use a class to encapsulate all relevant data items and methods that represent a shape (line and circle). In general, your class definition should include all of the functions that set shape properties, drew, and animated your shapes in the previous project. Your class definition should include appropriate comments. At a minimum, the comments must specify the following: -­‐ The return type for each method -­‐ Input(s), output(s), and any assumptions for each method -­‐ A description of the class' public interface Any class methods that do not modify internal class variables must be defined as const methods. All class data members must be private. Consequently, only class methods can modify class data members. Your program must provide a technique to copy one shape object to another shape object of the same class. One way to accomplish this is with a "copy constructor"; so you must provide one in your classes. The coding fragment below demonstrates how a copy constructor can be used in your program. CircleType myCircle2(myCircle1); This example assumes that CircleType is the class name and that myCircle 1 is a previously instantiated CircleType object. The declaration of myCircle 2 as shown above will instantiate a new CircleType object with data values copied from myCircle 1. Additionally, and for extra credit, you may overload the = operator to work as follows: CircleType myCircle1; // do stuff here to set center coordinates //and radius for myCircle CircleType myCircle2; myCircle 2 = myCircle1; //copies myCircle 1 data to myCircle 2

You may choose which functions from Assignment 5 to include as methods in your class. However, you must include as many methods as necessary to instantiate shape objects, set object properties, draw objects on screen, and animate objects. All functionality must be provided through class methods. Your program must instantiate and animate objects according to the following criteria:

  • Display at least two shapes simultaneously on screen
  • Animate at least one of the on-­‐screen shapes
  • Remove one shape from the screen while continuing to display other(s)
  • Use the following coordinates as the starting points for lines Start Point End Point x 1 y 1 x 2 y 2 40 3 60 3 68 3 68 12 49 20 70 10
  • Use the following values as the starting coordinates for circles Center Radius x y 43 9 4 43 8 8 58 16 5 Early submissions are encouraged. Program due date is Wednesday, December 7 , 2011 at 11:59 pm. Extensions to the program due date will not be granted for this assignment. Please plan appropriately. This graded assignment is worth 100 points and will be counted as part of your programming grade for the course. Extra credit worth up to 1 0 points is possible for overloading the = operator as described above. The points breakout is as follows: 50 Class definition and member declaration 15 Line drawing and animation 15 Circle drawing and animation 10 Programming style, etc. 10 Turn in on time. 10 Extra credit The product that you submit must be your own work. Collaboration is allowed as specified within the syllabus for this course. For this assignment, you are not required to submit an acknowledgement statement.