(c) 2004 Kari Laitinen http://www.naturalprogramming.com 2004-10-28 File created. 2004-11-25 Last modification. The cssolutions folder contains answers to the numbered exercises of my C# book. Below you can find a complete list which describes which .cs file is the solution to which exercise. When a file name is suggested in an exercise, you can find the solution in a file with the suggested name. Usually I have put "KL" to the end of the names of my solution files. This way you can use the suggested file name for your own solution without the possibility to mix your program with my program. When the task in an exercise is to modify a certain file, the name of the solution file usually begins with the name of the original file. For example, when the task is to modify a file named Whilesum.cs, you should look for the solution in a file whose name looks like Whilesum??????.cs The following is the complete list of solutions: EXERCISE SOLUTION FILE 2-1 SumSolution_2_1.cs 2-2 SumSolution_2_2.cs (See the end of this file to find solutions to the exercises in chapters 3 and 4.) 5-1 GameLoser.cs 5-2 GameSolution_5_2.cs 5-3 DistanceSolutions.cs 5-4 Distancesolutions.cs 5-5 HeightToCentimeters.cs 5-6 HeightToLightYears.cs 5-7 ConvertTemperature.cs 6-1 Largest4.cs and LargestSmallest4.cs 6-2 CurrencyConverterKL.cs 6-3 SolutionToExercise_6_3.cs 6-4 SolutionToExercise_6_4.cs 6-5 SolutionToExercise_6_5.cs 6-6 Whileodd.cs 6-8 MeanvalueSolution_6_8.cs 6-9 MilesToKilometersTable.cs 6-10 CelsiusToFahrenheitTable.cs 6-10 Codefinder.cs 7-1 ArrayDemoSolution_7_1.cs 7-2 ArrayDemoSolution_7_2.cs 7-3 ArrayDemoSolution_7_3.cs 7-4 ArrayDemoSolution_7_4.cs 7-5 ArrayDemoSolution_7_5.cs 7-6 IntegersLargerThan99.cs 7-7 EvenNumbersInArray.cs 7-7 CelsiusBetter.cs 8-1 StringWideReverse.cs 8-2 StringCharactersCounted.cs 8-3 StringToHexadecimalCodes.cs 8-4 StringToUpperCase.cs 8-5 StringPalindromeCheck.cs 8-6 MarilynSolution_8_6.cs 8-7 MarilynSolution_8_7.cs 8-8 StringInShrinkingPieces.cs 8-9 SplittingSentence.cs 8-10 MonthsHistoryKL.cs 9-1 LettersAndNumbers.cs 9-2 Sums3.cs 9-3 FactorialKL.cs 9-4 BoxKL.cs and BoxMoreElegant.cs 9-5 WidecallKL.cs 9-6 ReverseAndPrintAnArray.cs 9-7 SortingToDescendingOrder.cs 9-8 GetSumOfArrayElements.cs 9-9 Factorial_9_9.cs 9-10 ShowcodeKL.cs 10-1 BankBetterSolutions_10_1_and_2.cs 10-2 BankBetterSolutions_10_1_and_2.cs 10-3 AnimalsSolutions.cs 10-4 AnimalsSolutions.cs 10-5 AnimalsSolutions.cs 10-6 AnimalsSolutions.cs 10-7 OlympicsSolution_10_7.cs 10-8 No solution available. 10-9 StackSolution_10_9.cs 10-10 OlympicsSolution_10_10.cs 10-11 Car_10_11.cs 11-1 BirthdayDistance.cs 11-2 Age10000days.cs 11-3 NewYearDaySundays.cs 11-4 BirthdaysOnSunday.cs 11-5 CalendarSimple.cs 11-6 DateISO.cs 11-7 DateISO.cs 11-8 DateISO.cs 11-9 DateISO.cs 11-10 DateISO.cs 11-11 PresidentsImproved.cs 11-12 PresidentsImproved.cs 11-13 PresidentsImproved.cs 11-14 PresidentsImproved.cs 11-15 No solution available. 11-16 No solution available. 11-17 AllOlympicsKL.cs 11-18 UnabbreviatorWithoutIndexers.cs 12-1 BetterDateBetter.cs 12-2 NowKL.cs 12-3 No solution available. 12-4 CalendarsMore.cs 12-5 YearcalendarKL.cs 12-6 WindowsSolutions.cs 12-7 WindowsSolutions.cs 12-8 BankRichPersonAccount.cs 12-9 TimesWithTextualTime.cs 13-1 ExceptionalNumbersModified.cs 13-2 ExceptionalNumbersModified.cs 14-1 FileprintCountingCharacters.cs 14-2 FilecopyCommand.cs 14-3 MirrorKL.cs 14-4 EditorSimple.cs 14-5 SearchMany.cs, SearchManyBetter.cs 14-6 FileCompare.cs 14-7 FilecopyBinaryKL.cs 14-8 Examine.cs 14-9 No solution needed. 14-10 CollectSolutions.cs 14-11 CollectSolutions.cs 14-12 collectSolutions.cs 14-13 CollectSolutions.cs 14-14 CollectSolutions.cs 14-15 No solution available. 15-1 TranslateSolutions.cs 15-2 TranslateSolutions.cs 15-3 No solution available. 15-4 ReverseWithArrayList.cs 15-5 CollectWithArrayList.cs 15-6 EventsSolution_15_6.cs 15-7 CollectSortable.cs 15-8 WeddingdatesDateTime.cs 15-9 EventsDateTime.cs 16-1 EvenoddWithBitOperator.cs 16-2 UplowLowercase.cs 16-3 ShowbitsKL.cs 16-4 ShowbitsKL.cs 16-5 DotsAndDollarsModified.cs 16-6 PlaytimeModified.cs 16-7 StopwatchKL.cs 16-8 AlarmclockKL.cs SOLUTIONS TO THE EXERCISES PRESENTED IN CHAPTERS 3 AND 4: EXERCISE SOLUTION 3-1 1011 1010 B == 186 == BAH 1010 1011 0110 B == 2742 == AB6H 3-2 AF21H == 1010 1111 0010 0001 B == 44833 B29DH == 1011 0010 1001 1101 B == 45725 3-3 1234 == 0000 0100 1101 0010 B == 4D2H 5678 == 0001 0110 0010 1110 B == 162EH 4-1 9 == 1001 B => A3 == 5V, A2 == 0v, A1 == 0V, A0 == 5V 97 == 0110 0001 B => D7 == 0V, D6 == 5V, D5 == 5V, D4 == 0V, D3 == 0V, D2 == 0V, D1 == 0V, D0 == 5V 4-2 The instruction which occupies memory locations 09H and 0AH could be taken away, and the rest of the instructions could be moved two positions towards the beginning of the memory. The instruction in question (15H) loads the register A with value 6CH, but it is not necessary to load register A with this value because the value in question is already present in register A. 4-3 If 00H (zero) were written to memory location 0FH the program would change so that it would print "Hello". The program stops printing characters from memory when it finds a zero. 4-4 If the second byte of the program in address 01H were changed to 0BH, the program would start printing bytes from address 0BH, and thus the letter e would be the first character to be printed. 4-5 No solution needed. Use the simulator. 4-6 The first instruction of the program should be load_register_a_with_value 9 4-7 The second instruction of the program should be load_register_b_with_value 'H' 4-8 Instruction increment_register_b should be replaced with decrement_register_b. Thus both registers should be decremented inside the loop. 4-9 There should be two output_byte_from_register_b instructions inside the loop. The program should look like beginning_of_program: load_register_a_with_value 5 load_register_b_with_value 'A' print_next_letter: output_byte_from_register_b output_byte_from_register_b increment_register_b decrement_register_a jump_if_register_a_zero end_of_program jump_to_address print_next_letter end_of_program: stop_processing 4-10 If the first instruction would be load_register_a_with_value 'x' the program would print xxxxyyyyzzzz If the latter increment_register_a instruction would be removed, the program would print aaaabbbbbbbb 4-11 The instruction load_register_b_with_value ' ' must be replaced with load_register_b_with_value '.' 4-12 See file solution_exercise_4_12.iml in the icom folder. 4-13 See file solution_exercise_4_13.iml in the icom folder.