Posts

Showing posts from September, 2014

Reflection: Funtion

Image
I, Summary There are four components to a C function: -  its return value -  name -  parameters -  and associated code block( function body). Functions need to be defined before they are used. A function declaration tells the compiler what the function’s inputs and outputs look like. By providing the data types for the return value and parameters of a function, the compiler can make sure that you’re using it properly without knowing what it actually does .The corresponding implementation attaches a code block to the declared function. Function declarations vs. implementations II, Applied to solve problems 1. Implement functions with the following prototypes: int power(int m, int n) – In: m, n; Out: mn I wrote a program. It just ran with small limited, because data type of output is int. It's too small with big data. So I try to instead data types. int gt(int n) – In: n; Out: n! Although, output is int, I replace it by double to ha...

Reflection:Constructs

Image
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, Dra...

Reflection: Operators

Image
After researching about operators, I have learned somethings. I, Summary -  A simple expression consists of an operator and operand(s) : - The ALU receives the operator from the Control Unit.  The operator may be:      + arithmetic       + relational       + logical. II, Applied to solve problems Calculate value of expression:  There are some expressions by myself:  Then, I write a program to check my result: My results are right. link product:  bt.cpp III, Some of my thoughts Sometime, I had some mistakes. I forgot the order to calculate, the difference between binary and unary, then my results are wrong. I think we should remember the the order to calculate before solving expression.  To calculate the expression isn't difficult. Just remember the operator what they are, and their order, you can calculate any expressio...

Reflection: Variables

Image
After researching about variables, I have learned somethings. I, Summary -  A variable is a name reference to a memory location, holds data that can change in value during the lifetime of the variable. -  How to use variable II, Applied to solve problems There are some question from my teacher to check my knowledge. 1.Change data types and operators in the demo (done in class) 2. Convert C to F. °C  x  9/5 + 32 = °F CtoF.cpp 3.       Convert meter to feet: ft =m * 3.2808 MtoFt 4.      Calculate the area of ​​a square when we know an adjacent edge. square.cpp 5.      Calculate the area of ​​the rectangle when we know width and length. rectangle.cpp 6.      Calculate the area of ​​right triangles we when know 2 adjacent sides triangle.cpp III, Some of my thoughts This is a mind map about variable. When I code, I have some mistakes. Firstly,...

Reflection: Data types

Image
After researching about data types, I have learn somethings. I, Summary - D ata type definition and how to use them. - C has 4 primitive data types: int, char, float, double. - How computers store negative integers. II, Applied to solve problems There are some question from my teacher to check my knowledge. How to represent negative integer? There are 3 ways to computers store negative integers using encoding schemes: two's complement notation, one's complement notation, and sign magnitude notation. - Two's Complement Representation:  The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometimes called the sign bit. If the sign bit is zero, then the number is greater than or equal to zero, or positive. If the sign bit is one, then the number is less than zero, or negative. To calculate the 2's complement of an integer, invert the binary equivalent of the number by changing all of the ones to zeroes and all of the ze...