Skip to content

Solutions to the Exercises from "Fundamentals of Computer Programming with C#" by S. Nakov et al. Exam Practice.

Notifications You must be signed in to change notification settings

Ziezi/Introduction-to-Programming-with-C-Sharp-S.Nakov-et-al-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repository Content

Chapter 1

  1. Install Visual Studio and MSDN Library Documentation.
  2. Describe the class System.Console.
  3. Describe the method System.Console.WriteLine().
  4. Compile and run a program using the Command Line Interface.
  5. "Добър Ден!".
  6. First and last name.
  7. Print $1, 101, 1001$.
  8. Print date and time.
  9. Square root of $12345$.
  10. Write the first 100 terms of the sequence $2, -3, 4 , -5, 6 , -7, 8...$.
  11. Read age and print age after 10 years.
  12. Differences between C# and .NET Framework.
  13. Compile a list of the most famous program languages; their differences from C#.
  14. Decompile Exercise 5 . Use ILSpy-2.3.1 - Decompiler

Chapter 2

  1. Match values with appropriate types.
  2. Witch of the values could be assigned to float, double and decimal.
  3. Calculate with precision up to the sixth digit after the decimal point.
  4. Initialize an int with the hexadecimal value 256.
  5. Initialize a char with the symbol with Unicode value 72.
  6. Define a variable of type bool named isMale and initialize it properly.
  7. Define two strings, concatenate them and assign the result to variable of type object.
  8. Define two strings, concatenate them and assign the result to variable of type object; Initialize a string with the value held in the variable of type object.
  9. Use escape sequences or @-quoted strings to declare a string containing " or \.
  10. Print a shape of heart using the symbol o.
  11. Print an isosceles triangle using the symbol © (copyright).
  12. Company employees first-, last- name, gender and ID.
  13. Swap the values of two int variables.

Chapter 3

  1. Check whether a number is odd or even.
  2. Check if a number is perfectly divisble by $5$ and $7$.
  3. Is the 3rd least significant digit is 7.
  4. Is the 3rd bit of a number 0 or 1. MSB enumeration from right to left LSB
  5. Area of a trapezium from given a, b and h.
  6. Area and circumference of a rectangle from given length and height.
  7. Calculate the weight of an human on the Moon, given his weight on Earth.
  8. Check if a point is within a given circle.
  9. Check if a point is within a given circle and out of a rectangle.
  10. Number's digits manipulation: sum, reversed digits, swap first/second and last/third.
  11. Print the bit on position p in the number n.
  12. Given a number n, check if the bit on position p has a value v = 1.
  13. Given a number n, a position p and a bit value v. Write a program that sets the bit at position p to value v in number n.
  14. Check if a number is prime.
  15. Swap the bits at positions 3, 4 , 5 with those at positions 24, 25, 26.
  16. Swap k number of bits starting a position p with k number of bits starting at position q.

Chapter 4

  1. Read1 three ints from the console and print their values. 1. "Read"/"Write" to/from Standard Input/Output.
  2. Read a radius of circle , r, and print its area and circumference.
  3. Read and print company data: name, address, phone number, FAX, website and manager (first-, last- name and phone number).
  4. Output formatting: print three columns of numbers with: width = 10, left aligned, first column: hexadecimal , second column: positive floating point, negative floating point. The last two columns to be rounded up to the 2nd digit after the decimal point.
  5. Find perfectly divisible to 5 numbers within [a,b], where a and b read from console.
  6. Read two numbers, print the largest without the use of conditional expressions.
  7. Read five numbers and print the largest of them.
  8. Read five numbers and print their sum. (Check input validity).
  9. Find the real roots of the quadratic equation, read the coefficients a, b, c from the console.
  10. Sum n numbers, read them from console.
  11. Read a number n, print all the numbers within [1, n] on a new line.
  12. Print the first 100 terms of Fibonacci sequence.
  13. Accumulate the first 1000 terms of the Harmonic Series.

Chapter 5

  1. Write an if construction such that it swaps the values of two variables if the first is larger than the second.
  2. Print the sign (+ , -) of the product of thee numbers without actually calculating it. (Use if statements)
  3. Find the largest value among the values of three numbers.
  4. Sort three real integers in descending order using nested if statements.
  5. Read an integer [0,9] and print its name in Bulgarian.
  6. Print the roots (0 ,1 or 2 real roots) of the quadratic equation.
  7. Find the largest among 5 integers.
  8. Define variables of type int, double and string. Depending on their type, increment the value if the type is within the first two, append * if it is the last; print them. (Use switch statement)
  9. Given five int values, find all subsets (if existent) that sum up to 0.
  10. Apply the following rules for the number, n (within $[1,9]$) read from the console: if n in: $[1,3]$ -> n * 10 ; $[4,6]$ -> n * 100; $[7,9]$ -> n * 1000.
  11. Read a number n within [0,999] and print its name in Bulgarian language.

Chapter 6

  1. Read a number n. Print the numbers from $1$ to $n$.
  2. Read a number n. Print all the numbers within $[1, n]$ not divisible by $3$ and $7$.
  3. Read a sequence of integers. Print the numbers with min and max values.
  4. Print all the possible playing cards. (52 in total, 4 colours and 13 ranks)
  5. Read a number n. Print the first n terms of the Fibonacci sequence.
  6. Read n and k. Print $\frac{n!}{k!}$, where $1 < k < n$.
  7. Read n and k. Print $\frac{n! * k!}{(n - k)!}$, where $1 < k < n$.
  8. Read n and calculate the nth Catalan number.
  9. Read n and x. Calculate the first n terms of the series $\frac{n!}{x^n}$.
  10. Read n, where n < 20 and print a matrix where each next row contains the incremented values of the above, starting with 1,2,...n.
  11. Calculate the number of trailing zeroes of a factorial of a given value n.
  12. Convert a number from decimal to binary representation.
  13. Convert a number from binary to decimal representation.
  14. Convert a number from decimal to hexadecimal representation.
  15. Convert a number from hexadecimal to decimal representation.
  16. Read n, print the numbers within $[1,n]$ in random order.
  17. Read a and b. Find the greatest common divisor of a and b.
  18. Read n. Print n x n matrix with values increasing in a clockwise inward pattern, starting from element with matrix index 00 and value 1.

Chapter 7

  1. Define and print an int array of size 20 with elements initialized to values equal to their index multiplied by 5.
  2. Read two arrays and check if they are identical.
  3. Compare two char arrays lexicographically.
  4. Find the longest sub-array of adjacent elements with identical values.
  5. Find the longest sub-array of adjacent elements with increasing values.
  6. Find the longest sub-array (with the smallest indexes) of consecutive elements with increasing values.
  7. Read n and k. Read n elements to populate an int array. Find k adjacent elements with max sum.
  8. Implement selection sort algorithm that sorts an int array in increasing order.
  9. Find the int sub-array with max sum.
  10. Find mode of int array .
  11. Read sum. Find whether there is a sub-array of elements that sum up to sum.
  12. Read n. Print n x n matrix with values increasing in different patterns (in terms of the indexes of the matrix elements).
  13. Read n and m. Define a n x m matrix and populate its elements. Find a 3 x 3 submatrix with maximum sum of its elements.
  14. Find longest sequence (horizontal, vertical, diagonal) of identical strings within a 2D string array.
  15. Read a word and print the indexes of its letters, where the letters of the English alphabet are within $[0,25]$.
  16. Implement binary search for int array.
  17. Implement merge sort for int array.
  18. Implement quick sort for int array.
  19. Find primes within $[1, 10000000]$.
  20. Check if an int array of n elements contains a sub-array with elements that sum up to s.
  21. Check if an int array of n elements contains a sub-array with k elements that sum up to s.
  22. Read n elements to populate an int array; remove minimal number of elements such that the array is sorted in ascending order.
  23. Print all permutations of n elements.
  24. Print all k variations of n elements. (no repetition)
  25. Print all k combinations of n elements. (no repetition)
  26. Go through matrix elements in specific pattern: in parallel/perpendicularly to the main diagonal starting from the bottom.
  27. Find the largest region of horizontally or vertically adjacent elements with equal values within a 2D int matrix.

Chapter 8

  1. Convert int and float numbers into binary strings.
  2. Convert a binary string to hexadecimal and decimal.
  3. Convert hexadecimal to decimal and binary.
  4. Convert decimal to binary.
  5. Convert binary to decimal.
  6. Convert decimal to hexadecimal.
  7. Convert hexadecimal to decimal.
  8. Convert hexadecimal to binary.
  9. Convert binary to hexadecimal.
  10. Convert binary to decimal using Horner's method.
  11. Convert Roman numeral to Arabic.
  12. Convert Arabic numeral to Roman.
  13. Given N, S and D, where 2 <= S and 16 >= D. Convert number N from base S to base D.
  14. Store 0.000001 in float, double and decimal and sum it 50000000 times. Observe rounding error and execution time.
  15. Extract sign, exponent and mantissa of float number.

Chapter 9

From now on, it is implied that all the tasks must be implemented via methods.

  1. Print a greeting by name read from standard input. Create a Unit Test for the implemented method.
  2. Implement GetMax(int a, int b) returning the largest of the two input parameters.
  3. Return the English name of the last digit of a number.
  4. Read an number n. Check how many times n occurs in an integer array. Write a test unit for the method.
  5. Read an index n. Check if an element with index n is smaller- or greater- than its two adjacent. Write a test unit.
  6. Find the first array element larger than its two adjacent.
  7. Reverse integer digits.
  8. Sum large integers represented as arrays, using Little-Endian representation.
  9. Write a method that finds element with max value in sub-array. Use the method to sort an array in ascending / descending order.
  10. Calculate n!, where 1 < n <= 100. Use BigInteger or array representaion.
  11. Implement a program that contains a menu prompting the use to: reverses integer digits, calculates arithmetic mean, finds the root of the linear eqation. Checks input validity for the three cases.
  12. Sum polynomials.
  13. Multiply polynomials.

Chapter 10

1. First steps in Coding

  1. Print "Hello C#".
  2. Simple Algebraic Expression.
  3. GUI application: simple summator.
  4. Web application: simple summator.
  5. Print the numbers from 1 to 20, each on a new line.
  6. Print a right-angle triangle using the symbol *.
  7. Read base a and height b, calculate the area of rectangle.
  8. Read side length N, print a square of asterisks with side lenght N.

2. Simple calculations

  1. Visual Studio blank solution. Collect projects related to different exercises under common solution.
  2. Square area.
  3. Inch to centimeter unit converter.
  4. Greetings by personal name.
  5. Text and character concatenation.
  6. Trapezium area.
  7. Circle area and perimeter.
  8. Rectangle area.
  9. GUI application BGN to EUR currency converter.
  10. Triangle area.
  11. Celsius to Fahrenheit degrees converter.
  12. Degrees to radians angle units converter.
  13. GUI application USD to BGN currency converter.
  14. Multiple currency converter.
  15. Astronomical date manipulation.
  16. GUI application push a button appearing on random location.
  17. Number of classroom seats.

3. Simple conditions

  1. Area of figures.
  2. Bonus score.
  3. Cheap transport.
  4. GUI Currency converter.
  5. Equal words.
  6. Even or odd.
  7. Excellent or not.
  8. Excellent result.
  9. Greater number.
  10. Metric converter.
  11. Number from 1 to 100 to text.
  12. Numbers from 100 to 200.
  13. Number to text.
  14. Password guess.
  15. Simple conditions.
  16. Speed info.
  17. Sum seconds.
  18. Swimming pool pipes.
  19. Three equal numbers.
  20. Time in 15 minutes.

4. Complex conditions

  1. Cinema.
  2. Fruit or Vegetable.
  3. Fruit shop.
  4. Invalid Number.
  5. On time for the Exam.
  6. Personal Title.
  7. GUI Point and Rectangle.
  8. Point in Rectangle.
  9. Point in the figure.
  10. Point on Rectangle border.
  11. Small shop.
  12. Trade comission.
  13. Volleyball.
  14. Voyage.

5. Loops

  1. Equal Pairs.
  2. Half Sum Element.
  3. Histogram.
  4. Latin Letters.
  5. Left and Right Sum.
  6. Max Number.
  7. Min Number.
  8. Numbers 1 to 100.
  9. Numbers ending in 7.
  10. Odd - Even Position.
  11. Odd - Even sum.
  12. Perfect division.
  13. Sum numbers.
  14. GUI Turtle Graphics.
  15. Vowels Sum.

6. Drawing with Loops

  1. Butterfly.
  2. Christmas Tree.
  3. Diamond.
  4. Draw fort.
  5. House.
  6. Triangle with dollars.
  7. Rectangle of 10 by 10 Stars.
  8. Rectangle of N by N stars.
  9. Rhombus stars.
  10. Square of stars.
  11. Sunglasses.
  12. Web Application Rattings.

7. Advanced Loops

  1. Check prime.
  2. Enter even number.
  3. Even powers of 2.
  4. Factorial.
  5. Fibonacci.
  6. Web app Fruits web game.
  7. Greatest common divisor.
  8. Number pyramid.
  9. Numbers from 1 to N with step 3.
  10. Numbers in range.
  11. Numbers from N to 1.
  12. Number table.
  13. Powers of 2.
  14. Sequence of 2k + 1.
  15. Sum digits.
  16. Magic numbers.
  17. Stupid password generator.

Exam date: 12.04.2014

1. Morning

  1. Triangle.
  2. Pairs.
  3. House.
  4. Magic Dates.
  5. Bits Killer.

2. Evening

Exam date: 14.04.2014

1. Morning

  1. Fruit Market.
  2. Biggest triple.
  3. Wine Glass.
  4. Longest Alphabetical Word.
  5. Bit Shooter.

2. Evening

  1. Inside The Building.
  2. Student Cables.
  3. Programmer DNA.
  4. Magic Car Numbers.
  5. Bit flipper.

Exam date: 29.03.2015

1. Morning

  1. Torrent Pirate.
  2. Basket Battle.
  3. Dumbbell.
  4. Encrypted Matrix.
  5. Game of Bits.

1. Evening

  1. Array Matcher.
  2. Currency Check.
  3. Dream Item.
  4. Knight Path.
  5. Magic Wand.

Exam date: 17.03.2016

  1. Beer Stock.
  2. Cake Tycoon.
  3. Emergency Repairs.
  4. Illuminati Lock.
  5. Master Herbalist.


Remarks:
No enumeration of the (sub)chapter contents, e.g 3.1; 3.2
Page 265, Proposed Solution to Exercise 15: upper case / lower case ? `(int) ch - (int) 'A'`, `(int) ch - (int) 'a'`.
Errata:
Page 260-1, Exercise 14 : Matrix rows next to each other and on next page.
Page 262, Exercise 26 : Firtst row of right matrix appended at the bottom of the left.
Page 330, Triangles with different size: all but two lines from the triangle on the rhs of the picture indented.
The word "съответно" in Chapter 9 appears a lot.

OS: Windows 10
IDE: Visual Studio 2015




MIT License

Copyright (c) 2017 Chris B. Kirov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Solutions to the Exercises from "Fundamentals of Computer Programming with C#" by S. Nakov et al. Exam Practice.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages