CSharp part2 – Strings and Text Processing

Posted in Homeworks Telerik - CSharp Part2 on February 2, 2013 by krstan4o

Това са домашните ми от темата по Стрингове и текстообработка:

CSharp

Условия:

1. Describe the strings in C#. What is typical for the string data type? Describe the most important methods of the String class.
2. Write a program that reads a string, reverses it and prints the result at the console.
Example: “sample” => “elpmas”.
3. 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)).
4.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:
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.
The result is: 9.
5.You are given a text. Write a program that changes the text in all regions surrounded by the tags <upcase> and </upcase> to uppercase. The tags cannot be nested. Example:
We are living in a <upcase>yellow submarine</upcase>. We don’t have <upcase>anything</upcase> else.
The expected result:
We are living in a YELLOW SUBMARINE. We don’t have ANYTHING else.
6. Write a program that reads from the console a string of maximum 20 characters. If the length of the string is less than 20, the rest of the characters should be filled with ‘*’. Print the result string into the console.
7. Write a program that encodes and decodes a string using given encryption key (cipher). The key consists of a sequence of characters. The encoding/decoding is done by performing XOR (exclusive or) operation over the first letter of the string with the first of the key, the second – with the second, etc. When the last key character is reached, the next is the first.
8. Write a program that extracts from a given text all sentences containing given word.
Example: The word is “in“. The text is:
We are living in a 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.
The expected result is:
We are living in a yellow submarine.
We will move out of it in 5 days.
Consider that the sentences are separated by “.” and the words – by non-letter symbols.
9. We are given a string containing a list of forbidden words and a text containing some of these words. Write a program that replaces the forbidden words with asterisks. Example:
Microsoft announced its next generation PHP compiler today. It is based on .NET Framework 4.0 and is implemented as a dynamic language in CLR.

 

Words: “PHP, CLR, Microsoft”
The expected result:
********* announced its next generation *** compiler today. It is based on .NET Framework 4.0 and is implemented as a dynamic language in ***.
10. Write a program that converts a string to a sequence of C# Unicode character literals. Use format strings. Sample input:
Hi!

 

Expected output:
\u0048\u0069\u0021
11. Write a program that reads a number and prints it as a decimal number, hexadecimal number, percentage and in scientific notation. Format the output aligned right in 15 symbols.
12. 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”
13. Write a program that reverses the words in given sentence.
Example: “C# is not C++, not PHP and not Delphi!” => “Delphi not and PHP, not C++ not is C#!”.
14. A dictionary is stored as a sequence of text lines containing words and their explanations. Write a program that enters a word and translates it by using the dictionary. Sample dictionary:
.NET – platform for applications from Microsoft
CLR – managed execution environment for .NET
namespace – hierarchical organization of classes
15. Write a program that replaces in a HTML document given as string all the tags <a href=”…”>…</a> with corresponding tags [URL=…]…/URL]. Sample HTML fragment:
<p>Please visit <a href=”http://academy.telerik. com”>our site</a> to choose a training course. Also visit <a href=”www.devbg.org”>our forum</a> to discuss the courses.</p>
Output:
<p>Please visit [URL=http://academy.telerik. com]our site[/URL] to choose a training course. Also visit [URL=www.devbg.org]our forum[/URL] to discuss the courses.</p>
16. Write a program that reads two dates in the format: day.month.year and calculates the number of days between them. Example:
Enter the first date: 27.02.2006
Enter the second date: 3.03.2004
Distance: 4 days
17. Write a program that reads a date and time given in the format: day.month.year hour:minute:second and prints the date and time after 6 hours and 30 minutes (in the same format) along with the day of week in Bulgarian.
18. Write a program for extracting all email addresses from given text. All substrings that match the format <identifier>@<host>…<domain> should be recognized as emails.
19. Write a program that extracts from a given text all dates that match the format DD.MM.YYYY. Display them in the standard date format for Canada.
20. Write a program that extracts from a given text all palindromes, e.g. “ABBA”, “lamal”, “exe“.
21. Write a program that reads a string from the console and prints all different letters in the string along with information how many times each letter is found.
22. Write a program that reads a string from the console and lists all different words in the string along with information how many times each word is found.
23. Write a program that reads a string from the console and replaces all series of consecutive identical letters with a single one. Example: “aaaaabbbbbcdddeeeedssaa” => “abcdedsa“.
24. Write a program that reads a list of words, separated by spaces and prints the list in an alphabetical order.
25. Write a program that extracts from given HTML file its title (if available), and its body text without the HTML tags. Example:
<html>
  <head><title>News</title></head>
    Academy</a>aims to provide free real-world practical
    training for young people who want to turn into
    skillful .NET software engineers.</p></body>
</html>
Ето ги и решенията ми на това дълго домашно :):   BE4AA7E888E32AB67B7ACC6E4D413DA63AA51C2C_small

CSharp part2 – TextFiles

Posted in Homeworks Telerik - CSharp Part2 on January 28, 2013 by krstan4o

Ето го и домашното ми от Текстови файлове:

CSharp

Условия:

1. Write a program that reads a text file and prints on the console its odd lines.

2. Write a program that concatenates two text files into another text file.
3. Write a program that reads a text file and inserts line numbers in front of each of its lines. The result should be written to another text file.
4. Write a program that compares two text files line by line and prints the number of lines that are the same and the number of lines that are different. Assume the files have equal number of lines.
5. Write a program that reads a text file containing a square matrix of numbers and finds in the matrix an area of size 2 x 2 with a maximal sum of its elements. The first line in the input file contains the size of matrix N. Each of the next N lines contain N numbers separated by space. The output should be a single number in a separate text file. Example:
4
2 3 3 4
0 2 3 4   => 17
3 7 1 2
4 3 3 2
6. Write a program that reads a text file containing a list of strings, sorts them and saves them to another text file. Example:
Ivan                        George
Peter                      Ivan
Maria      =>         Maria
George                  Peter
7. Write a program that replaces all occurrences of the substring “start” with the substring “finish” in a text file. Ensure it will work with large files (e.g. 100 MB).
8. Modify the solution of the previous problem to replace only whole words (not substrings).
9. Write a program that deletes from given text file all odd lines. The result should be in the same file.
10. Write a program that extracts from given XML file all the text without the tags. Example:

11. Write a program that deletes from a text file all words that start with the prefix “test”. Words contain only the symbols 0…9, a…z, A…Z, _.
12. Write a program that removes from a text file all words listed in given another text file. Handle all possible exceptions in your methods.
13. Write a program that reads a list of words from a file words.txt and finds how many times each of the words is contained in another file test.txt. The result should be written in the file result.txt and the words should be sorted by the number of their occurrences in descending order. Handle all possible exceptions in your methods.
Свали решенията: BE4AA7E888E32AB67B7ACC6E4D413DA63AA51C2C_small

CSS – Less homeworks

Posted in Homeworks Telerik - CSS on January 25, 2013 by krstan4o

Това са домашните от последната лекция по CSS:

images

Условия:

1. Implement the following using LESS
­Use the HTML code from homework.html
­Create the LESS easy to change (backgrounds, fonts)
­Use mixins for clears, gradients)
2css2
Ето и решенията ми: BE4AA7E888E32AB67B7ACC6E4D413DA63AA51C2C_small

CSharp part2 – Exeption Handling

Posted in Homeworks Telerik - CSharp Part2 on January 22, 2013 by krstan4o

В тази тема ще представя условията и решенията от домашното по Обработка на изключения:

CSharp

Условия:

1. Write a program that reads an integer number and calculates and prints its square root. If the number is invalid or negative, print “Invalid number”. In all cases finally print “Good bye”. Use try-catch-finally.
2. Write a method ReadNumber(int start, int end) that enters an integer number in given range [start…end]. If an invalid number or non-number text is entered, the method should throw an exception. Using this method write a program that enters 10 numbers:
a1, a2, … a10, such that 1 < a1 < … < a10 < 100
3. 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.
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 in the finally block.
Свали решенията: BE4AA7E888E32AB67B7ACC6E4D413DA63AA51C2C_small

CSharp part2 – Using Classes and Objects

Posted in Homeworks Telerik - CSharp Part2 on January 19, 2013 by krstan4o

В тази тема ще представя условията и решенията от домашното по Използване на класове и обекти:

CSharp

Условия:

1. Write a program that reads a year from the console and checks whether it is a leap. Use DateTime.
2. Write a program that generates and prints to the console 10 random values in the range [100, 200].
3. Write a program that prints to the console which day of the week is today. Use System.DateTime.
4. 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.
5. Write a method that calculates the number of workdays between today and given date, passed as parameter. Consider that workdays are all days from Monday to Friday except a fixed list of public holidays specified preliminary as array.
6. You are given a sequence of positive integer values written into a string, separated by spaces. Write a function that reads these values from given string and calculates their sum. Example:
string = “43 68 9 23 318” à result = 461
7. *Write a program that calculates the value of given arithmetical expression. The expression can contain the following elements only:
®Real numbers, e.g. 5, 18.33, 3.14159, 12.6
®Arithmetic operators: +, -, *, / (standard priorities)
®Mathematical functions: ln(x), sqrt(x), pow(x,y)
®Brackets (for changing the default priorities)
Examples:
(3+5.3) * 2.7 – ln(22) / pow(2.2, -1.7) => ~ 10.6
pow(2, 3.14) * (3 – (3 * sqrt(2) – 3.2) + 1.5*0.3) =>~ 21.22
Свали решенията: BE4AA7E888E32AB67B7ACC6E4D413DA63AA51C2C_small