HOMEWORK 1, Due on Feb 11, 2005 1. Write a C program, which reads a string from stdin and replaces each occurrence of consecutive blanks in the string with single blank(there may be multiple occurrences of consecutive blanks). The end of the string is indicated by a carriage return. The string may have multiple lines, each of which is seperated by a backslash \ right before a carriage return. (which is the convention of writing C programs) 2. Write a function expand(s, t) which converts characters like newline and tab into visible escape sequences line \n and \t as it copies the string s to t.Use a switch. 3. Write a C program that reads a string and converts it to a string such that all the characters are in uppercase. For example, "Life is like a box of chocolates." should be converted to "LIFE IS LIKE A BOX OF CHOCOLATES." 4. Given below is portion of a program that takes as input the letter grade of a student and prints it. Is this porition of the program correct? If not, pick out the mistakes and write the correct portion of the program. Assume that GRADE is of type char. getchar (GRADE); if (GRADE = "A") printf ("You are a GREAT student!"); else if (GRADE = 'B') print (" You are not bad"); else if (GRADE == 'C") printf ('You could do better'); else if (GRADE == 'F') printf("Failing! You better study some more"); 5. What is the output generated by each of the following programs? Do you observe anything unusual? A) main() { int i, sum; i = 0; sum = i; printf("%d ", sum) ; while (i < 20) { i += 5; sum += i ; printf("%d ",sum) ; } printf("\n %d",sum) ; } B) main() { int i, x = 0; for (i=1; i <= 10; i++) if (floor(sqrt(i)) == sqrt(i)) x++; printf(" %d ",x) ; } C) main() { int i, x = 0; for (i=0; i<5; i++) { switch(i) { case 0: {x++; break ;} case 1: {x--; break ;} case 2: {x++; break ;} case 3: {x += 1; } case 4: {x += 2; } } printf("x = %d", x) ; x = 0 ; } } D) main() { int i = 0; printf("%d ", ++i) ; printf("%d", i--) ; } 6. Describe each of the following declarations a. char **a ; b. char (*a)[] ; c. int *f() ; d. int *(*f)() ; e. int (*f())[] ; 7. What will be the output of the following program? main(int argc, char * argv[]) { int i ; for (i = 0; i< argc; i++) { printf("%c ",argv[i][i]) ; } } 8. In the following program, which of the following sepereate expressions evaluate to the contents of p[1]? main() { char p[] = {'a', 'b', 'c'}; char *q; q = p ; /* Here is where the expression goes */ } a) *++q b) *(++q) c) *(q+1) d) *(p+1) e) 1+p 9. Write a test driver for the q functions from the xinu source. You will need the q.h and queue.cpp file. Do things like create queues, add items to the queue, remove items. Test for removal from empty queues and adds to full queues.