Amazon.com Widgets Exercise 12.2-12.7
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 31, 2014, 01:41:50 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ Exercises
| | |-+ Chapter 12
| | | |-+ Exercise 12.2-12.7
Pages: [1] Go Down
Print
Author Topic: Exercise 12.2-12.7 (Read 737 times)
tknp
Newbie
*
Posts: 23






on: January 18, 2012, 03:00:11 PM

main.m
Code: (Objective-C)
#import <Foundation/Foundation.h>

#define MINOF2(a,b) ( ((a) < (b)) ? (a) : (b) )
#define MAXOF3(a,b,c) ( ((a) > (b)) ? ((a) > (c)) ? (a): (c): ((b) > (c)) ? (b) : (c) )
#define IS_UPPER_CASE(x) ( ((x) >= 'A') && ((x) <= 'Z') )
#define IS_LOWER_CASE(x) ( ((x) >= 'a') && ((x) <= 'z') )
#define IS_ALPHABETIC(x) ( ( IS_UPPER_CASE(x) ) || ( IS_LOWER_CASE(x) ) )
#define IS_DIGIT(x) ( ((x) >= 0) && ((x) <= 9) )
#define IS_SPECIAL(x) ( ( !IS_ALPHABETIC(x) ) && ( !IS_DIGIT(x) ) )
#define ABSOLUTE_VALUE(x) ( ((x) >= 0) ? (x) : -(x) )


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

    // exercise 12.2
int lowNumber = MINOF2 (100-60,20);
NSLog(@"Min value is %i", lowNumber);

// exercise 12.3
int highNumber = MAXOF3 (150+500,225,475);
NSLog(@"Max value is %i", highNumber);

// exercise 12.4
(( IS_UPPER_CASE ('C') ) ? NSLog(@"Upper case letter") : NSLog(@"Not upper case letter"));

// exercise 12.5
(( IS_ALPHABETIC ('R') ) ? NSLog(@"Alphabetic") : NSLog(@"Not alphabetic"));

// exercise 12.6
(( IS_DIGIT (9) ) ? NSLog(@"Digit") : NSLog(@"Not digit"));
(( IS_SPECIAL ('$') ) ? NSLog(@"Special character") : NSLog(@"Not special character"));

// exercise 12.7
int absoluteVal = ABSOLUTE_VALUE (-10-5-20);
NSLog(@"%i", absoluteVal);

    [pool drain];
    return 0;
}
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.