Common Type System

  1. Define a classStudent, which contains data about a student – first, middle and last name, SSN, permanent address, mobile phone e-mail, course, specialty, university, faculty. Use an enumeration for the specialties, universities and faculties. Override the standard methods, inherited by System.Object:Equals(),ToString(),GetHashCode()and operators==and!=.
  2. Add implementations of the ICloneableinterface. The Clone()method should deeply copy all object’s fields into a new object of type Student.
  3. Implement the IComparable<Student>interface to compare students by names (as first criteria, in lexicographic order) and by social security number (as second criteria, in increasing order).GitHub Link
  4. Create a class Person with two fields – name and age. Age can be left unspecified (may contain nullvalue. Override ToString() to display the information of a person and if age is not specified – to say so. Write a program to test this functionality.GitHub Link
  5. Define a class BitArray64 to hold 64 bit values inside an ulong value. Implement IEnumerable<int> and Equals(…), GetHashCode(), [], == and !=.GitHub Link
  6. * Define the data structure binary search tree with operations for “adding new element”, “searching element” and “deleting elements”. It is not necessary to keep the tree balanced. Implement the standard methods from System.Object – ToString(), Equals(…),GetHashCode()and the operators for comparison ==and!=.Add and implement the ICloneable interface for deep copy of the tree. Remark: Use two types – structure BinarySearchTree (for the tree) and classTreeNode (for the tree elements). Implement IEnumerable<T> to traverse the tree.GitHub Link

Object Oriented Programming Fundamental Principles Part II

  1. Define abstract class Shape with only one abstract method CalculateSurface() and fields width and height. Define two new classes Triangle and Rectangle that implement the virtual method and return the surface of the figure (height*width for rectangle and height*width/2 for triangle). Define class Circle and suitable constructor so that at initialization height must be kept equal to width and implement the CalculateSurface() method. Write a program that tests the behavior of the CalculateSurface() method for different shapes(Circle, Rectangle, Triangle) stored in an array.GitHub Link
  2. A bank holds different types of accounts for its customers: deposit accounts, loan accounts and mortgage accounts. Customers could be individuals or companies.
    All accounts have customer, balance and interest rate (monthly based). Deposit accounts are allowed to deposit and with draw money. Loan and mortgage accounts can only deposit money.All accounts can calculate their interest amount for a given period (in months). In the common case its is calculated as follows: number_of_months * interest_rate.Loan accounts have no interest for the first 3 months if are held by individuals and for the first 2 months if are held by a company.

    Deposit accounts have no interest if their balance is positive and less than 1000.

    Mortgage accounts have ½ interest for the first 12 months for companies and no interest for the first 6 months for individuals.

    Your task is to write a program to model the bank system by classes and interfaces. You should identify the classes, interfaces, base classes and abstract actions and implement the calculation of the interest functionality through overridden methods.

    GitHub Link

  3. Define a class InvalidRangeException<T> that holds information about an error condition related to invalid range. It should hold error message and a range definition [start … end].
    Write a sample application that demonstrates the InvalidRangeException<int>and InvalidRangeException<DateTime>by entering numbers in the range [1..100] and dates in the range [1.1.1980 … 31.12.2013].GitHub Link

Object Oriented Programming Fundamental Principles Part I

 

  1. We are given a school. In the school there are classes of students. Each class has a set of teachers. Each teacher teaches a set of disciplines. Students have name and unique class number. Classes have unique text identifier. Teachers have name. Disciplines have name, number of lectures and number of exercises. Both teachers and students are people. Students, classes, teachers and disciplines could have optional comments (free text block).
    Your task is to identify the classes (in terms of OOP) and their attributes and operations, encapsulate their fields, define the class hierarchy and create a class diagram with Visual Studio. 

    GitHub Link 

  2. Define abstract class Human with first name and last name. Define new class Student which is derived from Human and has new field – grade. Define class Worker derived from Human with new property WeekSalary and WorkHoursPerDay and method MoneyPerHour() that returns money earned by hour by the worker. Define the proper constructors and properties for this hierarchy. Initialize a list of 10 students and sort them by grade in ascending order (use LINQ or OrderBy() extension method). Initialize a list of 10 workers and sort them by money per hour in descending order. Merge the lists and sort them by first name and last name.GitHub Link
  3. Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods. Dogs, frogsand cats are Animals. All animals can produce sound (specified by the ISound interface). Kittens and tomcats are cats. All animals are described by age, name and sex. Kittens can be only female and tomcats can be only male. Each animal produces a specific sound. Create arrays of different kinds of animals and calculate the average age of each kind of animal using a static method (you may use LINQ)GitHub Link

Extension Methods, Lambda Expressions and LINQ

  1. Implement an extension method Substring(int index, int length) for the class StringBuilder that returns new StringBuilder and has the same functionality as Substring in the class String.GitHub Link
  2. Implement a set of extension methods for IEnumerable<T> that implement the following group functions: sum, product, min, max, average.GitHub Link
  3. Write a method that from a given array of students finds all students whose first name is before its last name alphabetically. Use LINQ query operators.GitHub Link
  4. Write a LINQ query that finds the first name and last name of all students with age between 18 and 24.GitHub Link
  5. Using the extension methods OrderBy() and ThenBy() with lambda expressions sort the students by first name and last name in descending order. Rewrite the same with LINQ.GitHub Link
  6. Write a program that prints from given array of integers all numbers that are divisible by 7 and 3. Use the built-in extension methods and lambda expressions. Rewrite the same with LINQ.GitHub Link
  7. Using delegates write a class Timer that has can execute certain method at each t seconds.GitHub Link

Defining Classes – Part II

  1. Create a structure Point3D to hold a 3D-coordinate {X, Y, Z} in the Euclidian 3D space. Implement the ToString() to enable printing a 3D point.
  2. Add a private static read-only field to hold the start of the coordinate system – the point O{0, 0, 0}. Add a static property to return the point O.
  3. Write a static class with a static method to calculate the distance between two points in the 3D space.
  4. Create a class Path to hold a sequence of points in the 3D space. Create a static class PathStorage with static methods to save and load paths from a text file. Use a file format of your choice.GitHub Link
  5. Write a generic class GenericList<T> that keeps a list of elements of some parametric type T. Keep the elements of the list in an array with fixed capacity which is given as parameter in the class constructor. Implement methods for adding element, accessing element by index, removing element by index, inserting element at given position, clearing the list, finding element by its value and ToString(). Check all input parameters to avoid accessing elements at invalid positions.
  6. Implement auto-grow functionality: when the internal array is full, create a new array of double size and move all elements to it.
  7. Create generic methods Min<T>() and Max<T>() for finding the minimal and maximal element in the  GenericList<T>. You may need to add a generic constraints for the type T.

    GitHub Link

  8. Define a class Matrix<T> to hold a matrix of numbers (e.g. integers, floats, decimals).
  9. Implement an indexer this[row, col] to access the inner matrix cells.
  10. Implement the operators + and – (addition and subtraction of matrices of the same size) and * for matrix multiplication. Throw an exception when the operation cannot be performed. Implement the true operator (check for non-zero elements).

    GitHub Link

  11. Create a [Version] attribute that can be applied to structures, classes, interfaces, enumerations and methods and holds a version in the format major.minor (e.g. 2.11). Apply the version attribute to a sample class and display its version at runtime.

    GitHub Link

Defining Classes – Part I

  1. Define a class that holds information about a mobile phone device: model, manufacturer, price, owner, battery characteristics (model, hours idle and hours talk) and display characteristics (size and number of colors). Define 3 separate classes (class GSM holding instances of the classes Battery and Display).

  2. Define several constructors for the defined classes that take different sets of arguments (the full information for the class or part of it). Assume that model and manufacturer are mandatory (the others are optional). All unknown data fill with null.

  3. Add an enumeration BatteryType (Li-Ion, NiMH, NiCd, …) and use it as a new field for the batteries.

  4. Add a method in the GSM class for displaying all information about it. Try to override ToString().

  5. Use properties to encapsulate the data fields inside the GSM, Battery and Display classes. Ensure all fields hold correct data at any given time.

  6. Add a static field and a property IPhone4S in the GSM class to hold the information about iPhone 4S.

  7. Write a class GSMTest to test the GSM class:
    • ­Create an array of few instances of the GSM class.
    • ­Display the information about the GSMs in the array.
    • ­Display the information about the static property IPhone4S.
  8. Create a class Call to hold a call performed through a GSM. It should contain date, time, dialed phone number and duration (in seconds).

  9. Add a property CallHistory in the GSM class to hold a list of the performed calls. Try to use the system class List<Call>.

  10. Add methods in the GSM class for adding and deleting calls from the calls history. Add a method to clear the call history.

  11. Add a method that calculates the total price of the calls in the call history. Assume the price per minute is fixed and is provided as a parameter.

  12. Write a class GSMCallHistoryTest to test the call history functionality of the GSM class.
    • ­Create an instance of the GSM class.
    • ­Add few calls.
    • ­Display the information about the calls.
    • ­Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history.
    • ­Remove the longest call from the history
    • and calculate the total price again.Finally clear the call history and print it.

    GitHub Link

Operators and Expressions

  1. Write an expression that checks if given integer is odd or even.
    GitHub Link

  2. Write a boolean expression that checks for given integer if it can be divided (without remainder) by 7 and 5 in the same time.
    GitHub Link

  3. Write an expression that calculates rectangle’s area by given width and height.
    GitHub Link

  4. Write an expression that checks for given integer if its third digit (right-to-left) is 7. E. g. 1732 -> true.
    GitHub Link

  5. Write a boolean expression for finding if the bit 3 (counting from 0) of a given integer is 1 or 0.
    GitHub Link

  6. Write an expression that checks if given point (x,  y) is within a circle K(O, 5).
    GitHub Link

  7. Write an expression that checks if given positive integer number n (n ≤ 100) is prime. E.g. 37 is prime.
    GitHub Link

  8. Write an expression that calculates trapezoid’s area by given sides a and b and height h.
    GitHub Link

  9. Write an expression that checks for given point (x, y) if it is within the circle K( (1,1), 3) and out of the rectangle R(top=1, left=-1, width=6, height=2).
    GitHub Link

  10. Write a boolean expression that returns if the bit at position p (counting from 0) in a given integer number v has value of 1. Example: v=5; p=1 -> false.
    GitHub Link

  11. Write an expression that extracts from a given integer i the value of a given bit number b. Example: i=5; b=2 -> value=1.
    GitHub Link

  12. We are given integer number n, value v (v=0 or 1) and a position p. Write a sequence of operators that modifies n to hold the value v at the position p from the binary representation of n.

    Example: n = 5 (00000101), p=3, v=1 -> 13 (00001101)

    n = 5 (00000101), p=2, v=0 à 1 (00000001)
    GitHub Link

  13. Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.
    GitHub Link

Primitive Data Types and Variables

  1. Declare five variables choosing for each of them the most appropriate of the types byte, sbyte, short, ushort, int, uint, long, ulong to represent the following values: 52130, -115, 4825932, 97, -10000.
    GitHub Link
  2. Which of the following values can be assigned to a variable of type float and which to a variable of type double: 34.567839023, 12.345, 8923.1234857, 3456.091?
    GitHub Link
  3. Write a program that safely compares floating-point numbers with precision of 0.000001. Examples:
    (5.3 ; 6.01) -> false;  (5.00000001 ; 5.00000003) -> true
    GitHub Link
  4. Declare an integer variable and assign it with the value 254 in hexadecimal format. Use Windows Calculator to find its hexadecimal representation.
    GitHub Link
  5. Declare a character variable and assign it with the symbol that has Unicode code 72. Hint: first use the Windows Calculator to find the hexadecimal representation of 72.
    GitHub Link
  6. Declare a boolean variable called isFemale and assign an appropriate value corresponding to your gender.
    GitHub Link
  7. Declare two string variables and assign them with “Hello” and “World”. Declare an object variable and assign it with the concatenation of the first two variables (mind adding an interval). Declare a third string variable and initialize it with the value of the object variable (you should perform type casting).
    GitHub Link

  8. Declare two string variables and assign them with following value:
    Do the above in two different ways: with and without using quoted strings.
    GitHub Link

  9. Write a program that prints an isosceles triangle of 9 copyright symbols ©. Use Windows Character Map to find the Unicode code of the © symbol. Note: the © symbol may be displayed incorrectly.
    GitHub Link

  10. A marketing firm wants to keep record of its employees. Each record would have the following characteristics – first name, family name, age, gender (m or f), ID number, unique employee number (27560000 to 27569999). Declare the variables needed to keep the information for a single employee using appropriate data types and descriptive names.
    GitHub Link

  11. Declare  two integer variables and assign them with 5 and 10 and after that exchange their values.
    GitHub Link

  12. Find online more information about ASCII (American Standard Code for Information Interchange) and write a program that prints the entire ASCII table of characters on the console.
    GitHub Link

  13. Create a program that assigns null values to an integer and to double variables. Try to print them on the console, try to add some values or the null literal to them and see the result.
    GitHub Link

  14. A bank account has a holder name (first name, middle name and last name), available amount of money (balance), bank name, IBAN, BIC code and 3 credit card numbers associated with the account. Declare the variables needed to keep the information for a single bank account using the appropriate data types and descriptive names.
    GitHub Lin

Introduction-to-Programming

  1. Familiarize yourself with:
    ­ Microsoft Visual Studio
    ­ Microsoft Developer Network (MSDN) Library Documentation
    ­ Find information about Console.WriteLine() method.
    GitHub Link
  2. Create, compile and run a “Hello C#” console application.
    GitHub Link
  3. Modify the application to print your name.
    GitHub Link
  4. Write a program to print the numbers 1, 101 and 1001.
    GitHub Link
  5. Install at home:
    ­Microsoft Visual Studio (or Visual Studio Express)
    GitHub Link
  6. Create console application that prints your first and last name.
    GitHub Link
  7. Create a console application that prints the current date and time.
    GitHub Link
  8. Create a console application that calculates and prints the square of the number 12345.
    GitHub Link
  9. Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, …
    GitHub Link
  10. Provide a short list with information about the most popular programming languages. How do they differ from C#?
    GitHub Link
  11. Describe the difference between C# and .NET Framework.
    GitHub Link
  12. * Write a program to read your age from the console and print how old you will be after 10 years.
    GitHub Link