Posts

Reflection: Assignment1_bank

Image
Đề bài: Viết chương trình tính tiền khách hàng phải trả vào gốc và lãi cho ngân hàng theo nghiệp vụ được mô tả như sau: Với mỗi khoản vay của ngân hàng. Khách hàng đều phải cam kết trả nợ trong một khoảng thời gian nhất định tính bằng tháng. Theo khoảng thời gian này, hàng tháng khách hàng phải trả khoản gốc cho khoản vay bằng Tổng dư nợ : số tháng. Ví dụ khách hàng vay 1,2 tỷ trong vòng 5 năm (60 tháng) thì mỗi tháng khách hàng phải trả gốc là 1,2 tỷ : 60 tháng = 20 triệu/tháng Khoản tiền lãi sẽ được tính theo dư nợ hiện thời với lãi suất theo hợp đồng tín dụng. Ví dụ khách hàng vay 1.2 tỷ với lãi suất 12%/năm. Sau 10 tháng trả nợ, dư nợ của khách hàng còn 1 tỷ. Vậy khoản lãi của khách hàng cho tháng 11 sẽ là: 1 tỷ * 12/100/12 = 10 triệu Với mỗi khoản vay, hàng tháng khách hàng bắt buộc phải trả một khoản bảo hiểm cho tài sản thuế chấp bằng 1.2% /năm cho tổng số tiền vay. Ví dụ với khoản vay 1,2 tỷ. Hàng tháng khách hàng phải trả tiền bảo hiểm tài sản là: 1.2 tỷ * 1.2/100/12...

Reflection: Array

Image
I, Summary A data structure is a collection of data types designed to store information in some optimal way. The simplest example of a data structure is an array. The fundamental unit of an array is an element. Each element holds has an index and holds one data value.  Index numbering starts at 0 and extends to one less than the size of the array. To refer to an element, we use the array name followed by bracket notation around the element index.  dataType arrayIdentifier[ size ] = { value, ... , value }; II, Applied to solve problems A,Write program 1. Declare an double array with max 100 elements 2. Input an positive integer n that indicated the number of element of array 3. Input n elements of array 4. Display array has just been inputted 5. Calculate sum of all elements, sum of odd element, average of even elements, average of element at odd index Source and demo: file source:  array.cpp B, Pro...

Reflection: Pointer

Image
I, Summary What is pointer? Pointers are the container/variable who holds address of other variables. C uses pointers in three different ways:      - C uses pointers to create dynamic data structures -- data structures built up from blocks of memory allocated from the heap at run-time.      - C uses pointers to handle variable parameters passed to functions.      - Pointers in C provide an alternative way to access information stored in arrays. Pointer techniques are especially valuable when you work with strings. There is an intimate link between arrays and pointers in C. The declaration of pointers follows this format: type * name;  II, Applied to solve problems 1. void input(int*n, int*m); – input and check n>0, m>0 2. int fun2(int n, int m); Function returns n! + m n if n > 0 and m > 0, otherwise return 0 3. double fun6(int n); Function returns value calculated by formula 4. i...

Reflection: Scope Variables

Image
I, Summary There are two types of c variables.      - Local      - Global Local variables:  Variable whose existence is known only to the main program or functions are called local variables. Local variables are declared with in the main program or a function. Global variables:  Variables whose existence is known to the both main() as well as other functions are called global variables. Global variables are declared outside the main() and other functions. Difference between Local and Global c variables:      - Local c variable is declared in functions and blocks, while global c variables are declared outside functions and blocks.      - Local c variables can be accessed only that function and blocks which declared it, while global c variables can be accessed within all program.      - Local c variables when declared not initialized automatically by system you have to decla...

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