From d794e808053d2bf819b38f939d3cc92fd616dc8b Mon Sep 17 00:00:00 2001 From: Zoufishan Mehdi Date: Tue, 30 Jun 2015 21:50:52 -0400 Subject: [PATCH] I finished --- TestAssessment/TestViewController.m | 156 ++++++++++++++++++++++++---- 1 file changed, 133 insertions(+), 23 deletions(-) diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 013428d..70d50f8 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -18,47 +18,79 @@ @implementation TestViewController This method should return any positive NSInteger (hint: cannot be 0) */ -- (void)shouldReturnAPositiveNSInteger { - -} + +- (int)shouldReturnAPositiveInt { + return 25; +} /* This method should return any negative CGFloat (hint: cannot be 0) */ -- (void)shouldReturnANegativeCGFloat { - -} +- (float)shouldReturnANegativeFloat { + return -2.42000; +} /* This method should return a falsy boolean Falsey: Something which evaluates to FALSE. */ -- (void)shouldReturnAFalseyBool { - + +- (BOOL)shouldReturnAFalseyBool { + return NO; } + /* This method should return a single char from a - z */ -- (void)shouldReturnACharAtoZ { + + +- (char)shouldReturnACharAtoZ { + char aToZ; + for(int i = 0; i < 26; i++ ) { + char aToZ[i]; + } + return aToZ; } /* This method should return the sum of all numbers from 0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99) */ + + - (NSInteger)shouldReturnSumOf0To100 { - return 0; + int sum = 0; + for(int i = 0; i < 100; i++ ) { + sum += i; + + } + return sum; } + /* Given a c array (int[]) and a count, return the sum of the numbers within the arr (eg. arr[0] + arr[1] ...) */ + + - (NSInteger)shouldReturnSumOfArrayValues:(int *)arr withSize:(int)count { - return 0; -} + int COUNT; + int a[COUNT] = {5,6,2,9,3,82,93}; + int i, total = 0; + + for(i = 0; i <= (COUNT-1); i++) + { + + total += a[i]; + } + printf("\nThe sum of the array elements is %d\n", total); + + } + + /* Provided a C string (array of chars), return the character @@ -66,15 +98,31 @@ Provided a C string (array of chars), return the character (ex. "aionkljajvqlkjaml" would return the letter 'v') (hint: while loop) */ -- (char)shouldReturnCharBeforeQ:(char *)str { - return '\0'; + +- (char)shouldReturnCharBeforeQ:(char *)str{ + int i; + int size; + char * arr[i]; + char *new_arr = malloc(sizeof(char) * size); + while(i < 16) { + new_arr[i] = arr[i]; + } + return arr[i]; } +int main() { + + char arr[16]= {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q"}; + + +} /* This method should return the sum of aNumber + bNumber */ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber { - return 0; + NSInteger sum = 0; + sum = aNumber + bNumber; + return sum; } @@ -82,22 +130,40 @@ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNum This method should return a YES if aNumber is odd */ - (BOOL)isOdd:(NSInteger)aNumber { + for (int i = 0; i < 50; i++) { + if (i % 2 != 0) { + return YES; + } else { return NO; + } +} } /* This method should return YES if aNumber is a multiple of 5 */ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { - return NO; + for (int j = 0; j < 100; j++) { + if (j % 5 == 0) { + return YES; + } else { + return NO; + } + } } + /* This method should return YES is aNumber is odd and bNumber is even */ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { - return NO; + for (int i = 0; i < 50; i++) { + if (aNumber % 2 != 0 && bNumber % 2 == 0) { + return YES; + } else { + return NO; + } } /* @@ -105,14 +171,15 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber parameter (hint: command + click on class name to jump to the interface. */ - (NSString *)shouldReturnPersonsName:(Person *)person { - return @""; + return @Person; } /* This method should change the person name to "Ada Lovelace" */ - (void)changePersonsNameToAdaLovelace:(Person *)person { - + NSString *replaced = [str stringByReplacingOccurrencesOfString:@"Tom" + withString:@"Ada Lovelace"]; } /* @@ -121,8 +188,42 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person { 2) Set the person's name to "Santa Clause" 3) Set the person's age to 1823 */ + @interface + -(void)setName:(NSString *)name; + + -(NSString *)name; + + -(void)setAge:(NSString *)age; + + -(NSString *)age; + @end + + @implementation + -(void)setName:(NSString *)name { + _name = name; + } + + -(NSString *)name { + return _name; + + -(void)setAge:(NSString *)age { + _age = age; + } + + -(NSString *)age { + return _age; + @end + - (Person *)createAndReturnPersonWithSomeProperties { - return [[Person alloc] init]; + + Person *santaClause = [[Person alloc] init]; + SantaClause = [person setName: "Santa Clause"]; + SantaClause = [person setAge: "1823"]; + + return [[Person alloc] init]; + } + + } /* @@ -133,7 +234,11 @@ - (Person *)createAndReturnPersonWithSomeProperties { */ - (void)makePersonSitInChair:(Chair *)chair { - + SitInChair *sitInChair = [[SitInChair alloc] init]; + Person *carl = [[Person alloc] init]; + Thing *chair = [[Thing alloc] init]; + [SitInChair sit:chair withPerson:carl]; + } /* @@ -141,7 +246,10 @@ - (void)makePersonSitInChair:(Chair *)chair { Send a message to this Person object telling it to stand up */ - (void)makePersonStandUp:(Person *)person { - + StandUp *standUp = [[StandUp alloc] init]; + Person *carl = [[Person alloc] init]; + [StandUp withPerson:carl]; + } /* @@ -149,8 +257,10 @@ - (void)makePersonStandUp:(Person *)person { https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/ */ - (NSArray *)createAndReturnNSArray { + NSArray *objects = [NSString arrayWithObjects:@"I", @"need", "to", "take" "a", "nap", nil]; return [[NSArray alloc] init]; } + // BONUS /* @@ -187,4 +297,4 @@ - (int)returnSumWhileSumIsLessThan1050:(int *)arr { return 0; } -@end +"\n@end\n"