SlideShare a Scribd company logo
CS193P                                                                            Assignment 2A
Winter 2010                                                                    Cannistraro/Shaffer

                      Assignment 2A - WhatATool (Part II)
Due Date
This assignment is due by 11:59 PM, January 20.

 Assignment
Now that we have some Objective-C experience under our belt, we’ll dive into the world of
custom classes and more advanced Objective-C language topics. You will define and use a new
custom class, and learn about Objective-C categories.

We will use the same WhatATool project from last week as our starting point. A few more
sections will be added to the existing structure.

The basic layout of your program should look something like this:

#import <Foundation/Foundation.h>

// sample function for one section, use a similar function per section
void PrintPathInfo() {
	      // Code from path info section here
}

int main (int argc, const char * argv[]) {
    NSAutoreleasepool * pool = [[NSAutoreleasePool alloc] init];

	    PrintPathInfo();                  //   Section   1
	    PrintProcessInfo();               //   Section   2
	    PrintBookmarkInfo();              //   Section   3
	    PrintIntrospectionInfo();         //   Section   4
	    PrintPolygonInfo();               //   Section   6 (No function for section 5)

    [pool release];
    return 0;
}




Testing
In most assignments testing of the resulting application is the primary objective. In this case,
testing/grading will be done both on the output of the tool, but also on the code of each
section.

We will be looking at the following:
1. Your project should build without errors or warnings.
2. Your project should run without crashing.
3. Each section of the assignment describes a number of log messages that should be printed.
   These should print.
4. Each section of the assignment describes certain classes and methodology to be used to
   generate those log messages – the code generating those messages should follow the
   described methodology, and not be simply hard-coded log messages.

To help make the output of your program more readable, it would be helpful to put some kind
of header or separator between each of the sections.



                                            Page 1 of 4
CS193P                                                                            Assignment 2A
Winter 2010                                                                    Cannistraro/Shaffer


Assignment Walkthrough


Section 5: Creating a new class
Create a PolygonShape class. To create the files for the new class in Xcode:

1. Choose File > New File…
2. In the Cocoa section under Mac OS X, select the ‘Objective-C class’ template
3. Name the file PolygonShape.m – Be certain the checkbox to create a header file is also
   checked




Note that your new class inherits from NSObject by default, which happens to be what we want.

Now that we’ve got a class, we need to give it some attributes. Objective-C 2.0 introduced a
new mechanism for specifying and accessing attributes of an object. Classes can define
“properties” which can be accessed by users of the class. While properties usually allow
developers to avoid having to write boilerplate code for setting and getting attributes in their
classes, they also allow classes to express how an attribute can be used or what memory
management policies should be applied to a particular attribute. For example, a property can
be defined to be read-only or that an when an object property is set how the ownership of that
object should be handled.

In this section you will add some properties to your PolygonShape class.

1. Add the following properties to your PolygonShape class

    •  numberOfSides – an int value
    •  minimumNumberOfSides – an int value
    • maximumNumberOfSides – an int value
    • angleInDegrees – a float value, readonly
    •  angleInRadians – a float value, readonly
    •  name – an NSString object, readonly

2. The numberOfSides, minimumNumberOfSides and maximumNumberOfSides properties
   should all be backed by instance variables of the appropriate type. These properties should
   all be synthesized. When a property is “synthesized” the compiler will generate accessor
   methods for the properties according to the attributes you specify in the @property
   declaration. For example, if you specified a property as “readonly” then the compiler will

                                           Page 2 of 4
CS193P                                                                          Assignment 2A
Winter 2010                                                                  Cannistraro/Shaffer

    only generate a getter method but not a setter method.

3. Implement setter methods for each of the number of sides properties and enforce the
   following constraints:

    •  numberOfSides – between the minimum and maximum number of sides
    •  minimumNumberOfSides – greater than 2
    • maximumNumberOfSides – less than or equal to 12

    Attempts to set one of these properties outside of the constraints should fail and log an
    error message. For example, if you have a polygon that is configured with a
    maximumNumberOfSides set to 5 and you attempt to set the numberOfSides property to 9
    you should log a message saying something like:

        Invalid number of sides: 9 is greater than the maximum of 5 allowed

4. Implement a custom initializer method that takes the number of sides for the polygon:

        - (id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min
    maximumNumberOfSides:(int)max;

    Your initializer should set the minimum and maximum number of sides first (to establish the
    constraints) and then set the number of sides to the value passed in.

5. Implement a custom init method (overriding the version implemented in NSObject) which
   calls your custom initializer with default values. For example, your generic -[PolygonShape
   init] method might create a 5 sided polygon with min of 3 sides and max of 10.

6. The angleInDegrees and angleInRadians properties should not be stored in an instance
   variable since they are all properties derived by the numberOfSides. These properties do
   not need to be synthesized and you should implement methods for each of them which
   return the appropriate values. We’re being boring and using regular polygons so the angles
   are all the same.

7. Similarly, the name property should also not be synthesized (nor stored in an instance
   variable) and you should implement a method for it. The name of the polygon should be a
   descriptive name for the number of sides. For example, if a polygon has 3 sides it is a
   “Triangle” A 4-sided polygon is a “Square”
              .                             .

8. Give your PolygonShape class a -description method. Example output from this method:

        Hello I am a 4-sided polygon (aka a Square) with angles of 90 degrees
    (1.570796 radians).

9. In order to verify your memory management techniques, implement a dealloc method and
   include an NSLog statement indicating that dealloc is being called.


Section Hints:
   • You can find a list of names for polygons on the web. Wikipedia has a good one.
    • The formula for computing the internal angle of a regular polygon in degrees is (180 *
      (numberOfSides - 2) / numberOfSides).
    • Remember your trigonometry: 360° is equal to 2π.

                                          Page 3 of 4
CS193P                                                                            Assignment 2A
Winter 2010                                                                    Cannistraro/Shaffer

     • You can use the preprocessor value M_PI for π.

Section 6: Using the PolygonShape class
Write a C function (e.g. PrintPolygonInfo) called by main() that uses your newly created
PolygonShape class.

You will have to add an import statement to the WhatATool.m file:
         #import "PolygonShape.h"

IMPORTANT: In this section, you are expected to use +alloc and –init methods to create the
polygons and the array that they are put into. You must practice correct memory
management techniques of releasing the polygon objects when you are done with them.

1.   Create a mutable array (using alloc/init).

2. Create 3 (or more) PolygonShape instances with the following values:

       Min number of sides          Max number of sides         Number of sides

                  3                               7                      4

                  5                               9                      6

                  9                           12                        12

       When allocating your polygons, use a mixture of vanilla alloc/init then set the properties
       along with using your custom initializer method that takes all of the properties in the
       initializer method.

3. As you create each polygon, add them to the array of polygons and emit a log with the
     polygon’s description. There should be at least 3 descriptions logged.

4. Test the constraints on your polygons. Iterate over the array of polygons and attempt to set
     their numberOfSides properties to 10. This should generate two logs indicating that the
     number of sides doesn’t fall within the constraints (for the first two polygons in the table
     above).

5. Verify that your polygon objects are being deallocated correctly. If you have followed the
     rules correctly with regard to memory management you should see 3 logs from the
     dealloc method of your polygons. If you do not see these logs, review your alloc/init and
     release calls to make sure they are correctly balanced for your polygon objects as well as
     the array you are putting them into. Remember, alloc/init and release work like malloc
     and free in C.




                                             Page 4 of 4

More Related Content

What's hot (13)

PDF
C sharp chap6
Mukesh Tekwani
 
PDF
C sharp chap5
Mukesh Tekwani
 
PDF
C,c++ interview q&a
Kumaran K
 
PDF
C sharp chap4
Mukesh Tekwani
 
PPTX
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Abu Saleh
 
PPTX
Pointer and polymorphism
SangeethaSasi1
 
PPT
Templates exception handling
sanya6900
 
KEY
Domänenspezifische Sprachen mit Xtext
Dr. Jan Köhnlein
 
PDF
Generic Programming
Muhammad Alhalaby
 
PPTX
Basic iOS Training with SWIFT - Part 2
Manoj Ellappan
 
PPTX
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
PPT
Pointers
Lp Singh
 
C sharp chap6
Mukesh Tekwani
 
C sharp chap5
Mukesh Tekwani
 
C,c++ interview q&a
Kumaran K
 
C sharp chap4
Mukesh Tekwani
 
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Abu Saleh
 
Pointer and polymorphism
SangeethaSasi1
 
Templates exception handling
sanya6900
 
Domänenspezifische Sprachen mit Xtext
Dr. Jan Köhnlein
 
Generic Programming
Muhammad Alhalaby
 
Basic iOS Training with SWIFT - Part 2
Manoj Ellappan
 
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Pointers
Lp Singh
 

Viewers also liked (15)

PDF
Paparazzi2
Mahmoud
 
PDF
08 Table Views
Mahmoud
 
PDF
06 View Controllers
Mahmoud
 
DOC
New Study Of Gita Nov 8 Dr Shriniwas J Kashalikar
chitreajit
 
PDF
01 Introduction
Mahmoud
 
PDF
04 Model View Controller
Mahmoud
 
PPT
Imoot
Miles Berry
 
PDF
07 Navigation Tab Bar Controllers
Mahmoud
 
PDF
مهارات التعامل مع الغير
Mahmoud
 
PPT
Appleipad 100205071918 Phpapp02
Mahmoud
 
PDF
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
Mahmoud
 
PDF
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
Mahmoud
 
PDF
Handout 00 0
Mahmoud
 
PDF
الشخصية العبقرية
Mahmoud
 
PDF
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
Mahmoud
 
Paparazzi2
Mahmoud
 
08 Table Views
Mahmoud
 
06 View Controllers
Mahmoud
 
New Study Of Gita Nov 8 Dr Shriniwas J Kashalikar
chitreajit
 
01 Introduction
Mahmoud
 
04 Model View Controller
Mahmoud
 
07 Navigation Tab Bar Controllers
Mahmoud
 
مهارات التعامل مع الغير
Mahmoud
 
Appleipad 100205071918 Phpapp02
Mahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
Mahmoud
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
Mahmoud
 
Handout 00 0
Mahmoud
 
الشخصية العبقرية
Mahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
Mahmoud
 
Ad

Similar to Assignment2 A (20)

PDF
Assignment1 B 0
Mahmoud
 
PPTX
Presentation 1st
Connex
 
PDF
Assignment3
Mahmoud
 
DOCX
1 Project 2 Introduction - the SeaPort Project seri.docx
honey725342
 
DOCX
ContentsCOSC 2436 – LAB4TITLE .............................docx
dickonsondorris
 
PDF
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
PPTX
advancedzplmacroprogramming_081820.pptx
ssuser6a1dbf
 
DOCX
matmultHomework3.pdfNames of Files to Submit matmult..docx
andreecapon
 
DOCX
Process Synchronization Producer-Consumer ProblemThe purpos.docx
stilliegeorgiana
 
DOCX
Article link httpiveybusinessjournal.compublicationmanaging-.docx
fredharris32
 
PDF
a3.pdf
1914848496c
 
DOCX
Comp 220 ilab 5 of 7
ashhadiqbal
 
PDF
C# conventions & good practices
Tan Tran
 
PDF
System verilog Coverage including types.pdf
yifohab193
 
DOCX
ITECH 2100 Programming 2 School of Science, Information Te.docx
christiandean12115
 
PPT
Vb introduction.
sagaroceanic11
 
PDF
Publishing geoprocessing-services-tutorial
Sebastian Correa Gimenez
 
ODT
Designing Better API
Kaniska Mandal
 
DOCX
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
stilliegeorgiana
 
PPTX
Objective c slide I
Diksha Bhargava
 
Assignment1 B 0
Mahmoud
 
Presentation 1st
Connex
 
Assignment3
Mahmoud
 
1 Project 2 Introduction - the SeaPort Project seri.docx
honey725342
 
ContentsCOSC 2436 – LAB4TITLE .............................docx
dickonsondorris
 
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
advancedzplmacroprogramming_081820.pptx
ssuser6a1dbf
 
matmultHomework3.pdfNames of Files to Submit matmult..docx
andreecapon
 
Process Synchronization Producer-Consumer ProblemThe purpos.docx
stilliegeorgiana
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
fredharris32
 
a3.pdf
1914848496c
 
Comp 220 ilab 5 of 7
ashhadiqbal
 
C# conventions & good practices
Tan Tran
 
System verilog Coverage including types.pdf
yifohab193
 
ITECH 2100 Programming 2 School of Science, Information Te.docx
christiandean12115
 
Vb introduction.
sagaroceanic11
 
Publishing geoprocessing-services-tutorial
Sebastian Correa Gimenez
 
Designing Better API
Kaniska Mandal
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
stilliegeorgiana
 
Objective c slide I
Diksha Bhargava
 
Ad

More from Mahmoud (20)

PDF
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
Mahmoud
 
PDF
كيف تقوى ذاكرتك
Mahmoud
 
PDF
مهارات التعامل مع الغير
Mahmoud
 
PDF
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
Mahmoud
 
PDF
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
Mahmoud
 
PDF
كيف تقوى ذاكرتك
Mahmoud
 
PDF
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
Mahmoud
 
PDF
الشخصية العبقرية
Mahmoud
 
PPT
Accident Investigation
Mahmoud
 
PPT
Investigation Skills
Mahmoud
 
PDF
Building Papers
Mahmoud
 
PPTX
Operatingsystemwars 100209023952 Phpapp01
Mahmoud
 
PDF
A Basic Modern Russian Grammar
Mahmoud
 
PDF
Teams Ar
Mahmoud
 
PDF
Stress Ar
Mahmoud
 
PDF
Small Projects
Mahmoud
 
PDF
Risk
Mahmoud
 
PDF
Problem Ar
Mahmoud
 
PDF
Negotiation Ar
Mahmoud
 
PDF
Health Ar
Mahmoud
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
Mahmoud
 
كيف تقوى ذاكرتك
Mahmoud
 
مهارات التعامل مع الغير
Mahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
Mahmoud
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
Mahmoud
 
كيف تقوى ذاكرتك
Mahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
Mahmoud
 
الشخصية العبقرية
Mahmoud
 
Accident Investigation
Mahmoud
 
Investigation Skills
Mahmoud
 
Building Papers
Mahmoud
 
Operatingsystemwars 100209023952 Phpapp01
Mahmoud
 
A Basic Modern Russian Grammar
Mahmoud
 
Teams Ar
Mahmoud
 
Stress Ar
Mahmoud
 
Small Projects
Mahmoud
 
Risk
Mahmoud
 
Problem Ar
Mahmoud
 
Negotiation Ar
Mahmoud
 
Health Ar
Mahmoud
 

Recently uploaded (20)

PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Q2 Leading a Tableau User Group - Onboarding
lward7
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
July Patch Tuesday
Ivanti
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Q2 Leading a Tableau User Group - Onboarding
lward7
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
July Patch Tuesday
Ivanti
 

Assignment2 A

  • 1. CS193P Assignment 2A Winter 2010 Cannistraro/Shaffer Assignment 2A - WhatATool (Part II) Due Date This assignment is due by 11:59 PM, January 20. Assignment Now that we have some Objective-C experience under our belt, we’ll dive into the world of custom classes and more advanced Objective-C language topics. You will define and use a new custom class, and learn about Objective-C categories. We will use the same WhatATool project from last week as our starting point. A few more sections will be added to the existing structure. The basic layout of your program should look something like this: #import <Foundation/Foundation.h> // sample function for one section, use a similar function per section void PrintPathInfo() { // Code from path info section here } int main (int argc, const char * argv[]) { NSAutoreleasepool * pool = [[NSAutoreleasePool alloc] init]; PrintPathInfo(); // Section 1 PrintProcessInfo(); // Section 2 PrintBookmarkInfo(); // Section 3 PrintIntrospectionInfo(); // Section 4 PrintPolygonInfo(); // Section 6 (No function for section 5) [pool release]; return 0; } Testing In most assignments testing of the resulting application is the primary objective. In this case, testing/grading will be done both on the output of the tool, but also on the code of each section. We will be looking at the following: 1. Your project should build without errors or warnings. 2. Your project should run without crashing. 3. Each section of the assignment describes a number of log messages that should be printed. These should print. 4. Each section of the assignment describes certain classes and methodology to be used to generate those log messages – the code generating those messages should follow the described methodology, and not be simply hard-coded log messages. To help make the output of your program more readable, it would be helpful to put some kind of header or separator between each of the sections. Page 1 of 4
  • 2. CS193P Assignment 2A Winter 2010 Cannistraro/Shaffer Assignment Walkthrough Section 5: Creating a new class Create a PolygonShape class. To create the files for the new class in Xcode: 1. Choose File > New File… 2. In the Cocoa section under Mac OS X, select the ‘Objective-C class’ template 3. Name the file PolygonShape.m – Be certain the checkbox to create a header file is also checked Note that your new class inherits from NSObject by default, which happens to be what we want. Now that we’ve got a class, we need to give it some attributes. Objective-C 2.0 introduced a new mechanism for specifying and accessing attributes of an object. Classes can define “properties” which can be accessed by users of the class. While properties usually allow developers to avoid having to write boilerplate code for setting and getting attributes in their classes, they also allow classes to express how an attribute can be used or what memory management policies should be applied to a particular attribute. For example, a property can be defined to be read-only or that an when an object property is set how the ownership of that object should be handled. In this section you will add some properties to your PolygonShape class. 1. Add the following properties to your PolygonShape class •  numberOfSides – an int value •  minimumNumberOfSides – an int value • maximumNumberOfSides – an int value • angleInDegrees – a float value, readonly •  angleInRadians – a float value, readonly •  name – an NSString object, readonly 2. The numberOfSides, minimumNumberOfSides and maximumNumberOfSides properties should all be backed by instance variables of the appropriate type. These properties should all be synthesized. When a property is “synthesized” the compiler will generate accessor methods for the properties according to the attributes you specify in the @property declaration. For example, if you specified a property as “readonly” then the compiler will Page 2 of 4
  • 3. CS193P Assignment 2A Winter 2010 Cannistraro/Shaffer only generate a getter method but not a setter method. 3. Implement setter methods for each of the number of sides properties and enforce the following constraints: •  numberOfSides – between the minimum and maximum number of sides •  minimumNumberOfSides – greater than 2 • maximumNumberOfSides – less than or equal to 12 Attempts to set one of these properties outside of the constraints should fail and log an error message. For example, if you have a polygon that is configured with a maximumNumberOfSides set to 5 and you attempt to set the numberOfSides property to 9 you should log a message saying something like: Invalid number of sides: 9 is greater than the maximum of 5 allowed 4. Implement a custom initializer method that takes the number of sides for the polygon: - (id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min maximumNumberOfSides:(int)max; Your initializer should set the minimum and maximum number of sides first (to establish the constraints) and then set the number of sides to the value passed in. 5. Implement a custom init method (overriding the version implemented in NSObject) which calls your custom initializer with default values. For example, your generic -[PolygonShape init] method might create a 5 sided polygon with min of 3 sides and max of 10. 6. The angleInDegrees and angleInRadians properties should not be stored in an instance variable since they are all properties derived by the numberOfSides. These properties do not need to be synthesized and you should implement methods for each of them which return the appropriate values. We’re being boring and using regular polygons so the angles are all the same. 7. Similarly, the name property should also not be synthesized (nor stored in an instance variable) and you should implement a method for it. The name of the polygon should be a descriptive name for the number of sides. For example, if a polygon has 3 sides it is a “Triangle” A 4-sided polygon is a “Square” . . 8. Give your PolygonShape class a -description method. Example output from this method: Hello I am a 4-sided polygon (aka a Square) with angles of 90 degrees (1.570796 radians). 9. In order to verify your memory management techniques, implement a dealloc method and include an NSLog statement indicating that dealloc is being called. Section Hints: • You can find a list of names for polygons on the web. Wikipedia has a good one. • The formula for computing the internal angle of a regular polygon in degrees is (180 * (numberOfSides - 2) / numberOfSides). • Remember your trigonometry: 360° is equal to 2π. Page 3 of 4
  • 4. CS193P Assignment 2A Winter 2010 Cannistraro/Shaffer • You can use the preprocessor value M_PI for π. Section 6: Using the PolygonShape class Write a C function (e.g. PrintPolygonInfo) called by main() that uses your newly created PolygonShape class. You will have to add an import statement to the WhatATool.m file: #import "PolygonShape.h" IMPORTANT: In this section, you are expected to use +alloc and –init methods to create the polygons and the array that they are put into. You must practice correct memory management techniques of releasing the polygon objects when you are done with them. 1. Create a mutable array (using alloc/init). 2. Create 3 (or more) PolygonShape instances with the following values: Min number of sides Max number of sides Number of sides 3 7 4 5 9 6 9 12 12 When allocating your polygons, use a mixture of vanilla alloc/init then set the properties along with using your custom initializer method that takes all of the properties in the initializer method. 3. As you create each polygon, add them to the array of polygons and emit a log with the polygon’s description. There should be at least 3 descriptions logged. 4. Test the constraints on your polygons. Iterate over the array of polygons and attempt to set their numberOfSides properties to 10. This should generate two logs indicating that the number of sides doesn’t fall within the constraints (for the first two polygons in the table above). 5. Verify that your polygon objects are being deallocated correctly. If you have followed the rules correctly with regard to memory management you should see 3 logs from the dealloc method of your polygons. If you do not see these logs, review your alloc/init and release calls to make sure they are correctly balanced for your polygon objects as well as the array you are putting them into. Remember, alloc/init and release work like malloc and free in C. Page 4 of 4