// Birthdays.m Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2013-07-15 Objective-C version of this file was created. // 2013-07-15 Last modification. /* This program uses class ISODate to calculate information about birthdays for a person. The file class_isodate_oc.h must be in the same folder with this file when this program is compiled. Here is a sample execution of this program: Type in your date of birth in the form YYYY-MM-DD. Use four digits for the year and two digits for the month and day: 1976-08-02 You were born on a Monday Here are your days to celebrate. You are 10 years old on 1986-08-02 (Saturday) 20 years old on 1996-08-02 (Friday) 30 years old on 2006-08-02 (Wednesday) 40 years old on 2016-08-02 (Tuesday) 50 years old on 2026-08-02 (Sunday) 60 years old on 2036-08-02 (Saturday) 70 years old on 2046-08-02 (Thursday) */ #include #import #import "class_isodate_oc.h" int main( void ) { NSAutoreleasePool* autorelease_pool = [ [ NSAutoreleasePool alloc ] init ] ; char date_of_birth_as_c_string[ 20 ] ; printf( "\n Type in your date of birth in the form YYYY-MM-DD. " "\n Use four digits for the year and two digits for the month " "\n and day: " ) ; scanf( "%s", date_of_birth_as_c_string ) ; NSString* date_of_birth_as_nsstring = [ NSString stringWithUTF8String: date_of_birth_as_c_string ] ; ISODate* date_of_birth = [ [ ISODate alloc ] init_with_string: date_of_birth_as_nsstring ] ; NSString* text_to_print = [ NSString stringWithFormat: @"\n You were born on a %@" @"\n Here are your days to celebrate. You are\n", [ date_of_birth get_day_of_week ] ] ; printf( "%s", [ text_to_print UTF8String ] ) ; int years_to_celebrate = 10 ; while ( years_to_celebrate < 80 ) { ISODate* date_to_celebrate = [ [ ISODate alloc ] init_year: [ date_of_birth year ] + years_to_celebrate and_month: [ date_of_birth month ] and_day: [ date_of_birth day ] ] ; text_to_print = [ NSString stringWithFormat: @"\n %d years old on %@ (%@)", years_to_celebrate, date_to_celebrate, [ date_to_celebrate get_day_of_week ] ] ; printf( "%s", [ text_to_print UTF8String ] ) ; years_to_celebrate = years_to_celebrate + 10 ; } printf( "\n\n" ) ; [ autorelease_pool drain ] ; }