-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates Content/Chapter-1-first-steps-in-programming/how-to-write-con…
…sole-app/typical-mistakes-in-csharp-programs.md Auto commit by GitBook Editor
- Loading branch information
Svetlin Nakov
committed
Jan 14, 2019
1 parent
593d34d
commit d4e3bad
Showing
49 changed files
with
547 additions
and
402 deletions.
There are no files selected for viewing
5 changes: 1 addition & 4 deletions
5
...t-steps-in-programming/console-graphical-web-apps/console-graphical-web-apps.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
## Console, Graphical and Web Applications | ||
## | ||
|
||
With **console applications**, as you can figure out yourselves, **all operations** for reading input and printing output are **done through the console**. **The input data is inserted** in the console, which is then read by the application, also in it, and the **output data is printed** on the console after or during the runtime of the program. | ||
|
||
While a console application **uses the text console**, web applications **use web-based user interface**. To **execute them**, two things are needed - **a web server** and **a web browser**, as **the browser** plays the main role in **the visualization of the data and the interaction with the user**. Web applications are much more pleasant for the user, they visually look better, and a mouse and touch screen can be used (for tablets and smartphones), but programming stands behind all of that. And this is why **we have to learn to program** and we have already made our first very little steps towards that. | ||
|
||
Graphical (GUI) applications have **a visual user interface**, directly into your computer or mobile device, without a web browser. Graphical applications (also known as desktop applications) **contain one or more graphical windows**, in which certain **controllers** are located (text fields, buttons, pictures, tables and others), **serving for dialog** with the user in a more intuitive way. Similar to them are the mobile applications in your telephone or your tablet: we use forms, text fields, buttons and other controls and we control them by programming code. This is why we are learning how to write code now: **the code is everywhere in software development**. |
21 changes: 19 additions & 2 deletions
21
...-programming/exercises-first-steps-in-coding/exercises-first-steps-in-coding.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
## Exercises: First Steps in Coding | ||
# Exercises: First Steps in Coding | ||
|
||
Welcome to the **exercises**. Now we are going to write a couple of console applications, by which we are going to make a few more steps into programming. After that we will show how we can program something more complex - programs with graphical user interface. | ||
|
||
## What We Learned in This Chapter? | ||
|
||
First we have learned **what is programming** - **giving commands, written in a computer language**, which the machine understands and is able to execute. We understood what is **a computer program** - it represents a **sequence of commands**, arranged one after another. We got familiar with **the language for programming C\#** on a base level and how **to create simple console applications** with Visual Studio. We followed **the structure of the programming code in the C\# language**, as for example, the fact that commands are mainly given in the section `static void Main(string[] args)` between **the opening and closing curly parentheses**. We saw how to print with `Console.WriteLine(…)` and how to start our program with \[**Ctrl + F5**\]. We learned how to test our code in **SoftUni Judge**. | ||
|
||
## The Exercises | ||
|
||
Let's get started with the **exercises**. You didn't forget that programming is learned by writing a lot of code and solving problems, did you? Let's solve a few problems to confirm what we have learned. | ||
|
||
* [Problem: Console Application “Expression”](https://legacy.gitbook.com/book/software-university-foundation/programming-basics-csharp-en/edit#) | ||
* [Problem: Numbers from 1 to 20](/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/numbers-1-to-20.md) | ||
* [Problem: A Triangle Made Out of 55 Stars](/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md) | ||
* [Problem: Calculate Rectangle Area](/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/rectangle-area.md) | ||
* [Problem: A Square Made Out of Stars](/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/square-of-stars.md) | ||
|
||
|
||
|
||
Welcome to the exercises. Now we are going to write a couple of console applications, by which we are going to make a few more steps into programming. After that we will show how we can program something more complex - programs with graphical user interface. |
12 changes: 7 additions & 5 deletions
12
...pter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 9 additions & 11 deletions
20
...1-first-steps-in-programming/exercises-first-steps-in-coding/numbers-1-to-20.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
### Problem: Numbers from 1 to 20 | ||
# 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 rows on the console. | ||
|
||
#### Tips and Tricks | ||
## Tips and Tricks | ||
|
||
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. | ||
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: | ||
|
||
![](/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 | ||
2 | ||
… | ||
20 | ||
``` | ||
|
||
#### Testing in the Judge System | ||
## Testing in the Judge System | ||
|
||
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/503\#2](https://judge.softuni.bg/Contests/Practice/Index/503#2). | ||
|
||
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/503#2](https://judge.softuni.bg/Contests/Practice/Index/503#2). | ||
Now think whether we can write the program **a smarter way**, so we don't repeat the same command 20 times. Seek out information on the Internet about "[**for loop C\#**](https://www.google.bg/search?q=for+loop+C%23&oq=for+loop+C%23)". | ||
|
||
Now think whether we can write the program **a smarter way**, so we don't repeat the same command 20 times. Seek out information on the Internet about "**[for loop C#](https://www.google.bg/search?q=for+loop+C%23&oq=for+loop+C%23)**". |
24 changes: 12 additions & 12 deletions
24
...-1-first-steps-in-programming/exercises-first-steps-in-coding/rectangle-area.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
### Problem: Calculate Rectangle Area | ||
# Problem: Calculate Rectangle Area | ||
|
||
Write a C# program that **reads** from the console **two numbers, a and b**, **calculates** and **prints** the area of a rectangle with sides **a** and **b**. | ||
Write a C\# program that **reads** from the console **two numbers, a and b**, **calculates** and **prints** the area of a rectangle with sides **a** and **b**. | ||
|
||
#### Sample Input and Output | ||
|
||
| a | b | area | | ||
| :---: | :---: | :---: | | ||
| 2 | 7 | 14 | | ||
| 7 | 8 | 56 | | ||
| 12 | 5 | 60 | | ||
| 2 | 7 | 14 | | ||
| 7 | 8 | 56 | | ||
| 12 | 5 | 60 | | ||
|
||
#### Tips and Tricks | ||
## Tips and Tricks | ||
|
||
Create a new **console C# program**. To **read both of numbers**, use the following commands: | ||
Create a new **console C\# program**. To **read both of numbers**, use the following commands: | ||
|
||
![](/assets/chapter-1-images/05.Rectangle-area-01.png) | ||
|
||
What remains is to finish the program above, to calculate the area of the rectangle and to print it. Use the command that is already known to us **`Console.WriteLine()`** and put inside its brackets the multiplication of the numbers **a** and **b**. In programming, multiplication is done using the operator **`*`**. | ||
What remains is to finish the program above, to calculate the area of the rectangle and to print it. Use the command that is already known to us `Console.WriteLine()` and put inside its brackets the multiplication of the numbers **a** and **b**. In programming, multiplication is done using the operator `*`. | ||
|
||
#### Test your solution | ||
## Test Your Solution | ||
|
||
Test your solution with a few examples. You have to receive an output, similar to this one (we enter 2 and 7 as input and the program prints result 14 - their multiplication): | ||
Test your solution with a few examples. You have to receive an output, similar to this one \(we enter 2 and 7 as input and the program prints result 14 - their multiplication\): | ||
|
||
``` | ||
2 | ||
7 | ||
14 | ||
``` | ||
|
||
#### Testing in the Judge System | ||
## Testing in the Judge System | ||
|
||
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/503#4](https://judge.softuni.bg/Contests/Practice/Index/503#4). | ||
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/503\#4](https://judge.softuni.bg/Contests/Practice/Index/503#4). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 19 additions & 1 deletion
20
...rogramming/exercises-graphical-and-web-apps/exercises-graphical-and-web-apps.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
## Exercises: Graphical and Web Applications | ||
# Exercises: Graphical and Web Applications | ||
|
||
Now we are about to build one simple **web application** and one simple **graphical application**, in order to take a look at what we will be able to create when we progress with programming and software development. We are not going to look through the details about the used techniques and constructions fundamentally. Rather than that, we are just going to take a look at the arrangement and functionality of our creation. After we progress with our knowledge, we will be able to do bigger and more complex software applications and systems. We hope that the examples given below will **straighten your interest**, rather than make you give up. | ||
|
||
## Console, Graphical and Web Applications | ||
|
||
With **console applications**, as you can figure out yourselves, **all operations** for reading input and printing output are **done through the console**. **The input data is inserted** in the console, which is then read by the application, also in it, and the **output data is printed** on the console after or during the runtime of the program. | ||
|
||
While a console application **uses the text console**, web applications **use web-based user interface**. To **execute them**, two things are needed - **a web server** and **a web browser**, as **the browser** plays the main role in **the visualization of the data and the interaction with the user**. Web applications are much more pleasant for the user, they visually look better, and a mouse and touch screen can be used \(for tablets and smartphones\), but programming stands behind all of that. And this is why **we have to learn to program** and we have already made our first very little steps towards that. | ||
|
||
Graphical \(GUI\) applications have **a visual user interface**, directly into your computer or mobile device, without a web browser. Graphical applications \(also known as desktop applications\) **contain one or more graphical windows**, in which certain **controllers** are located \(text fields, buttons, pictures, tables and others\), **serving for dialog** with the user in a more intuitive way. Similar to them are the mobile applications in your telephone or your tablet: we use forms, text fields, buttons and other controls and we control them by programming code. This is why we are learning how to write code now: **the code is everywhere in software development**. | ||
|
||
## Exercises: GUI and Web Applications | ||
|
||
In the next exercises we shall create a GUI and a Web application: | ||
|
||
* [Problem: Graphical Application "Sumator" \(Calculator\)](/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md) | ||
* [Problem: Web Application "Sumator" \(Calculator\)](/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md) | ||
|
||
|
||
|
16 changes: 1 addition & 15 deletions
16
...ses-graphical-and-web-apps/sumator-graphical/adding-text-fields-and-a-button.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,4 @@ | ||
#### Adding Text Fields and a Button | ||
#### | ||
|
||
We download from the bar on the left (Toolbox) **three text boxes** (**`TextBox`**), **two labels** (**`Label`**) and **a button** (**`Button`**), afterwards we arrange them in the window of the application. Then we **change the names of each of the controls**. This is done from **the window “Properties”** on the right, by changing the field (**`Name`**): | ||
|
||
![](/assets/chapter-1-images/07.Numbers-sum-04.png) | ||
|
||
* Names of the text boxes: **`textBox1`**, **`textBox2`**, **`textBoxSum`** | ||
* Name of the button: **`buttonCalculate`** | ||
* Name of the form: **`FormCalculate`** | ||
|
||
**We change the headings** (the **`Text`** property) of the controls: | ||
|
||
* buttonCalculate -> Calculate | ||
* label1 -> + | ||
* label2 -> = | ||
* Form1 -> Sumator | ||
|
||
![](/assets/chapter-1-images/07.Numbers-sum-05.png) |
9 changes: 1 addition & 8 deletions
9
...cises-graphical-and-web-apps/sumator-graphical/fixing-the-problem-and-retest.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
#### Solving the Problem and Retesting the Application | ||
#### | ||
|
||
The problem comes from **the conversion of the text field into a number**. If the value inside the field **is not a number, the program throws an exception**. We can rewrite the code in order to fix this problem: | ||
|
||
![](/assets/chapter-1-images/07.Numbers-sum-14.png) | ||
|
||
The code above **catches the errors when working with numbers** (it catches exceptions) and in case of an error **it gives a value `error`** in the field with the result. We start the program again with [**Ctrl+F5**] and try if it works. This time **by entering a wrong number the result is `error`** and the program doesn't break: | ||
|
||
![](/assets/chapter-1-images/07.Numbers-sum-15.png) ![](/assets/chapter-1-images/07.Numbers-sum-16.png) | ||
|
||
Is it complicated? It is normal to seem complex, of course. We are just beginning to get into programming. The example above requires much more knowledge and skills, which we are going to develop through this book and even afterwards. Just allow yourself to have some fun with desktop programming. If something doesn't work, watch **the video in the beginning of this chapter** or ask in **the SoftUni forum**: https://softuni.bg/forum. Or move on bravely forward to the next example or to the next chapter of the book. A time will come when it is going to be easy for you, but you really have to put **an effort and be persistent**. Programming is learnt slowly with lots and lots of practice. |
7 changes: 1 addition & 6 deletions
7
...amming/exercises-graphical-and-web-apps/sumator-graphical/new-csharp-project.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
#### Creating a New C# Project | ||
#### | ||
|
||
In Visual Studio we create **a new C# project of type „Windows Forms Application“**: | ||
|
||
![](/assets/chapter-1-images/07.Numbers-sum-02.png) | ||
|
||
When creating a Windows Forms application **an editor for user interface** will be shown, in which **different visual elements** could be put (for example textboxes and buttons): | ||
|
||
![](/assets/chapter-1-images/07.Numbers-sum-03.png) |
Oops, something went wrong.