1 #import " LotteryEntry.h " 2 3 4 @implementation LotteryEntry 5 6 - ( void )prepareRandomNumbers 7 { 8 firstNumber = random() % 100 + 1 ; 9 secondNumber = random() % 100 + 1 ; 10 } 11 12 - ( void )setEntryDate:(NSCalendarDate * )date 13 { 14 entryDate = date; 15 } 16 17 - (NSCalendarDate * )entryDate 18 { 19 return entryDate; 20 } 21 22 - ( int )firstNumber 23 { 24 return firstNumber; 25 } 26 27 - ( int )secondNumber 28 { 29 return secondNumber; 30 } 31 32 - (NSString * )description 33 { 34 NSString * result = [[NSString alloc] initWithFormat: @" %@ = %d and %d " , [entryDate descriptionWithCalendarFormat: @" %b %d %Y " ], firstNumber, secondNumber]; 35 return result; 36 } 37 @end
1 #include < Foundation / Foundation.h > 2 #include " LotteryEntry.h " 3 4 int main ( int argc, const char * argv[]) { 5 // insert code here... 6 7 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 8 9 NSCalendarDate * now = [[NSCalendarDate alloc] init]; 10 srand(time(NULL)); 11 12 13 NSMutableArray * array; 14 array = [[NSMutableArray alloc] init]; 15 16 int i; 17 for (i = 0 ; i < 10 ; i ++ ) 18 { 19 NSCalendarDate * iWeeksFromNow; 20 iWeeksFromNow = [now dateByAddingYears: 0 months: 0 days:(i * 7 ) hours: 0 minutes: 0 seconds: 0 ]; 21 LotteryEntry * entry = [[LotteryEntry alloc] init]; 22 [entry prepareRandomNumbers]; 23 [entry setEntryDate:iWeeksFromNow]; 24 25 [array addObject:entry]; 26 } 27 28 for (LotteryEntry * entryToPrint in array) 29 { 30 NSLog( @" %@ " , entryToPrint); 31 } 32 33 [pool drain]; 34 35 return 0 ; 36 }
转载于:https://www.cnblogs.com/zhtf2014/archive/2011/01/10/1931708.html
相关资源:垃圾分类数据集及代码