Thursday, November 5, 2009

Group meeting (Nov 5th)

To help our assignment successfully, we made rules for our group in the meeting.

Group rules:
1. Provide a mailbox and guarantee will check mail every day.
2. Respond for the group meeting schedule as soon as possible ( within 24hrs).
3. PLEASE DO NOT keep quiet during the meeting.
4. If there is no spec for the class, please make an empty cpp and header.

To follow Prof. Fardad's style, we also made some change with our coding style.
1. Function naming: someFunction();
lower first letter on function naming
2. Private and protected variable naming: int _top, bool _dynamic
adding underscore in front of variable

Since last time we have one class IO_Field() left, HongYong is taking care it, thanks to him.
For the new class IO_Vedit, we are looking for the volunteer.

Saturday, September 26, 2009

Challenges #3 : io_display

How do we write the io_display function in ONE line only?

void io_display(const char *str, int row, int col, int len) {
    io_move(row, col);
    if( len <= 0)
        io_putstr(str);
    else {
        for(;len>0; len--) io_putch(*str ? *str++ : ' ' );
    }
}

Well, use the same logic, the code can change as below:

void io_display(const char *str, int row, int col, int len) {
    for((io_move(row, col), (len <= 0)?io_putstr(str):0);  len>0;   len--)
        io_putch(*str ? *str++ : ' ' );
}

Wednesday, September 23, 2009

Challenges: io_display

For the io_display function, here is my consideration:
change the for-loop to while-loop
while(*str && i<len)
   io_putch(*str++);
   i++;
}

Challenges: GetInt

Here is my solution for void GetInt(char *strint, int val):

void GetInt(char *strint, int val) {
int length = 0;
int val_tmp = val;

if (!val_tmp) { /* if val is 0 */
*strint = '0';
*(strint + 1) = '\0';
}
else{ /* check the number of digits in val */
do{
val_tmp /= 10;
length++;
}while (val_tmp);
*(strint + length) = '\0'; /* null byte */
val_tmp = val;
while (length > 0) {
*(strint + length - 1) = val_tmp % 10 + '0';
val_tmp /= 10;
length--;
}
}
}

Tuesday, September 15, 2009

The #define Directive

We can use the #define directive to give a meaningful name to a constant in our program. The syntax is:
#define identifier token-string
The #define directive substitutes token-string for all subsequent occurrences of an identifier in the source file. The identifier is replaced only when it forms a token. For example,
#define SUM x+y
The identifier remains defined and can be tested using the #if defined and #ifdef directives.

Formal parameter names appear in token-string to mark the places where actual values are substituted. Each parameter name can appear more than once in token-string, and the names can appear in any order. The number of arguments in the call must match the number of parameters in the macro definition. Liberal use of parentheses ensures that complicated actual arguments are interpreted correctly. For example,
#define AVG(a,b) (((a)+(b))/2)