Tuesday, 16 October 2012 0 comments

Week 4-5: Flow Control

In the first few weeks, I had a rough view of the basic syntax and structure of C language. Instead of writing programs practically, I learnt to read a program which mainly involving printf() statements and some simple syntax, and I got 100 points in the first assignment!

In the previous two weeks, a new field - Flow Control was introduced. It was divided into two parts, in Flow Control I, relational, equality and logical operators were introduced. They are provided to facilitate flow controls, especially in calculations and executing statements, it is important to distinguish their meanings and purposes. Besides, two types of flow controls, sequential and selection, were taught. For sequential, statements in a program are executed one after another, it is easy to understand and use. For selection, it involves a choice of alternative actions, and can be classified into if, if-else, and switch. When using selection, statements will be executed in different orders depending on the value (zero or non-zero) of the expression. I have learnt the if and if-else statement in cert. level so a clear concept has already existed in my mind.


In programming, we should be very careful about the structure, the order of each word, and the presence of each symbol. The following are four modifications of a program, they are very alike, but actually one of them is different from the others.


 In Flow Control II, repetition was introduced. In this type of flow control, we use while and do-while statements to repeatedly execute a statement. They are very useful in performing miscellaneous calculations and tasks. In the following example, for statement, which is equivalent to the while statement, is used to find the factorial of an input integer.


To practice, assignment 2 was finished in the last week and it was required to use prinf() statements, print-out (screen) formatting and branching statement "if-else" to perform simple calculation using C. It was the first program I wrote, it behaves as a price comparator for mobile phone users. The program first prints the information of mobile phone network operator monthly plans, it then asks for the air-time usage information. After inputting a single integral number, it is expected that the costs of joining different operators and different plans will be calculated and listed out. The flow control in this program is not complicated and is rather easy, so I spent only about 45 minutes in compiling it.



In short, Flow Control is a challenging topic and it consolidates my mind in writing programs. A program involving Flow Control will not be workable if we just follow the structure and put in all the syntax validly. Addition to syntactically correct, it also requires plentiful logical thinking. We need to design every statement logically with our problem-solving skills, or else, the program will be resulted in a valid meaningless one, infinite loop is a good illustration.
Wednesday, 26 September 2012 1 comments

Week 1-3: Basis of C Language

To me, a freshman at university, everything is new and fresh. In the first semester, CSCI1110 is undoubtedly the course I most looking forward to study. Believe it or not, I love computers. Choosing between Information Engineering and Computer Science has already driven me crazy, imagine how excited I am when  I can study Computer Science course as a student of Information Engineering.

Programming is a new field to me, absolutely. Although I have studied Computer & Internet Technology in cert. level, I chose multimedia stream at that time. Multimedia and HTML can be easily accessed in our daily computer uses, I learnt web authoring by myself  since I was still in primary school. However, we cannot easily gain knowledge about programming when using computers. Now I have the chance to make friend with programming!

The lecture courses of CSCI1110, out of my expectation, is not that interesting. Hmmm... maybe this is because of the  beginner level, what we have learnt are mostly theoretic stuff but not so practical. Nevertheless, those knowledge is very important for me to build a clear concept of computing in my mind. I have learnt the syntax,expression, structure, elements,... of a high level language: C language. It is told that C language is small and relatively easy to learn, and I quite enjoy attending the lessons. I have just learnt different operators, prefix and postfix forms, and field-widths control in the previous week. I found that they are actually like maths, but involve some special rules which are just for programming, it is quite interesting and I should pay attention to them to avoid mixing up with maths. 


The professor has suggested some reference book, or called textbooks for us, I visited CUHK Library and a public library after class to find them but failed. Finally, I have borrowed a reference book written in Chinese, surely for Chinese to read and understand, so I think it will be suitable for me as a beginner to learn.

This week, the first assignment in CSCI, and even my university studies, is going to be handed in! I can finally put what I have gained in the lesson into a practical way. The assignment consists of two parts: This first part is a typing exercise, we just need to type the given program which is shown in image form into Visual C++ 2010 Express; the second part is to describe what this program does.


This assignment aims at helping us to get acquaint with the Visual Studio/ C++ programming environment. I have tried Visual C++ 2010 Express, it is definitely a new toy for me, HAHA! 



Below is a part of my typing work, strictly followed the given sample. Hope that there is no typing mistakes.


This assignment requires us to try to compile and execute the program with appropriate arguments. I have succeeded!