250 likes | 434 Views
http:// schoolacademy.telerik.com. Telerik School Academy. Meeting #1 – November 2010 – Intro to C# Homework Assignments. Svetlin Nakov. Telerik Corporation. www.telerik.com. Prepare IT Test Questions. Prepare IT Test Questions.
E N D
http://schoolacademy.telerik.com Telerik School Academy Meeting #1 – November 2010 – Intro to C# Homework Assignments Svetlin Nakov Telerik Corporation www.telerik.com
Prepare IT Test Questions • Prepare at least 20 questions for preparation for the National Olympiad's IT test • Prepare at least one question for each category from the official conspectus • Categories are officially published at http://edusoft.fmi.uni-sofia.bg/documents/Conspect0910.pdf • Follow strictly the IT test template: IT-Test-Questions-Template.pptx
.NET Framework • Install at home .NET Framework 4 and Microsoft Visual Studio 2010 (or VS Express) • Write a "Hello World" application in C# • Install at home the .NET Reflector • Play with it by decompiling the System.Console class
C# C# Language Overview
C# Language Overview • Write a C# program that prints all numbers 1…100. • Write a program that prints all the numbers from 1 to N, that are not divisible by 3 and 7. • Write a program that reads from the console a sequence of N integer numbers and returns the minimal and maximal of them. • Write a program that calculates N!/K! for given N and K (1<N<K). • Write a program that reads a number N and calculates the sum of the first N members of the sequence of Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, …
C# Language Overview (2) • Write a program that finds the maximal sequence of equal elements in an array. Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1} {2, 2, 2}. • Write a program that finds the maximal increasing sequence of elements in an array. Example: {3, 2, 3, 4, 2, 2, 4} {2, 3, 4}. • Write a program that finds the most frequent number in an array. Example: {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3} 4 (5 times) • Write a program that finds all prime numbers in the range [1...10 000 000]. Use the sieve of Eratosthenes algorithm (find it in Wikipedia).
C# Language Overview (3) • Write a program that prints to the console which day of the week is today. Use System.DateTime. • Write methods that calculate the surface of a triangle by given: side and an altitude to it; three sides; two sides and an angle between them. Use System.Math. • Write a program that enters file name along with its full file path (e.g. C:\WINDOWS\win.ini), reads its contents and prints it on the console. Find in MSDN how to use System.IO.File.ReadAllText(…). Be sure to catch all possible exceptions and print user-friendly error messages.
C# Language Overview (4) • Write a program that downloads a file from Internet (e.g. http://www.devbg.org/img/Logo-BASD.jpg) and stores it the current directory. Find in Google how to download files in C#. Be sure to catch all exceptions and to free any used resources. • Write a program that reads a string, reverses it and prints it on the console. Example: "sample" "elpmas". • Write a program that reads from a text file a list of strings, sorts them and prints them on the console in alphabetical order.
C# Language Overview (5) • Write a program that finds how many times a substring is contained in a given text (perform case insensitive search). Example: The target substring is "in". The text is as follows: The result is: 9. We are living in an yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.
C# Language Overview (6) • Write a program that parses an URL address given in the format: and extracts from it the [protocol], [server]and[resource]elements. For example from the URL http://www.devbg.org/forum/index.phpthe following information should be extracted: [protocol] = "http" [server] = "www.devbg.org" [resource] = "/forum/index.php" [protocol]://[server]/[resource]
C# Language Overview (7) • Write a program that finds in given array of integers (all belonging to the range [0..1000]) how many times each of them occurs. Example: array = {3, 4, 4, 2, 3, 3, 4, 3, 2} 2 2 times 3 4 times 4 3 times • Write a program that reads a text file and finds all words used in it and how many times each word occurs. Assume that words differing in character casing only are the same.
C# Object-Oriented Programming in C#
OOP in C# • Define a 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 field weekSalary and work-hours per day and method MoneyPerHour() that returns money earned by hour by the worker. Define the proper constructors and properties for this hierarchy. Initialize an array of 10 students and sort them by grade in ascending order. Initialize an array of 10 workers and sort them by money per hour in descending order. 15
OOP in C# (2) • Define abstract class Shape with only one virtual 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 on 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. 16
OOP in C# (3) • Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define suitable constructors and methods according to the following rules: all of this are Animals. 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 produce a sound. Create arrays of different kinds of animals and calculate the average age of each kind of animal using static methods. Create static method in the animal class that identifies the animal by its sound. 17
LINQ Lambda Expressions, Extension Methods and LINQ
LINQ • Create a class student with properties FirstName, LastName, FN, Tel, Email, Marks(aList<int>), GroupNumber. Create a List<Student> with sample students. Select only the students that are from group number 2. Use LINQ query. Order the students by FirstName. • Implement the previous using the same query expressed with extension methods. • Extract all students that have email in abv.bg. Use string methods and LINQ. • Extract all students having phones in Sofia (staring with 02). Use LINQ and regular expressions.
LINQ (2) • Select all students that have at least one mark Excellent (6) into a new anonymous class that has properties – FullName and Marks. Use LINQ. • Write down a similar program that extracts the students with exactly two marks "2". Use extension methods. • Extract all Marksof the students that enrolled in 2006. (The students from 2006 have 06 as their 5-th and 6-th digit in the FN). • Create a class Group with properties GroupNumberand DepartmentName. Introduce a property Group in the Student class. Extract all students from "Mathematics" department. Use the Join operator.
LINQ (3) • Write a program to return the string with maximum length from an array of strings. Use LINQ. • Create a program that extracts all students grouped by GroupName and then prints them to the console. Use LINQ. • Rewrite the previous using extension methods.
Submission Instructions • Homework solutions should be submitted at the following Web site: • http://nakov.devbg.org/schoolacademy-uploads/ • Solutions should be packed in a single ZIP or RAR archive with a following structure • IT-Test– directory for the IT test • CSharp– directory for the C# solutions • OOP – directory for the OOP solutions • LINQ– directory for the LINQ solutions
Further Instructions • The deadline for the homework is: • A week before the next training session • Everybody is free to use help from friends, teachers or Internet • Submission of the same work by different authors may result in a disqualification • Ask your questions in the Telerik School Academy official discussion group: • http://groups.google.com/group/it-olymp
Homework Assignments ? Questions? ? ? ? ? ? ? ? ? ? http://schoolacademy.telerik.com