Reflection:Constructs

I, Summary
There are three kinds of Constructs:
- sequence constructs
- selection constructs
- iteration constructs


Just see mind map and flow chart, you can understand what main of this lesson is.


II, Applied to solve problems
1,  Calculate the expression
Applied what I learned, I try to solve some problems from my teacher.
I choose exercise from 1 to 16 to solve them together.
Firstly, I create a do-while for menu, because users can have more choices.

Then I used switch for each case that I input. Each block can run a specific task from 1 to 15 following given threads.

You can see demo program:
You can also see code at tinh.cpp

2,Calculate electric cost
I create a menu, it has 3 choices:0, 1, 2
When I choose 1, this program will calculate household electricity.


When I choose 2, this program will calculate production electricity.

When I choose 0, this program will exit.

You can view code: dien.cpp

3, Drawing triangles
When you change the order of loop you can get the different triangles.

Then, these are results.
Source code: ve1.cpp ve2.cpp ve3.cpp ve4.cpp

4, Calculate e^x.
Because we don't know the number loop, we used while to solve this problem.

You can see code at: ex.cpp
III, Some of my thoughts

I feel uncomfortable, because in the same exercise, there have some the same block, I must use them again, but I can just copy-paste. Do nothing. It make me waste my time. If there is a tool or a function, I think I can do it easier and easier. For example, ex 1, I need  check if a number is a prime twice times, so I just copy-paste or code it again. So terrible!

To solve a problem, we should think carefully that choose while or while do or for, use if or switch for suitable with that problem. The constructs of C isn't difficult, just understand and apply them a suitable way, you can become master at C constructs. Nothing is impossible. Practice doesn't make perfect, only perfect practice makes perfect. Should practice more and more, you will become a perfect coder.

Comments

Popular posts from this blog

Reflection: Scope Variables

Những lợi ích của việc dùng email edu cho developer

Reflection: Pointer