SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&aKumaran K
 
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14Abu Saleh
 
Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphismSangeethaSasi1
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDr. Jan Köhnlein
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and HaskellHermann Hueck
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Manoj Ellappan
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 

La actualidad más candente (14)

C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
C sharp chap5
C sharp chap5C sharp chap5
C sharp chap5
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
 
C sharp chap4
C sharp chap4C sharp chap4
C sharp chap4
 
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
 
Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphism
 
Arrays
ArraysArrays
Arrays
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit Xtext
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Pointers
PointersPointers
Pointers
 

Destacado

Paparazzi2
Paparazzi2Paparazzi2
Paparazzi2Mahmoud
 
08 Table Views
08 Table Views08 Table Views
08 Table ViewsMahmoud
 
06 View Controllers
06 View Controllers06 View Controllers
06 View ControllersMahmoud
 
New Study Of Gita Nov 8 Dr Shriniwas J Kashalikar
New Study Of Gita Nov 8 Dr  Shriniwas J  KashalikarNew Study Of Gita Nov 8 Dr  Shriniwas J  Kashalikar
New Study Of Gita Nov 8 Dr Shriniwas J Kashalikarchitreajit
 
01 Introduction
01 Introduction01 Introduction
01 IntroductionMahmoud
 
04 Model View Controller
04 Model View Controller04 Model View Controller
04 Model View ControllerMahmoud
 
07 Navigation Tab Bar Controllers
07 Navigation Tab Bar Controllers07 Navigation Tab Bar Controllers
07 Navigation Tab Bar ControllersMahmoud
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغيرMahmoud
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Mahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمMahmoud
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهمهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهMahmoud
 
Handout 00 0
Handout 00 0Handout 00 0
Handout 00 0Mahmoud
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقريةMahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائقMahmoud
 

Destacado (15)

Paparazzi2
Paparazzi2Paparazzi2
Paparazzi2
 
08 Table Views
08 Table Views08 Table Views
08 Table Views
 
06 View Controllers
06 View Controllers06 View Controllers
06 View Controllers
 
New Study Of Gita Nov 8 Dr Shriniwas J Kashalikar
New Study Of Gita Nov 8 Dr  Shriniwas J  KashalikarNew Study Of Gita Nov 8 Dr  Shriniwas J  Kashalikar
New Study Of Gita Nov 8 Dr Shriniwas J Kashalikar
 
01 Introduction
01 Introduction01 Introduction
01 Introduction
 
04 Model View Controller
04 Model View Controller04 Model View Controller
04 Model View Controller
 
Imoot
ImootImoot
Imoot
 
07 Navigation Tab Bar Controllers
07 Navigation Tab Bar Controllers07 Navigation Tab Bar Controllers
07 Navigation Tab Bar Controllers
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهمهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
 
Handout 00 0
Handout 00 0Handout 00 0
Handout 00 0
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
 

Similar a Assignment2 A

Assignment1 B 0
Assignment1 B 0Assignment1 B 0
Assignment1 B 0Mahmoud
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
Assignment3
Assignment3Assignment3
Assignment3Mahmoud
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docxhoney725342
 
ContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docxContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docxdickonsondorris
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
advancedzplmacroprogramming_081820.pptx
advancedzplmacroprogramming_081820.pptxadvancedzplmacroprogramming_081820.pptx
advancedzplmacroprogramming_081820.pptxssuser6a1dbf
 
matmultHomework3.pdfNames of Files to Submit matmult..docx
matmultHomework3.pdfNames of Files to Submit  matmult..docxmatmultHomework3.pdfNames of Files to Submit  matmult..docx
matmultHomework3.pdfNames of Files to Submit matmult..docxandreecapon
 
Process Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docxProcess Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docxstilliegeorgiana
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7ashhadiqbal
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practicesTan Tran
 
ITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docxITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docxchristiandean12115
 
Publishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorialPublishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorialSebastian Correa Gimenez
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxProcess Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxstilliegeorgiana
 
Start machine learning in 5 simple steps
Start machine learning in 5 simple stepsStart machine learning in 5 simple steps
Start machine learning in 5 simple stepsRenjith M P
 

Similar a Assignment2 A (20)

Assignment1 B 0
Assignment1 B 0Assignment1 B 0
Assignment1 B 0
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Assignment3
Assignment3Assignment3
Assignment3
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
 
ContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docxContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docx
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
advancedzplmacroprogramming_081820.pptx
advancedzplmacroprogramming_081820.pptxadvancedzplmacroprogramming_081820.pptx
advancedzplmacroprogramming_081820.pptx
 
matmultHomework3.pdfNames of Files to Submit matmult..docx
matmultHomework3.pdfNames of Files to Submit  matmult..docxmatmultHomework3.pdfNames of Files to Submit  matmult..docx
matmultHomework3.pdfNames of Files to Submit matmult..docx
 
Process Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docxProcess Synchronization Producer-Consumer ProblemThe purpos.docx
Process Synchronization Producer-Consumer ProblemThe purpos.docx
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 
a3.pdf
a3.pdfa3.pdf
a3.pdf
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practices
 
ITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docxITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docx
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
Publishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorialPublishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorial
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxProcess Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Start machine learning in 5 simple steps
Start machine learning in 5 simple stepsStart machine learning in 5 simple steps
Start machine learning in 5 simple steps
 

Más de Mahmoud

مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟Mahmoud
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتكMahmoud
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغيرMahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائقMahmoud
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟Mahmoud
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتكMahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمMahmoud
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقريةMahmoud
 
Accident Investigation
Accident InvestigationAccident Investigation
Accident InvestigationMahmoud
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation SkillsMahmoud
 
Building Papers
Building PapersBuilding Papers
Building PapersMahmoud
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Mahmoud
 
A Basic Modern Russian Grammar
A Basic Modern Russian Grammar A Basic Modern Russian Grammar
A Basic Modern Russian Grammar Mahmoud
 
Small Projects
Small ProjectsSmall Projects
Small ProjectsMahmoud
 
Problem Ar
Problem ArProblem Ar
Problem ArMahmoud
 
Negotiation Ar
Negotiation ArNegotiation Ar
Negotiation ArMahmoud
 

Más de Mahmoud (20)

مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
 
Accident Investigation
Accident InvestigationAccident Investigation
Accident Investigation
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation Skills
 
Building Papers
Building PapersBuilding Papers
Building Papers
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01
 
A Basic Modern Russian Grammar
A Basic Modern Russian Grammar A Basic Modern Russian Grammar
A Basic Modern Russian Grammar
 
Teams Ar
Teams ArTeams Ar
Teams Ar
 
Stress Ar
Stress ArStress Ar
Stress Ar
 
Small Projects
Small ProjectsSmall Projects
Small Projects
 
Risk
RiskRisk
Risk
 
Problem Ar
Problem ArProblem Ar
Problem Ar
 
Negotiation Ar
Negotiation ArNegotiation Ar
Negotiation Ar
 
Health Ar
Health ArHealth Ar
Health Ar
 

Último

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

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