Wednesday 7 November 2012

Week 6-8: Miscellaneous Topics

In the previous week, I have submitted the third assignment in this course. This program acts as a calendar generator. User can enter the number of a year from 1990 to 2100 (inclusive) and desired month from 1 to 12 (inclusive) via the keyboard. The program will print the calendar according to user's input. For each month, it provides a heading showing the month and year, plus headings for the days of the week. Below is the programming result.


In the tutorial of assignment 3, two methods are provided for reference. I chose method B, using Zeller's congruence for the Gregorian calendar to calculate the day of the week in the program.


For the lecture, we have gone through some miscellaneous topics, including Fundamental Data Types, Functions, Variable Scope and Storage Class, Array Processing, Pointers and Arrays Revisited. Most of these topics are new to me, so I would like share two easier topics, Fundamental Data Types and Functions, in detail in this post.

At the beginning stage, we mainly used char, int and float in writing programs. In this chapter, we learnt all fundamental data types as shown below. They are classified into two types, Integral Types and Floating Types. For the presence of Integral types and Floating types in the same time, this is called Arithmetic Types.


Besides, the 7-bit ASCII Table has been introduced. ASCII stands "American Standard 
Code for Information Interchange". It includes some printable characters: 'A', '=', ':', ... and some non-printable characters: newline (NL), bell (BEL), tab (HT, VT), ... ASCII indicates the different values stored in one byte of each character. One byte equals 8 bits, which has 2 to the power 8 possibilities, 256 distinct values can be represented. Therefore, the full range of value is 0 - 255, ASCII uses 0 - 127 only.


For some non-printing or hard-to-print characters in ASCII, we write them with escape character (\) in C, instead of typing them directly, and it is called escape sequence.


On the other hand, I have learnt an interesting topic, Function. To use it, we need to define a function then we can call and execute it afterwards. It is very useful in writing programs, as illustrated below, the program can be simplified by calling a function, instead of using printf("*****************\n") one more time.


The following is another example similar to the above one, we can divided the function helping us to count the number of symbols we want to print out. By this method, we can save our time in counting the number of symbols and counting error can be prevented.


Apart from this, there are many different types of function, below are the examples of Math function. They help us to perform mathematical functions such as exponential function, absolute value, and even logarithm an d trigonometric functions.

0 comments:

Post a Comment