(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

Similar documents
CSCE 145 Exam 1 Review Answers. This exam totals to 100 points. Follow the instructions. Good luck!

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

Chapter 4: Control structures. Repetition

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Chapter 4: Control structures

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

I. True/False: (2 points each)

University of Massachusetts Amherst, Electrical and Computer Engineering

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!

McGill University School of Computer Science COMP-202A Introduction to Computing 1

1. Escape Sequences For each of the following snippets of code write down what will be printed on the screen.

AP CS Unit 3: Control Structures Notes

CS 112 Midterm Exam Fall 2016

(b) This is a valid identifier in Java: _T_R-U_E_. (c) This is a valid identifier in Java: _F_A_L_$_E_

Midterm Examination (MTA)

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

CSC141, Computer Science I, Instructor: Dr. Zhen Jiang, Test 2

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

APCS Semester #1 Final Exam Practice Problems

BSc (Hons) Computer Science with Network Security/ BSc (Hons) Software Engineering/ BSc (Hons) Web Technologies. Examinations for 2016 Semester 1

Selection Statements and operators

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Operators Questions

Operators in java Operator operands.

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

Exam 1. CSC 121 Spring Lecturer: Howard Rosenthal. March 1, 2017

Recitation: Loop Jul 7, 2008

Computer Applications Answer Key Class IX December 2017

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Decisions in Java IF Statements

CSIS-120 Final Exam Fall 2015 Name:

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

Introduction to Java Applications

Types, lists & functions

Introduction to the Java Basics: Control Flow Statements

CEN 134 Algorithms and Programming II Midterm I. April Duration: 90 minutes

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

Programming (Ü) Flow of Control. Solutions

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

COMPUTER APPLICATIONS

Task 1: Print a series of random integers between 0 and 99 until the value 77 is printed. Use the Random class to generate random numbers.

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Decision-Making and Repetition

CHAPTER 5 FLOW OF CONTROL

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

Selenium Class 9 - Java Operators

Selection and Repetition Revisited

JAVA OPERATORS GENERAL

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

SELECTION. (Chapter 2)

ESC101 : Fundamental of Computing

BRANCHING if-else statements

AP Computer Science Homework Set 1 Fundamentals

Name Section: M/W T/TH Number Definition Matching (6 Points)

Write a program which converts all lowercase letter in a sentence to uppercase.

6 COMPUTER PROGRAMMING

Final Exam. COMP Summer I June 26, points

APCS Assessment Sheet Consider the following program segment int count = 1;

Practice problems Set 2

Name Section: M/W T/TH Number Definition Matching (8 Points)

Selection and Repetition

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

Homework Set 1- Fundamentals

Selection and Repetition Revisited

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

CSIS-120 Final Exam Fall 2015 Name:

AP COMPUTER SCIENCE A

LAB 11: METHODS. CPCS The Lab Note Lab 11 Page 1. Statement Purpose:

(a) This midterm exam is very easy! (b) In Java the return value of a method can be ignored.

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

Repetition, Looping. While Loop

Claremont McKenna College Computer Science

Thomas Jefferson Invitational Open in Informatics 2012

Computer Programming I - Unit 5 Lecture page 1 of 14

ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

1. A company has vans to transport goods from factory to various shops. These vans fall into two categories: 50 items 150 items

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

LAB 5: SELECTION STATEMENTS

Programming with Java

The Java language has a wide variety of modifiers, including the following:

I. True/False: (2 points each)

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Control Structures in Java if-else and switch

Transcription:

ComS 207: Programming I Midterm 2, Tue. Mar 21, 2006 Student Name: Student ID Number: Recitation Section: 1. True/False Questions (10 x 1p each = 10p) Determine the value of each boolean expression given the following initial conditions: boolean a=true, b=false; int c=5, d=4; (a) (a (a && b)) (b) (b (a && b)) (c) ((!(a && b)) == (!a!b)) (d) (a && (c == d)) (e) (b && (c!= d)) (f) ((!(a b)) == (!a &&!b)) (g) (!(!a) && (c-d > 0) && (b!b)) (h) ((!false!=!(!true)) (3*3 + d*d <= c*c) && (a!a)) (i) (!a (!b && (c!= 0)) == (!(d -13%5-1 > 0)) &&!(!a!=!b)) (j) ((c-3/2 == 4) && (!b && false) (c == ++d) && (a && true)) 1

2. Short Answer Questions (5 x 2p each = 10p) (a) What is a ragged array? (b) What is a method? (c) What it the difference between an if statement and a switch statement? (d) What is a debugger? (e) What is the difference between a do loop and a while loop? 2

3. Code Snippets (3 x 5p each = 15p) Write a code snippet (3-5 lines max) that produces the result specified below. (a) Print the odd numbers from 1 to 100. The output should be in the following format: 1, 3, 5, 7,... (b) Calculate and print the numbers between 1 and 1000 that are powers of 2. The output should be in the following format: 2, 4, 8, 16,... (c) Calculate and print the sum of the numbers between 1 and 100 (inclusive). 3

4. Rewriting Code (4 x 5p each = 20p) (a) Rewrite the following while loop as a for loop. int i = 20; while(i > -10) { i = i -5; System.out.println("Value of i is " + i); } (b) Rewrite the following do loop as a for loop. int number= -5, j=0; do { System.out.println("number= " + number); number+=j; j++; } while(number <10); 4

(c) Rewrite the following switch statement using only if and else statements. switch(letter) { case A : case a : acount++; break; case B : case b : bcount++; break; default: System.out.println("Invalid Input"); break; } (d) Rewrite the following for loop as a do loop. for(;;) ; 5

5. What is the Output? (2 x 5p each = 10p) For each of the following code snippets write down what will be printed on the screen. (a) for(int a=0; a<5; a++) { for(int b=0; b<a; b++) System.out.print("#"); System.out.println("#\n#"); } (b) int[] a={1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int[] b={5, 3, 1, 0, 9, 2, 6, 8, 4, 7}; for(int i=0; i<b.length; i++) System.out.print(b[a[b[i]]] + ", "); System.out.println(); 6

6. Programming Projects (TOTAL 65p, but each has a different weight) (a) Numbers to Text (15p) Write a complete Java program that reads in an integer number and output its digits in reverse order but in English. For example, if the input was 608 then the output should be Eight Zero Six. You can assume that the user will be nice and will always input an integer. 7

(b) 3D Vectors (15p) Write a complete Java program which asks the user to enter the coordinates of two 3D vectors. In other words, the program must read two sets of three floating point numbers which represent the x, y, and z coordinates of the two vectors: u = (u x, u y, u z ) and v = (v x, v y, v z ). The program must then calculate and print on the screen the following four values associated with the vectors: 1) the length of the vector u; 2) the length of the vector v; 3) the dot product between the two vectors; 4) the angle θ between the two vectors. Hint 1: The length (or norm) of the vector u is defined as: u = u 2 x + u2 y + u2 z Hint 2: The dot product of two vectors u and v is defined as: u v = u x v x + u y v y + u z v z ( ) Hint 3: The angle between two vectors u and v is defined as: θ = acos u v u v 8

(c) Largest Five (15p) Write a Java program that initializes an integer array of size 10 with random integers between 1 and 10. The program must then find and print the five largest numbers stored in the array and their corresponding indices. If there are two (or more) numbers in the top five that have the same magnitude (this is possible since the array is initialized at random) then the number with the smaller index should be printed first. For example, if the random array is {9, 2, 4, 4, 2, 5, 7, 6, 7, 6} the program should print: 1) 9 at index 0 2) 7 at index 6 3) 7 at index 8 4) 6 at index 7 5) 6 at index 9 9

(d) Pascal s Triangle (20p) Write a Java program that calculates and prints the first nine rows (0, 1,... 8) of Pascal s Triangle (see the figure below). This triangle has many interesting mathematical properties and is formed as described below. Row 0 contains only a single number which is equal to 1. The first and the last number in all other rows is also 1. Any other number in the triangle can be calculated by adding the two numbers located above it. For example, the number 2 on row two is equal to the sum of the two 1 s located above it on row one. Similarly, the first 15 on row six is equal to the sum of the numbers 5 and 10 located above it on row five. And so on. NOTE: You will get 15 points if your program can calculate and print the first nine rows regardless of the output format. To get the extra 5 points you must print the output in the form of a triangle similar the figure below (hint 1: printing the output in this format is similar to printing the asterisks in problem 5.13.d on page 281 in your textbook; hint 2: the largest number in the first nine rows has at most two digits). 10

That s it. Good Luck! Question Max Score True/False 10 Short Answer 10 Code Snippets 15 Rewriting Code 20 What is the Output 10 Numbers to Text 15 3D Vectors 15 Largest Five 15 Pascal s Triangle 20 TOTAL: 130 11