Skip to content

Commit

Permalink
Bug fixes:
Browse files Browse the repository at this point in the history
 - row -> line
 - interval -> space
  • Loading branch information
nakov committed Feb 4, 2019
1 parent eab8fa5 commit 9c0b493
Show file tree
Hide file tree
Showing 45 changed files with 149 additions and 155 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Problem: Numbers from 1 to 20

Write a C\# console program that **prints the numbers from 1 to 20** on separate rows on the console.
Write a C\# console program that **prints the numbers from 1 to 20** on separate lines on the console.

## Hints and Guidelines

Create **a C\# console application** with name “`Nums1To20`:
Create **a C\# console application** with name “`Nums1To20`:

![](/assets/chapter-1-images/03.Numbers-1-to-20-01.png)

Inside the `static void Main()` method write 20 commands `Console.WriteLine(…)`, each on a separate row, in order to print the numbers from 1 to 20 one after another. Some of you may be wondering if there is a smarter way. Relax, there is, but we will mention it later on.![](/assets/chapter-1-images/03.Numbers-1-to-20-02.png)Now **we start the program** and we check if the result is what it is supposed to be:
Inside the `static void Main()` method write 20 commands `Console.WriteLine(…)`, each on a separate line, in order to print the numbers from 1 to 20 one after another. Some of you may be wondering if there is a smarter way. Relax, there is, but we will mention it later on.![](/assets/chapter-1-images/03.Numbers-1-to-20-02.png)Now **we start the program** and we check if the result is what it is supposed to be:

```
1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Problem: Triangle of 55 Stars

Write a C\# console program that **prints a triangle made of 55 stars** on 10 rows:
Write a C\# console program that **prints a triangle made of 55 stars** on 10 lines:

```
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Lab: Web Application "Sumator" (Calculator)

Now we are going to write something even more complex, but also more interesting: a web application that **calculates the sum of two numbers**. By **entering two numbers** in the first two text fields and pressing the \[**Calculate**\] button, **their sum is being calculated** and the result is shown in the third text field.
Now we are going to write something even more complex, but also more interesting: a web application that **calculates the sum of two numbers**. By **entering two numbers** in the first two text fields and pressing the [**Calculate**] button, **their sum is being calculated** and the result is shown in the third text field.

Pay attention that we are creating **a Web-based application**. This is an application that is available through a web browser, just like your favorite email or news website. The web application is going to have a server side \(back-end\), which is written in the C\# language with the ASP.NET MVC technology, and a client side \(front-end\), which is written in the HTML language \(this is a language for visualization of information in a web browser\).
Pay attention that we are creating **a Web-based application**. This is an application that is available through a web browser, just like your favorite email or news website. The web application is going to have a server side (back-end), which is written in the C\# language with the ASP.NET MVC technology, and a client side (front-end), which is written in the HTML language (this is a language for visualization of information in a web browser).

The **Web application** is expected to look similarly to the following:

![](/assets/chapter-1-images/08.Numbers-sum-web-01.png)

As a difference compared to console applications, which read and write the data in the form of a text in the console, web applications have **a web-based user interface**. Web applications **are being loaded from some Internet address** \(URL\) through a standard web browser. Users write input data in a page, visualized from the web browser, the data is processed on a web server and the results are shown again in a page of the web browser. For our web application we are going to use **the ASP.NET MVC technology**, which allows creating of **web applications with the programming language C\#** in the development environment **Visual Studio**.
As a difference compared to console applications, which read and write the data in the form of a text in the console, web applications have **a web-based user interface**. Web applications **are being loaded from some Internet address** (URL) through a standard web browser. Users write input data in a page, visualized from the web browser, the data is processed on a web server and the results are shown again in a page of the web browser. For our web application we are going to use **the ASP.NET MVC technology**, which allows creating of **web applications with the programming language C\#** in the development environment **Visual Studio**.

## Creating a New ASP.NET MVC Project

In Visual Studio we create **a new C\# project of type ASP.NET Web Application** with name **WebApp**:
In Visual Studio we create **a new C\# project of type ASP.NET Web Application** with name **WebApp**:

![](/assets/chapter-1-images/08.Numbers-sum-web-02.png)

Expand Down Expand Up @@ -53,4 +53,3 @@ The application is ready. We can start it with \[**Ctrl+F5**\] and test whether
Does it look scary? **Don't be afraid!** We have a lot more to learn, to reach the level of knowledge and skills to write web-based applications freely like in the example above, as well as much bigger and much more complex ones. If you don't succeed, there is nothing to worry about, keep moving on. After some time you will remember with a smile how incomprehensible and exiting your first collision with web programming was. If you have problems with the example above, **watch the video** at the beginning of this chapter. The application is built live there, step by step with a lot of explanations. Or ask in **the SoftUni forum**: [https://softuni.bg/forum](https://softuni.bg/forum).

The purpose of both of the above examples \(graphical desktop application and web application\) is not to teach you, but to make you dive a little deeper into programming, **to enhance your interest** towards software development and to inspire you to learn hard. **You have a lot to learn yet**, but it's interesting, isn't it?

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Before we start working with Visual Studio, it is necessary to get familiar with

**Visual Studio Project** represents "the project" we are working on. In the beginning, these will be our console applications, which we are going to learn writing with the help of the current book, the resources in it and the course Programming Basics in SoftUni. With deeper learning, time and practice, these projects will move into the direction of desktop applications, web applications and other developments. A project in VS **logically groups multiple files** constructing a given application or a component. A **C\# project** contains one or more **C\# source files**, configuration files and other resources. In every C\# source file there is one or more **definition of types** \(classes or other definitions\). In **the classes** there are **methods** \(actions\), and they contain **a sequence of commands**. It sounds complicated, but with bigger projects a structure like this one is very convenient and allows good organization of the work files.

**Visual Studio Solution** represents a container \(a work solution\), in which **a few projects are logically bound**. The purpose of the binding of these VS Projects is to create an opportunity for the code from any of the projects to collaborate with the code from the rest of the VS projects, in order for the application or the website to work correctly. When the software product or service that we develop is big, it is build as a **VS Solution**, and this Solution is split into **projects** \(VS Projects\) and inside each project there are **folders with source files**. This hierarchical organization is much more convenient with more serious projects \(let's say over 50 000 rows of code\).
**Visual Studio Solution** represents a container \(a work solution\), in which **a few projects are logically bound**. The purpose of the binding of these VS Projects is to create an opportunity for the code from any of the projects to collaborate with the code from the rest of the VS projects, in order for the application or the website to work correctly. When the software product or service that we develop is big, it is build as a **VS Solution**, and this Solution is split into **projects** \(VS Projects\) and inside each project there are **folders with source files**. This hierarchical organization is much more convenient with more serious projects (let's say over 50 000 lines of code).

For **smaller projects** VS Solutions and VS Projects are **complicating the work**, rather then helping, but you will get used to it quickly.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Here is how our program should look like in Visual Studio:

![](/assets/chapter-1-images/01.Hello-csharp-04.png)

The command `Console.WriteLine("Hello C#")` in the C\# language means to execute printing \(`WriteLine(…)`\) in the console \(`Console`\) and to print the text message `Hello C#`, which we have to surround by quotation marks, in order to clarify that this is a text. In the end of each command in the C\# language the symbol `;` is being put and it says that the command ends in that place \(it doesn't continue on the next row\).
The command `Console.WriteLine("Hello C#")` in the C\# language means to execute printing (`WriteLine(…)`) in the console (`Console`) and to print the text message `Hello C#`, which we have to surround by quotation marks, in order to clarify that this is a text. In the end of each command in the C\# language the symbol `;` is being put and it says that the command ends in that place (it doesn't continue on the next line).

This command is very typical in programming: we say a given **object** should be found \(in this case the console\) and some **action** should be executed upon it \(in this case it is printing something that is given inside the brackets\). More technically explained, we call the method `WriteLine(…)` from the class `Console` and give as a parameter to it a text literal `"Hello C#"`.

Expand All @@ -47,7 +47,7 @@ Actually, the output from the program is the following text message:
Hello C#
```

The message "**Press any key to continue . . .**" is written additionally on the bottom row in the Visual Studio console after the program ends, in order to push us to see the result from the execution and to press a button to close the console.
The message "**Press any key to continue . . .**" is displayed additionally on the last line on the console after the program ends, in order to push us to see the result from the execution and to press a key to close the console.

## Testing the Program in the Judge System

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Problem: Notifications

Write a program, which takes an integer **`n`** and on the next rows prints **`n`** **messages** (for each message read a few lines). Each message starts with **`messageType`**: **`success`**, **`warning`** or **`error`**:
Write a program, which takes an integer **`n`** and on the next lines prints **`n`** **messages** (for each message read a few lines). Each message starts with **`messageType`**: **`success`**, **`warning`** or **`error`**:
- When **`messageType`** is **`success`** read **`operation`** + **`message`** (each on a new line).
- When **`messageType`** is **`warning`** read only **`message`**.
- When **`messageType`** is **`error`** read **`operation`** + **`message`** + **`errorCode`** (each on a new line).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ When the title line of the method is **too long**, it is recommended to divide i

![](/assets/chapter-10-images/13.Calculate-triangle-area-01.png)

Another good practice when writing code is **to leave an empty row** between the methods, after loops and conditional statements. Also try to **abstain** from writing **long lines and complicated expressions**. With time you will see that this makes the readability better and saves time.
Another good practice when writing code is **to leave an empty line** between the methods, after loops and conditional statements. Also try to **abstain** from writing **long lines and complicated expressions**. With time you will see that this makes the readability better and saves time.

It is also recommended to always **use curly brackets for the bodies of conditional statements and loops**. The brackets not only improve readability, but also reduce the possibility to make a mistake and the program to run incorrectly.
4 changes: 2 additions & 2 deletions Content/Chapter-10-methods/what-method-is/what-method-is.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ When declaring methods you must follow the **sequence** of its base elements –

After we have declared a method, its **implementation (body)** follows. In the body of the method we write down **the algorithm**, by which it solves a problem, i.e. the body contains the code (program block), which applies the method's **logic**. In the shown example we are calculating the area of a square, which is **`num * num`**.

When declaring a variable in the body of a method, it is called a **local** variable of the method. The area where this variable exists and can be used starts from the row where we have declared it and reaches the closing curly bracket `}` of the body of the method. This area is called **variable scope**.
When declaring a variable in the body of a method, it is called a **local** variable of the method. The area where this variable exists and can be used starts from the line where we have declared it and reaches the closing curly bracket `}` of the body of the method. This area is called **variable scope**.

## Calling Methods

**Calling** a method means **starting to execute the code**, which is in **the body of the method**. This happens by writing its **name**, followed by parentheses **`()`** and the sign **`;`** to end the row. If the method needs input data, it is given in the parentheses **`()`**, and the succession of the parameters should be the same as the one of the given parameters when declaring the method. Here is an example:
**Calling** a method means **starting to execute the code**, which is in **the body of the method**. This happens by writing its **name**, followed by parentheses **`()`** and the sign **`;`** to end the line. If the method needs input data, it is given in the parentheses **`()`**, and the succession of the parameters should be the same as the one of the given parameters when declaring the method. Here is an example:

![](/assets/chapter-10-images/03.Invoking-methods-01.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The C# language is made by **Microsoft** and they are the people who define the

The official **C# code convention** by Microsoft is published in the "C# Coding Conventions" article in MSDN (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions) and in this book we will guide ourselves by it.

For formatting code Microsoft recommends **curly brackets `{}`** to be on a separate row and just below the construction to which they apply, as in the example below.
For formatting code Microsoft recommends **curly brackets `{}`** to be on a separate line and just below the construction to which they apply, as in the example below.

```csharp
if (someCondition)
Expand Down Expand Up @@ -38,7 +38,7 @@ if(someCondition){
Console.WriteLine("Inside the if statement");}
```

The first thing that we see is **the curly brackets `{}`**. The first (opening) bracket should be **just below the `if` condition**, and the second (closing) bracket – **below the command `Console.WriteLine(…)`, at a new and empty row**. In addition, the command inside the **`if`** construction should be **offset by 4 white spaces (one tab)**. Just after the keyword **`if`** and before the condition you should put **an interval**.
The first thing that we see is **the curly brackets `{}`**. The first (opening) bracket should be **just below the `if` condition**, and the second (closing) bracket – **below the command `Console.WriteLine(…)`, at a new and empty line**. In addition, the command inside the **`if`** construction should be **offset by 4 white spaces (one tab)**. Just after the keyword **`if`** and before the condition you should put **a space**.

The same rule applies for **the `for` loops and all other constructions with curly brackets `{}`**. Here are some more examples:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Debugging plays an important role in the process of creating software, which is

## Debugging in Visual Studio

Visual Studio gives us **a built in debugger**, thanks to which we can place **breakpoints** at places we have chosen. When it reaches a **breakpoint**, the program **stops running** and allows **step-by-step running** of the remaining rows. Debugging allows us to **get in the details of the program** and see where exactly the errors occur and what is the reason for this.
Visual Studio gives us **a built in debugger**, thanks to which we can place **breakpoints** at places we have chosen. When it reaches a **breakpoint**, the program **stops running** and allows **step-by-step running** of the remaining lines. Debugging allows us to **get in the details of the program** and see where exactly the errors occur and what is the reason for this.

In order to demonstrate the debugger, we will use the following program:

Expand All @@ -23,7 +23,7 @@ static void Main(string[] args)
}
```

We will place a **breakpoint** at the function `Console.WriteLine(…)`. For this we will need to move our cursor to the row, which prints on the console, and press \[**F9**\]. A **breakpoint** appears, showing where the program will **stop** running:
We will place a **breakpoint** at the function `Console.WriteLine(…)`. For this we will need to move our cursor to the line, which prints on the console, and press [**F9**]. A **breakpoint** appears, showing where the program will **stop** running:

![](/assets/chapter-11-images/02.Debugger-01.jpg)

Expand All @@ -33,7 +33,7 @@ In order to start **the program in debug mode**, we choose \[**Debug**\] ->

![](/assets/chapter-11-images/02.Debugger-02.jpg)

After starting the program, we can see that it **stops executing** at line 11, where we placed our breakpoint. The code in the current row **is colored in yellow** and we can **run it step by step**. In order to go to **the next row** we use the key \[**F10**\]. **We can see that the code on the current row hasn't executed yet**. **It executes when we go to the next row**:
After starting the program, we can see that it **stops executing** at line 11, where we placed our breakpoint. The code in the current line **is colored in yellow** and we can **run it step by step**. In order to go to **the next line** we use the key \[**F10**\]. **We can see that the code on the current line hasn't executed yet**. **It executes when we go to the next line**:

![Debugger](/assets/chapter-11-images/02.Debugger-03.jpg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The standard rule for priorities of arithmetic operations is applied: **multiply

## Example: Calculating Trapezoid Area

Let's write a program that inputs the lengths of the two bases of a trapezoid and its height \(one floating point number per row\) and calculates the **area of the trapezoid** by the standard math formula:
Let's write a program that inputs the lengths of the two bases of a trapezoid and its height (one floating point number per line) and calculates the **area of the trapezoid** by the standard math formula:

```csharp
var b1 = double.Parse(Console.ReadLine());
Expand Down
Loading

0 comments on commit 9c0b493

Please sign in to comment.