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

Similar documents
CS111: PROGRAMMING LANGUAGE II

University of Palestine. Mid Exam Total Grade: 100

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Methods (Deitel chapter 6)

Methods (Deitel chapter 6)

Pace University. Fundamental Concepts of CS121 1

Introduction. C provides two styles of flow control:

Loops. CSE 114, Computer Science 1 Stony Brook University

Loops / Repetition Statements

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

CS110D: PROGRAMMING LANGUAGE I

Chapter 4 Introduction to Control Statements

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

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

LECTURE 5 Control Structures Part 2

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Definite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting

Lecture 04 FUNCTIONS AND ARRAYS

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

Lecture 5: Methods CS2301

TOPICS TO COVER:-- Array declaration and use.

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

FORM 2 (Please put your name and form # on the scantron!!!!)

Principles of Computer Science

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Lecture 04 FUNCTIONS AND ARRAYS

Final Exam Data Structure course. No. of Branches (5)

Computer Programming I - Unit 5 Lecture page 1 of 14

Introduction to the Java Basics: Control Flow Statements

YOU ARE ALLOWED TO HAVE ONLY THE FOLLOWING ON YOUR DESK OR WORKTABLE:

CS 112 Midterm Exam Fall 2016

Introduction to Programming Using Java (98-388)

CS313D: ADVANCED PROGRAMMING LANGUAGE

Unit 1 Lesson 4. Introduction to Control Statements

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Activity 6: Loops. Content Learning Objectives. Process Skill Goals

CS302: Self Check Quiz 2

Visual Programming. Lecture 3: Loops, Arrays. Mahmoud El-Gayyar

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

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

APCS Semester #1 Final Exam Practice Problems

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

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

CompSci 125 Lecture 09. Chapter 5: while, break and continue statements Iterators and the ArrayList Class

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.


Introduction to Programming (Java) 4/12

Chapter 4: Control structures. Repetition

Recap: Assignment as an Operator CS 112 Introduction to Programming

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

Control Structures in Java if-else and switch

A Look Back at Arithmetic Operators: the Increment and Decrement

MEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1. March 28-30, 2007

Programming with Java

Exam 2. CSC 121 TTH Class. Lecturer: Howard Rosenthal. April 26, 2016

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

Sri Vidya College of Engineering & Technology

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

bool bool - either true or false

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017

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

Theory of control structures

CS 112 Introduction to Programming

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Fundamentals of Programming Session 13

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Chapter 4: Control structures

Computer Science II Lecture 1 Introduction and Background

Control Structures in Java if-else and switch

Score score < score < score < 65 Score < 50

STUDENT LESSON A12 Iterations

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

Object Oriented Programming with Java

Control Structures II. Repetition (Loops)

Subject: Fundamental of Computer Programming 2068

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

COMP 202 Recursion. CONTENTS: Recursion. COMP Recursion 1

CS110: PROGRAMMING LANGUAGE I

Methods: A Deeper Look

Lecture 5 Tao Wang 1

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Chapter 12 Supplement: Recursion with Java 1.5. Mr. Dave Clausen La Cañada High School

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

In this chapter you will learn:

Introduction to Java Applications

Computer Science & Engineering 150A Problem Solving Using Computers

Multiple-Subscripted Arrays

Loops / Repetition Statements

Transcription:

Page 1 of 6 Template no.: A Course Name: Computer Programming1 Course ID: Exam Duration: 2 Hours Exam Time: Exam Date: Final Exam 1'st Semester Student no. in the list: Exam pages: Student's Name: Student ID: Group ID: 101 Lecturer name: Mahmoud R. Alfarra Final marks Marks First Question Q1 Q2 Q3 Q Q Total 1 * 7 1 * 20 * 0. * 2 17 0 No. of Branches (1) (7/0) (1 min.) (7/7) Identify and correct the errors in each of the following segments of code (note the type of errors): 1 2 3 6 The following segment should return the result of factorial x. public long fact (long x){ if (x <= 1) return fact(x) else return x * fact(x-1); } The following segment should sum the numbers from 0 to 100. while ( x <= 100 ) total += x; ++x; The following code should print the odd integers from 19 to 1: for ( i = 19; i >= 1; i += 2 ) System.out.println( i ); int gender; if ( gender == 1 ) System.out.println( "Woman" ); else; System.out.println( "Man" ); int sum( int x, int y ) { int result; result = x + y;} int y = 9; if (y<=0); system.out.println("y is less"+ than zero"); else System.out.println("fail");

Page 2 of 6 Assume int b[] = new int [ 10 ]; 7 for ( int i = 0; i <= b.length; i++ ) b[ i ] = 1; Second Question A No. of Branches (1) (2 min.) Convert the following English sentences into a Java sentences to accomplish each of the following tasks: Write the header of Method smallest, which takes three integers x, y and z and returns an integer. (/0) (/) B Using Math class, compare the double x and double y to determine the maximum one of them. C Write two overloaded methods to return the summation of integer x with integer y and float x with float y. D Declare a method ArraySum which takes the array called numbers and returns its summation. And then write the calling statements. E Declare a String array which has 30 cells and then using loop to give the value "Ali" as the initialization of the array's cells. Third Question No. of Branches (2) (10/0) (10 min.) Branch One (/10) State whether each of the following is true [T] or false [F]. If false, explain why or correct? 1 The scope of a parameter declaration is the Header of the method in which the declaration appears.

Page 3 of 6 2 Arrays are data structures consisting of related data items many types. 3 Arrays are allocated with new because arrays are static. Using a value of type long as an array index results in a logical error. The while loop is considered a Post test loop Third Question No. of Branches (2) (1 min.) Branch Two Choose the most correct answer for the following statements: (10/0) (/10) 1 Iteration and recursion each involve a. a Integer counter b termination test c selection d ( b ) + ( c ) 2 The result of Math.floor(-3.7) is. a - 3.0 b - 3 c -.0 d - 3 Motivation of modularizing in java programming is avoid a reusability b Divide & conquer c repeating code d ( a ) + ( b ) A method which performs a task that does not depend on the contents of any object is called.. a Recursive b static c class d ( b ) + ( c ) Counter-controlled repetition requires: a Control variable b initial value c continuation condition d ( a ) + ( b ) + ( c ) 6 A program can test multiple floating cases by placing.. statements a if...else b switch c if d ( a ) + ( b ) 7 Set a semi colon after the condition results a a syntax error b logic error c compilation error d ( a ) + ( d ) 8 Java provides statements and.. to alter the flow of control. a break b continue c switch d ( a ) + ( b ) 9 Comparing strings is doing by using.. method. a ComparTo b == c Ceil d Math 10 A set of statements contained within a pair of braces is called a a segment b loop c block d Class

Page of 6 Fourth Question (10/0) (1 min.) (10/10) Trace the following java's code segments and print the expected results int even [ ]= new int[10]; for (in i = 0 ; i<=7; i++ ) {if(i%2==0) even [i]=i*2; 1 else even[i]= (i-1)*2; System.out.println( even[i]+"\n" );} System.out.println( "Finished" ); counter = 2; do { 2 System.out.println( counter ); counter += 2 ; } While ( counter < 100 ) Suppose x = Start No. of Branches (1) Read X Counter = 1 No Counter <=12 Yes Print (counter *X) Counter = counter +1

Page of 6 Fifth Question No. of Branches () (17/0) (3 min.) (17/17) Answer all the following questions: A Using recursion method concepts, Write a method to calculate the Fibonacci series and then use it to calculate the Fibonacci of with drawing. 3 marks 7 min [Hint]: Fibonacci (n) = Fibonacci (n-1)+ Fibonacci (n-2) Consider a two-by-three integer array t. 1. Write a statement that declares and creates t. 2. Write the names of all the elements in the second row of t. B 2 marks 8 min 3. Write the names of all the elements in the third column of t.. Write a single statement that sets the element of t in row 1 and column 2 to zero.

Page 6 of 6 C marks 20 min (Duplicate Elimination) Use a one-dimensional array to solve the following problem: Write an application that inputs five numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only if it is not a duplicate of a number already read. Provide for the "worst case," in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user inputs each new value. With My Best Wishes Mahmoud Rafeek Alfarra