diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 013428d..b40af92 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -18,30 +18,36 @@ @implementation TestViewController This method should return any positive NSInteger (hint: cannot be 0) */ -- (void)shouldReturnAPositiveNSInteger { - +- (NSInteger)shouldReturnAPositiveNSInteger { + NSInteger number= 2; + return number; } /* This method should return any negative CGFloat (hint: cannot be 0) */ -- (void)shouldReturnANegativeCGFloat { - +- (CGFloat)shouldReturnANegativeCGFloat { + CGFloat num=-2.4; + return num; } /* This method should return a falsy boolean Falsey: Something which evaluates to FALSE. */ -- (void)shouldReturnAFalseyBool { +- (BOOL)shouldReturnAFalseyBool { + BOOL falsey=FALSE; + return falsey; } /* This method should return a single char from a - z */ -- (void)shouldReturnACharAtoZ { +- (char)shouldReturnACharAtoZ { + char *singleChar="a"; + return *singleChar; } /* @@ -49,7 +55,11 @@ - (void)shouldReturnACharAtoZ { 0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99) */ - (NSInteger)shouldReturnSumOf0To100 { - return 0; + int sum=0; + for (int counter=0; counter<=99; counter++) { + sum=sum+counter; + } + return sum; } /* @@ -57,7 +67,12 @@ Given a c array (int[]) and a count, return the sum of the numbers within the ar (eg. arr[0] + arr[1] ...) */ - (NSInteger)shouldReturnSumOfArrayValues:(int *)arr withSize:(int)count { - return 0; + int sum=0; + for(int i=0;i<=count;i++){ + sum=sum+arr[i]; + } + return sum; + } /* @@ -67,6 +82,15 @@ Provided a C string (array of chars), return the character (hint: while loop) */ - (char)shouldReturnCharBeforeQ:(char *)str { +// int counter=0; +// while (true) { +// +// if (str[counter]==@"q") { +// return str[counter-1]; +// break; +// } +// counter++; +// } return '\0'; } @@ -74,7 +98,9 @@ - (char)shouldReturnCharBeforeQ:(char *)str { This method should return the sum of aNumber + bNumber */ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber { - return 0; + + NSInteger sum= aNumber+bNumber; + return sum; } @@ -82,14 +108,24 @@ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNum This method should return a YES if aNumber is odd */ - (BOOL)isOdd:(NSInteger)aNumber { - return NO; + if(aNumber%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; + if(aNumber%5==0){ + return YES; + } + else{ + return NO; + } } /* @@ -97,6 +133,11 @@ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { */ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { + + if(aNumber%2!=0 && bNumber%2==0){ + return YES; + } + return NO; } @@ -105,13 +146,16 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber parameter (hint: command + click on class name to jump to the interface. */ - (NSString *)shouldReturnPersonsName:(Person *)person { - return @""; + + return [person name]; + } /* This method should change the person name to "Ada Lovelace" */ - (void)changePersonsNameToAdaLovelace:(Person *)person { + [person setName: @"Ada Lovelace"]; } @@ -122,7 +166,12 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person { 3) Set the person's age to 1823 */ - (Person *)createAndReturnPersonWithSomeProperties { - return [[Person alloc] init]; + NSInteger bobsAge=1823; + Person* bob = [[Person alloc] init]; + [bob setName: @"Santa Clause"]; + [bob setAge:bobsAge]; + + return bob; } /* @@ -133,6 +182,8 @@ - (Person *)createAndReturnPersonWithSomeProperties { */ - (void)makePersonSitInChair:(Chair *)chair { + Person* dude= [[Person alloc] init]; + [dude sitInChair:chair]; } @@ -141,7 +192,7 @@ - (void)makePersonSitInChair:(Chair *)chair { Send a message to this Person object telling it to stand up */ - (void)makePersonStandUp:(Person *)person { - + [person standUp]; } /*