SAMPLE QUESTIONS FROM CIS71 EXAMS (G.Ingargiola) ============================================================================== A Computer System includes Hardware, Software and People. List some of each and what they are/do. ============================================================================== What are the basic components of a computer? ============================================================================== Describe what is meant by "Compilation" and "Compiler". ============================================================================== What is a BIT? what is a BYTE? ============================================================================== Describe in detail the steps involved in going from a problem statement (for example, the statement of a homework), to the moment that you have a corresponding running program in C. ============================================================================== It is recommended that you adopt the following steps when solving a programming problem: Problem Statement Analysis Design Implementation Testing Say what is meant by each step and give an example, say, from one of the homeworks. ============================================================================== Give examples of: Keyword Identifiers ============================================================================== Mark all the words that are not legal identifiers: Anna sam Joe's house#7 r2p2 ============================================================================== Give an example of: (a) A compiler directive (b) A variable declaration (c) A Conditional Statement (d) A loop Statement (e) An I/O Statement ============================================================================== What is a variable in C? Give at least one example and show how variables are used. ============================================================================== What is a data type? Give at least one example. ============================================================================== Consider the following loop statements: (a) while (E) S; (b) do S while (E); (c) for (lcv=0;lcv<4;lcv++)S; where E is a boolean expression and S is some executable statement. What is the minimum number of times that S will be executed in the three case? what the maximum? ============================================================================== You are given the following for loop: for(i=0;i<6;i++) printf("i=%d\n",i); Rewrite it using a while loop. ============================================================================== Give one example for each of the following kinds of loops: (a) Counting Loop (b) Sentinel Loop (c) Conditional Loop (d) General Loop ============================================================================== What is the value of the expression: ((2 < 3) && (3 == 3)) || (3 < 1) ============================================================================== What is the value of the expression: 5 + 3 * ( (7 / 2) % 5) ============================================================================== What is printed out by the following program fragment, assuming that x,y, and z are integer variables, with x and y initialized to 0 and z initialized to 1: if(x>0) if(y>0) z=2; else z=3; printf("z=%d\n",z); ============================================================================== Given the variables int x, *y; complete the scanf statement below to initialize the variables x and y: scanf("%d %d", , ); ============================================================================== Describe all that you know about the following function prototype: int moo (char *a[], int n); [of course you do not know what MOO does, but you know what it is, what are its parameters..] ============================================================================== What is written by the following program fragment: .... { int lcv; int a[7]; for (lcv=0;lcv<7;lcv++) a[lcv] = lcv + 2; for (lcv = 6;lcv>=0;lcv--) printf ("%4d", a[lcv]); ..................... } ============================================================================== What is written by the following program fragment: ....... { int lcv; char a[] = "9876543210"; for (lcv=0;lcv>3;lcv++) printf ("%c\n",a[lcv]); ....... } ============================================================================== What is written by the following program? #include int x = 2; int y = 3; int z = 4; void moo(int x, int *y){ int z; x = x+3; *y = *y+3; z = z+3; printf("moo : x = %1d, y = %1d, z = %1d\n", x,y,z); } int main(void){ moo(x, &y); printf("main: x = %1d1, y = %1d, z = %1d\n", x,y,z); } ============================================================================== What is printed by the following program fragment (explain your answer) int x; scanf("%d",&x); if (x) printf("Roses\n"); else printf("Violets\n"); ============================================================================== What is the output of the following program fragment: { int lcv; for (lcv = 1; lcv<=5; lcv++){ printf ("%d\n", lcv); lcv = lcv + 2; } } ============================================================================== What is the output of the following program fragment: { int a[10]; int lcv; for (lcv=0;lcv<10;lcv++) a [lcv] = lcv; for (lcv=0;lcv<5;lcv++) printf("%d %d\n", a[lcv], a[9 - lcv]); } ============================================================================== What is the output of the following program fragment: printf("%f\n", 20/3); printf("%d\n", 10%3); printf("%d\n", 3.1416); printf("%f\n", (double)20/3); printf("%d\n", (int)3.1416); ============================================================================== What is the Scope of an identifier? ============================================================================== Write a function that, given an integer X, returns 1 if and only if X is a multiple of 13, otherwise returns 0. ============================================================================== Write the function root that given three numbers a,b,c returns the value --------- -b + \/b*b - 4ac ---------------- 2a ============================================================================== Without worrying about declarations and initialization of variables, what errors do you find in the following program fragment: if x > 2 x++; else if x < 30 x = x + 12; printf("%d\n", x); else x = 0; ============================================================================== Implement the function: void printfactors (int n); {prints out all the integers, greater than 1, that evenly} {divide the positive integer n} ============================================================================== What is a string? Give the definition, a declaration of a string variable, an example of a string literal. ============================================================================== Describe the following standard string functions strlen strcpy strcmp ============================================================================== Assuming that the integer variable x has value 3, what is its value after each of the following statements: (a) x++; (b) x *= 5; (c) x = (x<2)?7:9; (d) x = x%2; ============================================================================== Write in C the following expressions: (a) The character variable c is equal to a lower y or to an uppercase Y (b) The character variable c is a capital letter (c) The integer variable x is greater than 6 or it is less that 3 ============================================================================== Write the prototype of a function moo that takes as arguments a string and an integer and returns no value. ============================================================================== What is the difference between a Declaration and a Definition. ============================================================================== Write in English the meaning of the following declarations (a) int *x; (b) char y[7]; (c) int *f(char x[], int n); (d) int x[2][3]; (e) int *x[3][4]; (f) int (*x)[3][4]; (g) int *(*x)[3][4]; (h) int foo(int x, char *who); (i) int *foo(int a[], int n); (j) void *foo(int a[], int n); (k) char moo(void); ============================================================================== Write an initial value for the following variables: int x = double y = int z[3] = char w[] = struct { int a; char b; }moo = ============================================================================== Given the definitions struct { char name[20]; int grade; }student; student x; student *y; assign the name "sam" and the grade 3 first to x and then to y. ============================================================================== We write a program moo.c that accepts two command line parameters. Show how we write the main function of the program so as to make sure that the correct number of parameters are received. ============================================================================== Describe the Break Statement and the Continue Statement. Be sure to indicate where they can be used and what they do. ============================================================================== What is printed out by the following program fragment: ......... enum color {green, red, blue} c; .. switch (c) { case green: printf("It is green\n"); case red: printf("It is red\n"); break; default: printf("It should be blue\n"); } in the case that (a) c is green (b) c is red (c) c is blue. ============================================================================== What is printed out by the following program fragment? int x[]={1,2,3}; printf("%d %d\n",x[0],*x); ============================================================================== Write a function that, given as parameters: o a string S of 32 characters o a positive integer N less or equal to 32 returns 1 if and only if the first N characters of S consist of letters and digits [otherwise it returns 0]. ============================================================================== Write the function capitalize that, given as parameter a character returns, if it is a letter, the corresponding capital letter, otherwise it returns the same character unaltered. ============================================================================== Write a function myStrLen that, given as parameter a string returns its length. ============================================================================== For a function, what are: (1) its formal parameters (2) an actual parameters (3) rules for correspondence of formal and actual parameters. ============================================================================== The following is said about parameters of C functions: Parameters can be passed by value or by address. Indicate what this means and give an example of a parameter passed by value and of a parameter passed by address. ============================================================================== Write a function MAX3 that, given three integers, returns the largest one. ============================================================================== Write a program that reads two sequences of twenty integers each and stores them, respectively, in arrays A and B. Then prints out on successive lines: A[1] + B[20] A[2] + B[19] ........... A[20] + B[1] ============================================================================== Implement a function FOO that returns the largest value in an array A of 6 integers. ============================================================================== Explain the following code fragment and specify the correct type for the variable fp: if((fp=fopen("unsorted.dat","r"))==NULL){ perror("fopen"); exit(0); } ============================================================================== Explain the following code fragment and specify the correct types for the variables fp, c, and nchars: nchars=0; while((c=getc(fp))!=EOF){ nchars++; } ============================================================================== Write the code for the function: void mycopy(char fromfile[], char tofile[]); /* It copies the content of the file with name fromfile to the file with name tofile. */ ============================================================================== Given the declaration struct{ char name[20]; int grade; }student; Write the code for the function: void printStudentArray(student a[], int n); /* It prints out the first n elements of the array a. */ ============================================================================== Explain the following program fragment and give a picture showing what it does: typedef struct node { struct node *next; void *value; } node; typedef struct { node *head; node *tail; } queue; queue *init(void){ queue *q; if((q=(queue *)malloc(sizeof(queue)))==NULL){ perror("malloc"); exit(1); } q->head=NULL; q->tail=NULL; return q; } ============================================================================== Explain what is wrong in each of the following program fragments: (a) char x[], y[]; .......... x = y; (b) char x[], y[]; ......... if (strcmp(x,y<=0)) printf("%s is less than %y\n",x,y); (c) int x, y; ......... if (x=y) printf("%d is equal to %d\n",x,y); ============================================================================== We have distinguished a certain number of areas in the memory of a program. What are they? ============================================================================== What is allocated: (a) in the stack (b) in the heap (c) in the global area. ============================================================================== Define and give an example of (a) Local variables (b) Global variables (c) Formal parameters (d) Actual parameters ============================================================================== Describe in English the Linear Search Algorithm and give its function prototype for integer values ============================================================================== Describe in English the Binary Search Algorithm, give its function prototype for integer values, and indicate its complexity in terms of the number n of given values. ============================================================================== Describe in English the Bubble Sort Algorithm and give its function prototype for integer values ============================================================================== Describe in English the Merge Algorithm and give its function prototype for integer values ============================================================================== We have said that the computational complexity of Bubble Sort is n*n, where n is the number of elements being sorted. What does it mean? Do you remember how we reached this conclusion? ============================================================================== Describe, assuming that hmw.c is a C file, the following Unix shell commands: % cc hmw.c % a.out % pico hmw.c ============================================================================== Explain briefly a topic that you have understood well in this course. ============================================================================== Describe a topic that you have understood poorly in this course and explain why you think it so happened. ============================================================================== Describe briefly typical bugs that you made in your programs. ============================================================================== (a) Access time to the main memory of a computer takes about ??? (b) Access time to the hard disk of a computer takes about ??? (c) MIPS stands for ... (d) RAM stands for ... (e) Give an example of statement that you use to talk to the operating system. ============================================================================== Debugging is a term that refers to: (a) A technique for writing programs (b) A technique for eliminating errors in programs (c) A technique for finding out if a program has errors (d) The activity of eliminating known errors from a program ============================================================================== Testing is a term that refers to: (a) A technique for documenting a program (b) The activity that finds out if a program has errors (c) A technique for producing more elegant output (d) A technique for improving the efficiency of a program. ============================================================================== Coding is a term that refers to: (a) What we do when we write a program (b) What we do when we enter the data of a program (c) A technique for eliminating the errors from a program ============================================================================== Design is a term that refers to: (a) A technique for writing programs (b) The activity of planning the implementation of a program (c) A technique for finding out if a program has errors (d) The specification of the purpose of a program ==============================================================================