C# Data structure assignment - HashTable, Dictionary Lab and HashSet
Question 1
In this lab, we will create a very simple
HashTable
a. Create a console application
b. Create a new Hash table.
c. Add the following key value pair to the
hash table
Josh",
"Joshua Whitetail"
"Sam",
"Samantha Bernie"
"Eli",
"Elizabeth Spiegel"
"Will",
"William Johnson"
"Don",
"Donald Regan"
d. Use foreach, to print the key and value to
console window.
Question 2
Write a console application that does
the following:
a. The main method should take a String array (use the one given below), and store the array's elements into a
HashSet to eliminate duplicates, and finally output the number of unique
strings in the
array and print the strings to the console.
String [] sampleStrings = {"that", "that",
"is", "is", "that", "that",
"is", "not", "is", "not",
"is", "that", "it", "it",
"is"};
Output:
Number of Unique Strings: 4
that, is, not, it
|
b. Add new code to the above application
to create a Dictionary that holds the number of occurrences of each unique
string in the array, and finally output the unique strings and the number of
occurrences of that string to the console.
that - 5
occurrences
is - 6
occurrences and so on....
Question 3
Zimmermann Telegram is a popular german secret
communication that was decoded by British Intelligence during World War I.
Google to learn more about Zimmermann Telegram.
Zimmermann Telegram used Code book cipher. In this exercise we will
create a simple codebook cipher to encrypt and decrypt text messages. The code
book cipher will use the following code book extracted cryptology notes by
Christensen (2005). This code book has codes for popular words and codes for
26l alphabets to spell the words that are not included in the codebook.
a 141 about 592 all 653 an 589 and 793 are 238
as 462 at 643 b 383 be 279 been 502 but 884 by 197 c 169 call 399 can 375 come
105 could 820 d 974 day 944 did 307 do 816 down 406 e 286 each 208 f 998 find
628 first 034 for 825 from 342 g 117 get 067 go 982 h 148 had 086 has 513 have
282 he 306 her 647 him 093 his 844 how 609 i 550 I 582 if 231 in 725 into 359
is 408 it 128 its 481 j 450 k 284 l 102 like 701 long 938 look 521 m 559 made
644 make 622 many 948 may 954 more 930 my 381 n 964 no 428 not 810 now 975
number 665 o 334 of 461 oil 756 on 482 one 337 or 867 other 831 out 652 p 712
part 019 people 091 q 456 r 856 s 692 said 346 see 861 she 045 so 432 some 664
t 821 than 339 that 607 the 260 their 249 them 273 then 724 there 870 these 066
they 063 this 155 time 881 to 488 two 152 u 092 up 096 use 254 v 715 w 364 was
367 water 892 way 590 we 360 were 011 what 330 when 305 which 204 who 213 will
841 with 469 word 519 would 415 write 116 x 094 y 572 you 703 your 657 z 595
Write a program that create and populates a
dictionary with the code book given above. Then use that dictionary to encrypt
or decrypt messages. The main method and
the output expected is shown below:
static void Main(string[] args)
{
CodeBookCipher cipher = new CodeBookCipher();
Console.WriteLine(cipher.encrypt("This is a test message"));
Console.WriteLine(cipher.decrypt("155 408 141 821 286 692 821 559
286 692 692 141 117 286"));
Console.ReadLine();
}
155 408 141 821 286 692 821
559 286 692 692 141 117 286
this is a t e s t m e s s a g
e
|
Question 4
- What
is the motivation to use HashTable or Dictionary over other collections
such as List or ArrayList?
- When
do you use a HashSet?
Reference
Christensen, C (2005), Cryptology notes on
Codes and Nomenclators
Hashtable and Dictionary Collection Types - https://msdn.microsoft.com/enus/library/4yh14awz(v=vs.110).aspx
Comments
Post a Comment