Download 9. Homework

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to C# and
Databases - Homework
Doncho Minkov
Technical Trainer
http://www.minkov.it
Telerik School Academy
schoolacademy.telerik.com
C# Overview
1.
Write a program that, for a given two integer
numbers N and X, calculates the sum
S = 1 + 1!/X + 2!/X2 + … + N!/XN
2.
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, …
Each member of the Fibonacci sequence (except the
first two) is a sum of the previous two members.
3.
Write a program that calculates the greatest
common divisor (GCD) of given two numbers. Use
the Euclidean algorithm (find it in Internet).
2
C# Overview (2)
4.
Write a program that fills a matrix of size (N, N) as
shown in the examples (for N=4):
a)
*c)
16 15 13 10
14 12 9 6
11 8 5 3
7 4 2 1
1
2
3
4
12 11 10
13 16 9
14 15 8
5 6 7
b)
*d)
7
4
2
1
11 14 16
8 12 15
5 9 13
3 6 10
10 11 12 13
9 2 3 14
8 1 4 15
7 6 5 16
3
C# Overview (3)
5.
* Write a program that converts a number in the
range [0...999] to a text corresponding to its
English pronunciation. Examples:
0  "Zero"
273  "Two hundred seventy three"
400  "Four hundred"
501  "Five hundred and one"
711  "Severn hundred and eleven"
4
C# Overview (4)
6.
Write a program that reads a list of words,
separated by spaces and prints the list in an
alphabetical order.
7.
Write a program to check if in a given expression
the brackets are put correctly. Example of
correct expression: ((a+b)/5-d). Example of
incorrect expression: )(a+b)).
8.
Write a program that generates and prints to the
console 10 random values in the range [100,200].
9.
Write a program that prints to the console which
day of the week is today. Use System.DateTime.
5
C# Overview (5)
10.
Write a program that parses an URL address
given in the format:
[protocol]://[server]/[resource]
and extracts from it the [protocol], [server]
and [resource] elements. For example from
the URL
http://www.devbg.org/forum/index.php
the following information should be extracted:
[protocol] = "http"
[server] = "www.devbg.org"
[resource] = "/forum/index.php"
6
C# OOP
11.
We are given a library of books. Define classes
for the library and the books. The library should
have name and a list of books. The books have
title, author, publisher, year of publishing and
ISBN. Keep the books in List<Book> (first find
how to use the class
System.Collections.Generic.List<T>).
12.
Implement methods for adding, searching by
title and author, displaying and deleting books.
13.
Write a test class that creates a library, adds few
books to it and displays them. Find all books by
Nakov, delete them and print again the library.
7
LINQ
14.
Create a class student with properties FirstName,
LastName, FN, Tel, Email, Marks (a List<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.
15.
Implement the previous using the same query
expressed with extension methods.
16.
Extract all students that have email in abv.bg. Use
string methods and LINQ.
17.
Extract all students with phones in Sofia. Use LINQ
and regular expressions.
8
LINQ (2)
18.
Select all students that have at least one mark
Excellent (6) into a new anonymous class that has
properties – FullName and Marks. Use LINQ.
19.
Write down a similar program that extracts the
students with exactly two marks "2". Use extension
methods.
20.
Extract all Marks of the students that enrolled in
2006. (The students from 2006 have 06 as their 5-th
and 6-th digit in the FN).
22.
Create a program that extracts all students grouped
by GroupName and then prints them to the console.
Use LINQ.
9
Entity Framework
23.
Using the Visual Studio Entity Framework designer
create a ObjectContext for the Northwind
database
24.
Create a DAO class with static methods which
provide functionality for inserting, modifying and
deleting customers. Write a testing class.
25.
Write a method that finds all customers who have
orders made in 1997 and shipped to Canada.
26.
Implement previous by using native SQL query and
executing it through the ObjectContext.
27.
Write a method that finds all the sales by specified
region and period (start / end dates).
Entity Framework (2)
28.
Create a database called NorthwindTwin with the
same structure as Northwind using the features
from ObjectContext. Find for the API for schema
generation in MSDN or in Google.
29.
Try to open two different data contexts and perform
concurrent changes on the same records. What will
happen at SaveChanges()? How to deal with it?
30.
By inheriting the Employee entity class create a class
which allows employees to access their
corresponding territories as property of type
EntitySet<T>.
Entity Framework (3)
31.
Create a method that places a new order in the
Northwind database. The order should contain
several order items. Use transaction to ensure the
data consistency.
32.
Create a stored procedures in the Northwind
database for finding the total incomes for given
supplier name and period (start date, end date).
Implement a C# method that calls the stored
procedure and returns the retuned record set.
12