From 8af1edd245c5877d4c912af506034da439a06e71 Mon Sep 17 00:00:00 2001 From: Shena Yoshida Date: Tue, 23 Jun 2015 19:16:03 -0400 Subject: [PATCH 1/3] changed my readme file --- CaesarCipher/.DS_Store | Bin 6148 -> 6148 bytes Election/Election/main.m | 2 ++ README.md | 2 ++ 3 files changed, 4 insertions(+) diff --git a/CaesarCipher/.DS_Store b/CaesarCipher/.DS_Store index 1dfdfaf370783ec3d89dd31e6d3f2f3933dc371f..d2a75cc870f9ce9cf339ec4196d7e08e044b3dfd 100644 GIT binary patch delta 43 xcmZoMXffE}#l#fEG}(vAhDm9`lfw5t;AoDkti4AO<**X650{|T74TAsx delta 43 xcmZoMXffE}#l#e`X0i{H4U^Ez$z4o#AnFv81LK6vg3RAoCN{8bX6N|J4*)-e4z&OP 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/README.md b/README.md index 569110c..fc0737c 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,5 @@ 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... From cfb7f2d3dd945cba048f0b91685dee7d91fd424f Mon Sep 17 00:00:00 2001 From: Shena Yoshida Date: Fri, 26 Jun 2015 16:00:32 -0400 Subject: [PATCH 2/3] homework 4:00pm --- CaesarCipher/.DS_Store | Bin 6148 -> 6148 bytes CaesarCipher/CaesarCipher/main.m | 60 ++++++++++++++++---- Person/Person/main.m | 91 +++++++++++++++++++++++++++++-- README.md | 2 + 4 files changed, 138 insertions(+), 15 deletions(-) diff --git a/CaesarCipher/.DS_Store b/CaesarCipher/.DS_Store index d2a75cc870f9ce9cf339ec4196d7e08e044b3dfd..756ecc87123ed601efe9a183c748a08cb940a0df 100644 GIT binary patch delta 45 ycmZoMXffE}#l#d-IoXHFnt8Ju_v9`nTQGf!$$@dgWwqW`clLKSJW + @interface CaesarCipher : NSObject -- (NSString *)decode:(NSString *)string offset:(int)offset; - (NSString *)encode:(NSString *)string offset:(int)offset; +- (NSString *)decode:(NSString *)string offset:(int)offset; +- (BOOL) breakCode:(NSString *)stringOne // created codebreaker method: + compareOneWithTwo:(NSString *)stringTwo; @end @@ -21,31 +24,68 @@ - (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 = 0; i < 25; 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 print values to test the encode/decode methods + [testStrings encode:@"bananas" offset:3]; + [testStrings decode:@"edqdqdv" offset:3]; + + NSLog(@"%@", [testStrings encode:@"bananas" offset:3]); + NSLog(@"%@", [testStrings decode:@"edqdqdv" offset:3]); + + // I can't get the below portion to work without crashing the system, that is why it is commented out. :( + + // BOOL isEqualTo = [testStrings breakCode:@"bananas" compareOneWithTwo:@"edqdqdv"]; + // NSLog(@"%c", isEqualTo); } -} + return 0; +} \ No newline at end of file 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 fc0737c..d6d5367 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,5 @@ Write a program to simulate an election. Create a class called **VotingSimulator 6. Ask the ElectionManager to ***displayResults*** this is my added text... + +me right now: 💆🏻 From 005612cbb6e031b29c9308741a13fa576fc63bd0 Mon Sep 17 00:00:00 2001 From: Shena Yoshida Date: Fri, 26 Jun 2015 19:19:01 -0400 Subject: [PATCH 3/3] updated homework --- CaesarCipher/.DS_Store | Bin 6148 -> 6148 bytes CaesarCipher/CaesarCipher/main.m | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CaesarCipher/.DS_Store b/CaesarCipher/.DS_Store index 756ecc87123ed601efe9a183c748a08cb940a0df..119af2700bfdd42b9b4afbb77821a547e5d0808f 100644 GIT binary patch delta 29 lcmZoMXffE}#l)0+X|fN~KE?%`1)0CGOl)A=%+B$b9{`@*3W5Lt delta 29 lcmZoMXffE}#l#d-IoXG4ALE40g3RAoCN{8bX6N|J4*-^R3K9SS diff --git a/CaesarCipher/CaesarCipher/main.m b/CaesarCipher/CaesarCipher/main.m index 42dd169..43d7189 100644 --- a/CaesarCipher/CaesarCipher/main.m +++ b/CaesarCipher/CaesarCipher/main.m @@ -13,7 +13,9 @@ @interface CaesarCipher : NSObject - (NSString *)encode:(NSString *)string offset:(int)offset; - (NSString *)decode:(NSString *)string offset:(int)offset; -- (BOOL) breakCode:(NSString *)stringOne // created codebreaker method: + +// stated codebreaker method here: +- (BOOL) breakCode:(NSString *)stringOne compareOneWithTwo:(NSString *)stringTwo; @end @@ -58,7 +60,7 @@ - (BOOL) breakCode:(NSString *)stringOne BOOL isEqualTo = NO; - for (int i = 0; i < 25; i++) { + 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]; @@ -75,17 +77,18 @@ int main(int argc, const char * argv[]) { CaesarCipher *testStrings = [[CaesarCipher alloc]init]; - // I print values to test the encode/decode methods + // I set words for the program to encode/decode: [testStrings encode:@"bananas" offset:3]; [testStrings decode:@"edqdqdv" offset:3]; - NSLog(@"%@", [testStrings encode:@"bananas" offset:3]); - NSLog(@"%@", [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]); - // I can't get the below portion to work without crashing the system, that is why it is commented out. :( + // 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); - // BOOL isEqualTo = [testStrings breakCode:@"bananas" compareOneWithTwo:@"edqdqdv"]; - // NSLog(@"%c", isEqualTo); } return 0; } \ No newline at end of file