HTML Basics


Това е първата домашна от HTML5 трака към Софтуерната Академия на Телерик.
Задача 1. Simple Page :

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>Simple Page</title>
		<meta name="description" content="homework" />
		<meta name="author" content="Teodor" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0" />
	</head>

	<body>
		<div>
			<header>
				<p>
					Hello, Stranger!
				</p>
				<h1>Welcome to Runners Home™</h1>
			</header>
			<div>
				<p>
					Runners Home™ is dedicated to provideing you with
				</p>
				- the moste up-to-date information on running races
				<br/>
				- the best resources for runners
			</div>
			<hr>
			<footer>
				<p>
					© Runners Home. All rights reserved.
				</p>
			</footer>
		</div>
	</body>
</html>

Задача 2. Nested Lists :

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>Simple Page</title>
		<meta name="description" content="homework" />
		<meta name="author" content="Teodor" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0" />
	</head>

	<body>
		<div>
			<p>
				Presseeding Text
			</p>
			<ol type="I">
				<li>
					List Item 1
					<ol type="a">
						<li>
							Nested Item 1.1
						</li>
						<li>
							Nested Item 1.2
						</li>
					</ol>
				</li>
				<li>
					List Item 2
					<ol>
						<li>
							Nested Item 2.1
						</li>
						<li>
							Nested Item 2.2
							<ul type="disc">
								<li>
									Nested Item 2.2.1
								</li>
								<li>
									Nested Item 2.2.2
									<ul type="square">
										<li>
											Nested Item 2.2.2.1
										</li>
										<li>
											Nested Item 2.2.2.2
										</li>
									</ul>
								</li>
								<li>
									Nested Item 2.2.3
								</li>
							</ul>
						</li>
						<li>
							Nested item 2.3
						</li>
					</ol>
				</li>
				<li>
					List Item 3
					<ul>
						<li>
							Nested Item 3.1
						</li>
						<li>
							Nested Item 3.2
						</li>
						<li>
							Nested Item 3.3
						</li>
					</ul>
				</li>
			</ol>
		</div>
	</body>
</html>

Задача 3. Web Profile:
Friends section:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
		Remove this if you use the .htaccess -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>Friends</title>
		<meta name="description" content="homework" />
		<meta name="author" content="Teodor" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0" />
		<link href="style/style.css" rel="stylesheet" type="text/css" />
	</head>

	<body>
		<div>
			<header>
				<h1>Friends</h1>
			</header>

			<nav>
				<a id="first" href="Profile.html">Profile</a>
				<a href="#">Friends</a>
				<a href="Info.html">Additional information</a>
			</nav>

			<div>
				<hr/>
				<h3><em>Additional Information about Doncho</em></h3>
				<hr/>
				<ol>
					<li>
						<dl>
							<dt>
								<em>Pesho Ivanov</em>
							</dt>
							<dd>
								Student
							</dd>
						</dl>
					</li>
					<li>
						<dl>
							<dt>
								<em>Vankata</em>
							</dt>
							<dd>
								Software developer
							</dd>
						</dl>
					</li>
					<li>
						<dl>
							<dt>
								<em>Bai Gosho</em>
							</dt>
							<dd>
								System admin
							</dd>
						</dl>
					</li>
				</ol>
			</div>
		</div>
	</body>
</html>

Information section:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>Info</title>
		<meta name="description" content="homework" />
		<meta name="author" content="Teodor" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0" />
		<link href="style/style.css" rel="stylesheet" type="text/css" />
	</head>

	<body>
		<div>
			<header>
				<h1><em>Additional information about Doncho </em></h1>
			</header>
			<nav>
				<a id="first" href="Profile.html">Profile</a>
				<a href="Friends.html">Friends</a>
				<a href="#">Additional information</a>
			</nav>

			<div>
				<hr/>
				<h3>Frends of Doncho</h3>
				<hr/>
			</div>

			<div>
				<em>Student at <a href="#">Sofia University</a>
				<br />
				Born in Burgas
				<br />
				Living in Sofia
				<br />
				Working at <a href="#">Telerik</a></em>
			</div>

		</div>
	</body>
</html>

Profile section:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>Profile</title>
		<meta name="description" content="homework" />
		<meta name="author" content="Teodor" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0" />
		<link href="style/style.css" rel="stylesheet" type="text/css" />
	</head>

	<body>
		<div>
			<header>
				<h1>Profile</h1>
			</header>
			<nav>
				<a id="first" href="#">Profile</a>
				<a href="Friends.html">Friends</a>
				<a href="Info.html">Additional information</a>
			</nav>
			<div>
				<hr/>
				<h3>Profile of Doncho</h3>
				<hr/>
			</div>
			<div>
				<img src="http://www.vnvlvokc.com/ow_userfiles/plugins/shoppro/images/product_1.jpg" alt="Testing image" width="50px" height="50px"/>
			</div>
			<div>
				<p>
					Name: Doncho Minkov
				</p>
				<p>
					Birthday: 22 June 1989
				</p>
				<p>
					Occupation: Student
				</p>
				<p>
					Area of occupation: IT
				</p>
			</div>
		</div>
	</body>
</html>

И накрая малко CSS за вкус към 3тата задача:

body 
{
	background-color: #ccecff;
}
nav > a
{
	margin-left: 100px;
}
#first
{
	margin: 0;
}

Advertisements

Primitive Data Types and Variables


Това е втората домашна от C# – Part1 курса:

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.

using System;

class SimpleDeclaration
{
    static void Main()
    {
        ushort unsignedShort = 52130;
        sbyte simpleByte = -115;
        int intiger = 4825932;
        byte smallByte = 97;
        short simpleShort = -10000;
    }
}

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?

using System;

class DoublesAndFloats
{
    static void Main()
    {
        double firstDouble = 34.567839023;
        float firstFloat = 12.345f;
        double secondDouble = 8923.1234857;
        float secondFloat = 3456.091f;
    }
}

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

using System;

class FloatingPointComparison
{
    static void Main()
    {
        decimal firstNumber = 1235.6666666666666666666666666M;
        decimal secondNumber = 6.01M;
        decimal roundedOne = Math.Round(firstNumber, 6);
        Console.WriteLine(roundedOne);
        decimal roundedTwo = Math.Round(secondNumber, 6);
        if (roundedOne == roundedTwo)
        {
            Console.WriteLine("The numbers are equal!");
        }
        else if (roundedOne > roundedTwo)
        {
            Console.WriteLine("The first number is greater than the second!");
        }
        else
        {
            Console.WriteLine("The second number is greater than the first!");
        }
    }
}

4.Declare an integer variable and assign it with the value 254 in hexadecimal format. Use Windows Calculator to find its hexadecimal representation.

using System;

class HexValue
{
    static void Main()
    {
        int hexValue = 0xFE;
    }
}

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.

using System;

class UniCodeSimbyl
{
    static void Main(string[] args)
    {
        char symbol = 'u0048';
        Console.WriteLine(symbol);
    }
}

6. Declare a boolean variable called isFemale and assign an appropriate value corresponding to your gender.

using System;

class Gender
{
    static void Main()
    {
        bool isFemale = false;
    }
}

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).

using System;

class ConcatenationAndCasting
{
    static void Main()
    {
        string firstPart = "Hello ";
        string secondPart = "World";
        object wholeObj = firstPart + secondPart;
        string wholeString = (string)wholeObj;
    }
}

8.Declare two string variables and assign them with following value: /The “use” of quotations causes difficulties./
Do the above in two different ways: with and without using quoted strings.

using System;

class QuoteProblems
{
    static void Main()
    {
        Console.WriteLine("The "use" of quotations causes difficulties.");
        Console.WriteLine(@"The ""use"" of quotations causes difficulties.");
    }
}

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.

using System;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        Console.OutputEncoding = Encoding.Unicode;
        int copyRignt = 169;
        byte spaceing = 2;
        for (int rows = 0; rows < 3; rows++)
        {
            for (int spaceCounter = 0; spaceCounter < spaceing; spaceCounter++) 
            {
                Console.Write(" ");
            }
            for (int cols = 0; cols <= rows; cols++)
            {
                Console.Write((char)copyRignt);
            }
            for (int cols = 0; cols <= rows - 1; cols++)
            {
                Console.Write((char)copyRignt);
            }
            spaceing--;
            Console.WriteLine();
        }
    }
}

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.

using System;

class MarketingFirmInfo
{
    static void Main()
    {
        string firstName = "Ivan";
        string lastName = "Ivanov";
        byte age = 23;
        char gender = 'm';
        long ID = 213124123;
        uint uniqueNumber = 27569999;
    }
}

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

using System;

class ChangeingValues
{
    static void Main()
    {
        int a = 5;
        int b = 10;
        int c;
        c = a;
        a = b;
        b = c;
        Console.WriteLine("The value of " a " is {0} and the value of " b " is {1}", a, b);
    }
}

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.

using System;
using System.Text;

class ASCIIsymbols
{
    static void Main()
    {
        Console.OutputEncoding = Encoding.Unicode;
        for (int i = 0; i <= 255; i++ )
        {
            char symbol = (char)i;
            Console.WriteLine("ASCII symbol {0} and its number {1}",symbol,i);
        }
    }
}

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.

using System;

class NullValues
{
    static void Main()
    {
        int? nullVauleOne = null;
        double? nullValueTwo = null;
        Console.WriteLine("First varibale {0} and second varibale {1}", nullVauleOne, nullValueTwo);
        Console.WriteLine(nullVauleOne + nullValueTwo);
        Console.WriteLine(nullVauleOne + 12);
        nullVauleOne = 5;
        Console.WriteLine(nullVauleOne.GetValueOrDefault());
    }
}

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.

using System;

class DoublesAndFloats
{
    static void Main()
    {
        string firstName = "Teodor";
        string middleName = "Ivanov";
        string lastName = "Kurtev";
        decimal balance = 1000;
        string bankName = "BNB";
        string IBAN = "";
        string BIC = "";
        ulong creditCard1 = 1111;
        ulong creditCard2 = 123123;
        ulong creditCard3 = 334324;

    }
}

Какво е Zen-Coding и трябва ли да го използваме ?


В няколкото години в които съм се занимавал с писането на HTML и многото досадни Copy + Paste случай, реших да потърся алтернатива на тази досада и така без да искам попаднах на Zen-Coding.

Но какво всъщност е Zen-coding и защо трябва да го ползвам ?

Та в същността си Zen-coding представлява разширение за почти всички по-популярни IDE, което улеснява и намалява значително времето за писане на код.

Добре, как ускорява писането на код ?

Със прости съкратени команди може да генерирате значително количество код. Ето пример:

Имате нужда от div, в които има неподреден списък с 5 елемента, в които има линк. Пишете си в IDE-то : div>ul>li*5>a , натискаме Ctrl+E ( това е шорткъта за “разпъване” на код ) и ни изкрава готовия HTML код:

<div>
<ul>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
</ul>
</div>

Искаме елементите на листа да имат клас “item”. Няма проблем: Пишете си в IDE-то : div>ul>li.item*5>a и вече имаме готов HTML код:

<div>
<ul>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
</ul>
</div>

За пълен списък на това какво може да правите с съкратения код, може да видите тук

Но откъде да си го сваля ?

Тук може да намерите най-новата версия на Zen-Coding – цък

Заключение

Силно ви препоръчвам да ползвате Zen-Coding, тъй кат без него ще прекарате доста часове в Copy + Paste на НТМL код;

Introduction to Programming


В следващите няколко реда ще публикувам примерни решения на задачите от Лекция Първа на Телерик Академи.

2. Create, compile and run a “Hello C#” console application.

using System;

    class HelloCSharp
    {
        static void Main()
        {
            Console.WriteLine("Hello, C#!");
        }
    }

3. Modify the application to print your name.

using System;

class HelloMyName
{
    static void Main()
    {
        Console.WriteLine("Hello, Teodor!");
    }
}

4. Write a program to print the numbers 1, 101 and 1001.

using System;

class PrintNumbers
{
    static void Main()
    {
        Console.WriteLine(1);
        Console.WriteLine(101);
        Console.WriteLine(1001);
    }
}

6. Create console application that prints your first and last name.

using System;

class PrintFirstAndLast
{
    static void Main()
    {
        Console.WriteLine("Teodor Kurtev");
    }
}

7. Create a console application that prints the current date and time.

using System;

class TimeAndDate
{
    static void Main()
    {
        Console.WriteLine("The date and time are:");
        Console.WriteLine(DateTime.Now);
    }
}

8. Create a console application that calculates and prints the square of the number 12345.

class Square
using System;

class Square
{
    static void Main()
    {
        Console.WriteLine("The square of 12345 is:");
        Console.WriteLine(Math.Pow(12345,2));
        // Another possibility is simply multiplying the 12345 and 12345
    }
}

9. Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, …

using System;

class Program
{
    static void Main()
    {
        for (int i = 2; i < 12; i++)
        {
            if (i % 2 == 0)
            {
                Console.WriteLine(i);
            }
            else
            {
                Console.WriteLine(-i);
            }
        }
    }
}

Друго решение е това, макар че при него се проявява проблем с последния елемент

using System;

class NumberSequence
{
    static void Main()
    {
        Console.WriteLine("The first 10 numbers of the sequence are:");
        for (int i = 2; i < 12;i = i + 2 )
        {
            Console.Write(" " + i);
            Console.Write(" " + - (i + 1));
        }
        Console.WriteLine();
    }
}

12. * Write a program to read your age from the console and print how old you will be after 10 years.

using System;

class FutureAge
{
    static void Main()
    {    
        int yearBorn;
        while (true)
        {
            Console.WriteLine("Please enter the year you were born:");
            if ( int.TryParse(Console.ReadLine(), out yearBorn) && yearBorn > 1900 && yearBorn < DateTime.Now.Year)
            {
                break;
            }
            else
            {
                Console.WriteLine("Incorect data, please try again!");
            }
        }
        
        int yearsNow = DateTime.Now.Year - yearBorn;
        int futureAge = yearsNow + 10;
        Console.WriteLine("Your age now is {0} and you will be {1} years old after 10 years", yearsNow, futureAge);
        
    }
}