diff --git a/CaesarCipher/.DS_Store b/CaesarCipher/.DS_Store index 1dfdfaf..119af27 100644 Binary files a/CaesarCipher/.DS_Store and b/CaesarCipher/.DS_Store differ diff --git a/CaesarCipher/CaesarCipher/main.m b/CaesarCipher/CaesarCipher/main.m index 8b8157a..43d7189 100644 --- a/CaesarCipher/CaesarCipher/main.m +++ b/CaesarCipher/CaesarCipher/main.m @@ -2,16 +2,21 @@ // main.m // CaesarCipher // -// Created by Michael Kavouras on 6/21/15. +// Created by Michael Kavouras, edited by Shena 🙋🏻 on 6/21/15. // Copyright (c) 2015 Mike Kavouras. All rights reserved. // #import + @interface CaesarCipher : NSObject -- (NSString *)decode:(NSString *)string offset:(int)offset; - (NSString *)encode:(NSString *)string offset:(int)offset; +- (NSString *)decode:(NSString *)string offset:(int)offset; + +// stated codebreaker method here: +- (BOOL) breakCode:(NSString *)stringOne + compareOneWithTwo:(NSString *)stringTwo; @end @@ -21,31 +26,69 @@ - (NSString *)encode:(NSString *)string offset:(int)offset { if (offset > 25) { NSAssert(offset < 26, @"offset is out of range. 1 - 25"); } + NSString *str = [string lowercaseString]; unsigned long count = [string length]; unichar result[count]; unichar buffer[count]; - [string getCharacters:buffer range:NSMakeRange(0, count)]; - + [str getCharacters:buffer range:NSMakeRange(0, count)]; + + char allchars[] = "abcdefghijklmnopqrstuvwxyz"; + for (int i = 0; i < count; i++) { if (buffer[i] == ' ' || ispunct(buffer[i])) { result[i] = buffer[i]; continue; } - - int low = islower(buffer[i]) ? 'a' : 'A'; - result[i] = (buffer[i]%low + offset)%26 + low; + + char *e = strchr(allchars, buffer[i]); + int idx= (int)(e - allchars); + int new_idx = (idx + offset) % strlen(allchars); + + result[i] = allchars[new_idx]; } - + return [NSString stringWithCharacters:result length:count]; } - (NSString *)decode:(NSString *)string offset:(int)offset { return [self encode:string offset: (26 - offset)]; } + +// implementation of codebreaker method: +- (BOOL) breakCode:(NSString *)stringOne + compareOneWithTwo:(NSString *)stringTwo{ + + BOOL isEqualTo = NO; + + for (int i = 1; i < 26; i++) { + NSString *decodeCyphStringOne = [self decode:stringOne offset:i]; + for (int j = 1; j < 26; j++) { + NSString *decodeCyphStringTwo = [self decode:stringTwo offset:j]; + if ([decodeCyphStringOne isEqualTo:decodeCyphStringTwo]) + isEqualTo = YES; + } + } + return isEqualTo; +} @end int main(int argc, const char * argv[]) { @autoreleasepool { - + + CaesarCipher *testStrings = [[CaesarCipher alloc]init]; + + // I set words for the program to encode/decode: + [testStrings encode:@"bananas" offset:3]; + [testStrings decode:@"edqdqdv" offset:3]; + + // I printed values to show the encode/decode is working: + NSLog(@"%@ = the encoded word", [testStrings encode:@"bananas" offset:3]); + NSLog(@"%@ = the decoded word", [testStrings decode:@"edqdqdv" offset:3]); + + // we can use the BOOL method to test the two words here: + BOOL isEqualTo = [testStrings breakCode:@"bananas" compareOneWithTwo:@"edqdqdv"]; + NSLog(@"is codebreaker working? 1 = YES, 2 = NOPE: %d", isEqualTo); + } -} + return 0; +} \ No newline at end of file diff --git a/Election/Election/main.m b/Election/Election/main.m index 550db3c..037d40a 100644 --- a/Election/Election/main.m +++ b/Election/Election/main.m @@ -206,6 +206,8 @@ - (BOOL)pollsOpen { int main(int argc, const char * argv[]) { @autoreleasepool { + + } return 0; } diff --git a/Person/Person/main.m b/Person/Person/main.m index 8937eb5..9e520c2 100644 --- a/Person/Person/main.m +++ b/Person/Person/main.m @@ -2,14 +2,15 @@ // main.m // Person // -// Created by Michael Kavouras on 6/21/15. +// Created by Michael Kavouras, edited by Shena 💁🏻 on 6/21/15. // Copyright (c) 2015 Mike Kavouras. All rights reserved. // - #import +// We always start with the INTERFACE: @interface Person: NSObject +// And then declare a few METHODS: - (void)setName:(NSString *)name; - (NSString *)name; @@ -19,14 +20,28 @@ - (NSString *)city; - (void)setPhoneNumber:(NSString *)phoneNumber; - (NSString *)phoneNumber; +// I added another method that will show each person's shoe size! +- (void)setShoeSize:(NSString *)shoeSize; +- (NSString *)shoeSize; + +// This method will eventually check the same city: +-(BOOL)checkSameCity:(Person *)aPerson; + +// This method adds a child: +-(Person *)haveChild; + @end +// We name the properties: +// I learned that we only have to declare variables here, so "have child" and "checkSameCity" don't qualify: @implementation Person { NSString *_name; NSString *_phoneNumber; NSString *_city; + NSString *_shoeSize; } +// Then we add the setter/getter methods: - (void)setName:(NSString *)name { _name = name; } @@ -51,13 +66,79 @@ - (NSString *)phoneNumber { return _phoneNumber; } +- (void)setShoeSize:(NSString *)shoeSize { + _shoeSize = shoeSize; +} + +- (NSString *)shoeSize { + return _shoeSize; +} + +// Here are the methods for checking the city: +-(BOOL) checkSameCity:(Person *)aPerson; { + // note: "==" does not work in obj c, use "isEqualToString" instead, like this: + if([[aPerson city] isEqualToString: [self city]]) { + return YES; + } else { + return NO; + } +} + +// And this method will return a child: +-(Person *)haveChild { + Person *child = [[Person alloc]init]; + [child setCity: [self city]]; + [child setPhoneNumber: [self phoneNumber]]; + return child; +} + @end int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"Hello, World!"); + + + Person *fred = [[Person alloc]init]; + Person *wilma = [[Person alloc]init]; + + // we can set our Person's properties: + + [fred setName: @"Fred"]; + [fred setCity: @"Bedrock"]; + [fred setPhoneNumber: @"123-4567"]; + [fred setShoeSize: @"9.5"]; + + [wilma setName: @"Wilma"]; + [wilma setCity: @"Bedrock"]; + [wilma setPhoneNumber: @"123-4567"]; + [wilma setShoeSize: @"7"]; + + BOOL checkSameCity = [wilma checkSameCity: fred]; + NSLog(@"Do Fred and Wilma live in the same city? 1 = yes, 0 = no. Answer: %i", checkSameCity); + + // to display Fred and Wilma's names, we call the "getter" + NSString *fredsName = [fred name]; + NSLog(@"Our first person is called %@", fredsName); + NSString *wilmasName = [wilma name]; + NSLog(@"Our second person is called %@", wilmasName); + + NSString *fredsPhone = [fred phoneNumber]; + NSLog(@"%@'s phone number is %@", fredsName, fredsPhone); + + NSString *wilmasShoeSize = [wilma shoeSize]; + NSLog(@"%@ wears size %@ shoes", wilmasName, wilmasShoeSize); + + NSString *wilmasCity = [wilma city]; + NSLog(@"%@ lives in %@", wilmasName, wilmasCity); + + [fred haveChild]; + Person *fredsBaby = [fred haveChild]; + [fredsBaby setCity: @"Dino Town"]; + [fredsBaby setPhoneNumber: @"123-4567"]; + NSLog(@"Fred's baby lives in %@", [fredsBaby city]); + + } return 0; -} +} \ No newline at end of file diff --git a/README.md b/README.md index 569110c..d6d5367 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,7 @@ Write a program to simulate an election. Create a class called **VotingSimulator 4. Ask the ElectionManager to ***initiatePolling*** 5. Follow the instructions on the console. After each round of polling you will be asked(within the console) whether you want to continue or not. 6. Ask the ElectionManager to ***displayResults*** + +this is my added text... + +me right now: 💆🏻