DOC PREVIEW
UW CSE 142 - Study Notes

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers suggests otherwise. What are the first three lines printed by the following code? int row = 1, i; while (row < 10) { switch (row % 3) { case 0: for (i = 1; i <=4; i++) printf ("+-"); break; case 1: for (i = 1; i <=4; i++) printf ("--"); break; case 2: for (i = 1; i <=4; i++) printf ("++"); break; default: for (i = 1; i <=4; i++) printf ("-+"); } printf ("\n"); row = row+1; } A. -------- ++++++++ -+-+-+-+ B. +-+-+-+- -------- ++++++++ C. -------- ++++++++ +-+-+-+- D. -+-+-+-+ -+-+-+-+ -+-+-+-+ 1. E. +-+-+-+- +-+-+-+- -------- Suppose you have a program that keeps track of deposits, withdrawals, and interest to a bank account. Inside the main() function, there is a variable that keeps track of the current balance in the bank account, declared as follows: double balance; Which of the following function prototypes could NOT be a function that could be called in main() to figure out the new balance and update the balance variable?: A. double update_balance(double old_balance, double interest, double amount); B. int withdraw_money(double *new_balance, double old_balance, double amount); C. void add_interest(double old_balance, double *new_balance, int days_of_interest, double interest_percent) D. void withdrawal(double old_balance, double amount, double new_balance, int *is_overdrawn); 2. E. double calc_moneyleft(double withdraw_amount, double old_balance);Page 2 Just after line S of the following program executes, what is the value of stop? #define START 10 int main (void) { double stop, start; start = START; stop = stop + start; /*line S*/ return (0); } A. 0.0 B. 10 C. 10.0 D. unpredictable (although the program will compile without error). 3. E. the program will have a syntax error, because start is defined twice (once spelled "START" and once as "start"). If the program fragment below executes, how many times does the word "Hello" get printed? int i, j, k; for (i = 0; i < 100; i = i + 10) for (k = 0; k < 5; k ++) for (j = 1; j <= 1; j++) { printf("Hello\n"); i = i-1; } A. 10 B. 20 C. 50 D. 100 4. E. Infinite What is the value of the expression: x % y + x / y + y % x given the following declarations: int x = 7; int y = 3; A. 3 B. 4 C. 5 D. 6 5. E. 7Page 3 Choose the conditional expression which is true only when the value of x (an int variable) is even and in the range 0 to 6. A. x == 0 && x == 2 && x == 4 && x == 6 B. x > 0 && x != 1 || x != 3 || x != 5 && x < 7 C. (x % 2) == 1 && x >= 0 && x <= 6 D. (x % 2) == 0 && x >= 0 && x <= 6 6. E. x == (2 * x) && x >= 0 && x <= 6 #define MAXGRADES 20 ... int winter[MAXGRADES]; int spring[MAXGRADES]; int classSize, i; The array winter has been initialized. The variable classSize contains the number of elements of winter which are used (all the used elements are together without gaps starting in the 0th position of the array). Which of the following code fragments will correctly copy the used elements of winter to the array spring? A. spring = winter; B. for (i = 0; i < classSize && i < MAXGRADES; i ++) spring[i] = winter[i]; C. spring[MAXGRADES] = winter[MAXGRADES]; D. spring[classSize] = winter[classSize]; A. A only B. B only C. C only D. D only 7. E. more than one of A, B, C, or D Among the choices given, the best definition of an "expression" is... A. a series of steps which compute an answer B. a mathematical formula C. something in a program which has a value D. an arithmetic operation 8. E. a single statementPage 4 What is the primary job of the Linker? A. To combine functions, libraries, etc. into an executable program B. To translate source code into object code C. To find syntax errors in a program D. To find semantic errors in a program 9. E. To convert input characters into the proper data types for the variables used for input Suppose the function Snork has the following prototype: int Snork(char *p, int x, int *y); Which of the following is a legal use of Snork assuming the declarations: int i, j; char ch; A. i = Sn ork(’A’, 10, j); B. j = *Snork(&ch, &i, &j); C. i = Snork(&ch, i, &17); D. Snork(ch, i, &j); 10. E. None of the above The setToBiggest function sets both of its input variables (passed as output parameters) to the value of the larger input. Which of the following is the correct function body for void setToBiggest(int *x, int *y){ BODY } A. if (x > y) y = x; else x = y; B. *y = x; *x = y; C. int temp; temp = *y; if (*x > *y) temp = *x; *y = temp; *x = temp; D. if (*x > *y) *x = *y; if (*y > *x) *y = *x; 11. E. *x = *y; if (y < x) *y = *x;Page 5 typedef struct { char name [MAX_NAME+1]; int id; double score; } Student Record; StudentRecord a[MAX_STUDENTS]; What are the types of the following three expressions: a[0], &a[5], a[0].name[0] A. StudentRecord, Illegal, char array B. struct, pointer, name C. StudentRecord array, StudentRecord, char D. StudentRecord array, StudentRecord, Illegal 12. E. StudentRecord, StudentRecord*, char typedef struct { int x, y; } Point; typedef struct { int color; Point pos; } ColoredPoint; MovePoint(ColoredPoint *cp){ ... } In the function MovePoint, what is the correct code to move cp to the origin of the coordinate system? A. cp->pos.x = 0; cp->pos.y = 0; B. cp.pos->x = 0; cp.pos->y = 0; C. cp->pos->x = 0; cp->pos->y = 0; D. cp.pos.x = 0; cp.pos.y = 0; 13. E. cp->pos = {0, 0};Page 6 void SetToQuestion(char str[]){ } The function SetToQuestion is supposed to set the string str to a string of all ’?’ characters. The length of the string is not changed. For example, if we have: char bob[5] = "ABCD"; then the call SetToQuestion(bob) would make bob the string "????" Which code correctly implements the body of SetToQuestion? A. int i=0; while (str[i] != ’\0’){ i = i + 1; str [i] = ’?’; } B. int i=0; while (str[i] != ’\0’){ str [i] = ’?’; i = i + 1; } C. int i=0; while (str[i] != ’?’){ str[i] = ’?’; i = i + 1; } D. int i; for (i = 0; str[i] != ’?’; i++) str [i] = ’?’; 14. E. int i; for (i = 0; str[i] == ’?’; i++) str[i] = ’\0’;


View Full Document

UW CSE 142 - Study Notes

Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?