exam i
play

Exam I Given: 12 October 2012 Due: End of class This exam is - PDF document

CSE 131 Introduction to Computer Science Fall 2012 Exam I Given: 12 October 2012 Due: End of class This exam is open-book, open-notes (your notes, not somebody elses), and open com- puter. You are not allowed to use any other resources: no


  1. CSE 131 Introduction to Computer Science Fall 2012 Exam I Given: 12 October 2012 Due: End of class This exam is open-book, open-notes (your notes, not somebody else’s), and open com- puter. You are not allowed to use any other resources: no Internet, except to access reposi- tories (your own or studio), and no access to anybody else’s computer. Where possible, answer questions on the pages of the exam. Attach other paper as you need. Your work must be legible. Work that is difficult to read will receive no credit. You must sign the pledge below for your exam to count. Any cheating will cause the students involved to receive an F for this course. Other action may be taken. The exam is due at the end of this class session. Name: Student ID: Problem Possible Received Number Points Points 1 20 2 10 3 30 4 10 5 10 6 20 Total 100 Pledge: On my honor, I have neither given nor received any unauthorized aid on this exam. Signed:

  2. CSE 131 (Exam I) –2– Due by End of class 1. (20 points) Circle the correct type for each expression in the table below, and state the result of evaluating the expression: Expression Type Result 100 + 31 double int boolean String 1 / 2 double int boolean String 100 < 31 double int boolean String "100" + "31" double int boolean String 1.0 / 2 double int boolean String true && false double int boolean String (2 ∗ 4 < 10) + "ly fun" double int boolean String true || false double int boolean String 1 / 2 < = 0 double int boolean String ! (true && (1 < 2)) double int boolean String 2. (10 points) Consider the following computation: double x = ap.nextDouble(); // input first double double y = ap.nextDouble(); // input second double (a) (5 points) Complete the following line of code to compute x divided by y as an integer , discading any digits after the decimal point: int z = (b) (5 points) Complete the following line of code to compute x divided by y as an integer , rounding the result: int z =

  3. CSE 131 (Exam I) –3– Due by End of class 3. (30 points) (a) (10 points) Complete the code below to print true if the first number is the sum of the other two; otherwise print false : int n1 = ap.nextInt(); // first number int n2 = ap.nextInt(); // second number int n3 = ap.nextInt(); // third number (b) (20 points) Complete the code below so that it prints the values of x , y , and z in order (from smallest to largest): 1 int n = ap.nextInt(); // a number: could be positive, negative or zero int x = n*5 + 100; int y = n*2 - 50; int z = n*40 + 10; 1 It is possible that two or more of those variables have the same value.

  4. CSE 131 (Exam I) –4– Due by End of class 4. (10 points) Below write a single loop (using any syntax you prefer) that prints the first 100 odd integers (1, 3, etc.), but omits any integer between 30 and 40: 5. (10 points) Complete the following code as directed by the comments: // n should be a random integer between 0 and 1000 int n = ________________________________ while (____________________) { n = n - 1; } // at this point, n should be zero System.out.println("This value should be zero: " + n);

  5. CSE 131 (Exam I) –5– Due by End of class 6. (20 points) // // Assume that code above here (not shown) created three arrays, // carbs, fat, and prot // each of the same length. // Each entry in the array corresponds to a given food. // double[] carbs contains the food’s carbs in grams // double[] fat contains the food’s fat in grams // double[] prot contains the food’s protein in grams // // For example, the nutrition in food 12 would be given by // carbs[12], fat[12], and prot[12] // // Below, write code that declares, creates, and computes the array // // cals // // which contains, for each food, its calories, as computed by the formula // // calories = 4*(grams of protein + grams of carbs) + 9 * grams of fat // // you did this in Lab 1 for a single food //

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend