CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Similar documents
Data Structures and Algorithms Winter Semester

CSEN 202: Introduction to Computer Programming Spring term Final Exam

Data Structures and Algorithms Winter term 2012

Data Structures and Algorithms Winter term 2006/2007 Final Exam

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

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

Midterm Examination (MTA)

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

I. True/False: (2 points each)

Question: Total Points: Score:

Data Structures and Algorithms Winter term 2016

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

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

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

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 6 Discussion:

CIS Introduction to Computer Programming Spring Exam 1

Final Exam. COMP Summer I June 26, points

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CSE142 Sample Midterm, Winter 2018

CSE 1223: Exam II Autumn 2016

Question: Total Points: Score:

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

Place your name tag here

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

CSE 142 Sample Midterm Exam #3

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

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CS 101 Exam 1 Spring 200 Id Name

I. True/False: (2 points each)

1 Short Answer (10 Points Each)

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm

COS 126 General Computer Science Fall Written Exam 1

AP COMPUTER SCIENCE A

CSEN 102 Introduction to Computer Science

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

CSE 143 Sample Midterm Exam #8 (12wi)

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

I. True/False: (2 points each)

1. An operation in which an overall value is computed incrementally, often using a loop.

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

CSE 114 Computer Science I

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50

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

CS 113 MIDTERM EXAM 2 SPRING 2013

2.2 - Making Decisions

COS 126 General Computer Science Spring Written Exam 1

CS 101 Fall 2006 Midterm 1 Name: ID:

CSE413 Midterm. Question Max Points Total 100

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

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

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Problem Points Score Grader Total 75

CS 101 Spring 2007 Midterm 2 Name: ID:

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

CSEN 202 Introduction to Computer Programming

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS 101 Exam 2 Spring Id Name

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

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

Building Java Programs

Term 1 Unit 1 Week 1 Worksheet: Output Solution

CSE 142 Sample Midterm Exam #3

COE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018

H212 Introduction to Software Systems Honors

CIS 110 Introduction to Computer Programming. 12 February 2013 Midterm. Answer Key

Midterm Review Session

CIS 110 Introduction To Computer Programming. November 21st, 2011 Exam 2

CSE 143 Lecture 11. Decimal Numbers

Practice Midterm 1. Problem Points Score TOTAL 50

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

CS 305j Midterm 2 Fall 2006

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 9 Discussion:

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 2 Discussion

AP CS Unit 3: Control Structures Notes

Question: Total Points: Score:

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010

NATIONAL UNIVERSITY OF SINGAPORE

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

CMPS 11 Introduction to Programming Midterm 1 Review Problems

Following is the general form of a typical decision making structure found in most of the programming languages:

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

Transcription:

Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code Instructions: Read carefully before proceeding. 1) Please tick your major Major Civil BI Engineering 2) Duration of the exam: 2 hours (120 minutes). 3) No books or other aids are permitted for this test. 4) This exam booklet contains 11 pages, including this one. Three extra sheets of scratch paper are attached and have to be kept attached. Note that if one or more pages are missing, you will lose their points. Thus, you must check that your exam booklet is complete. 5) Write your solutions in the space provided. If you need more space, write on the back of the sheet containing the problem or on the three extra sheets and make an arrow indicating that. Scratch sheets will not be graded unless an arrow on the problem page indicates that the solution extends to the scratch sheets. 6) When you are told that time is up, stop working on the test. Good Luck! Don t write anything below ;-) Exercise 1 2 3 4 5 Possible Marks 16 10 12 12 15 65 Final Marks

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 1 Exercise 1 (16 Marks) For each code fragment, (1) fill in the most appropriate data type in the 1st column and (2) fill in the value that z contains after the code has been executed in the 2nd column. If the code would result in an error, write ERROR in the 1st column and give the reason for the error in the 2nd column (you do not need to write the exact error message). The first two have been done for you. Code DataType/Error Value of z/reason z = 0.0; double 1.0 z++; z = true; ERROR z appears to have been declared as a boolean z = 1; originally and so can t be set to an int. z = 8; z /= 3; int 2 String s = "GUC"; z = s.length(); int 3 z = a ; int or 98 or z++; char b z = "hello"; z = z + 11.0; String hello11.0 String s = "CSEN"; == used for equality check z == "CSE" + "N"; ERROR not for assignment String s = "apples"; z = s.charat(5); char s int x = 0; int y = 1; int 1 z = (x = y); z = a < b ; boolean true

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 2 Exercise 2 (8+2=10 Marks) a) Write a method that takes two strings s1 and s2 as inputs and checks whether string s1 is a substring in string s2. You are only allowed to use the methods charat, length, and equals. Do not use neither indexof nor contains method. checkoccurrences("ab", "ababcdab") -> true checkoccurrences("ababcdab", "ab") -> false checkoccurrences("aa", "aaaaa") -> true public static boolean checkoccurrences (String s1, String s2) { boolean f = false; for (int i = 0; i < s2.length(); i++) { String temp = ""; for(int j = 0; j < s1.length() && (i+s1.length()) <= s2.length(); j++) { temp += s2.charat(i+j); if(temp.equals(s1)) f = true; return f; b) Write a test program with a main method that prompts the user to enter two strings and calls the method implemented above. public static void main(string [] args) { Scanner sc = new Scanner(System.in); String x = sc.next(); String y = sc.next(); System.out.println(checkOccurrences(x,y));

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 3 Exercise 3 For each of the calls to the following recursive method below, indicate what output is produced: (12 Marks) public static void mystery(int x, int y) { if (y <= 0) { System.out.print("0 "); else if (x > y) { System.out.print(x + " "); mystery(x - y, y); else { mystery(x, y - x); System.out.print(y + " "); a) mystery(6, 3); 6 0 3 b) mystery(3, 10); 3 2 0 1 4 7 10

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 4 Exercise 4 (12 Marks) We would like to count the number of ears in a mutant bunny line assuming that even numbered mutant bunnies have 2 ears and odd numbered mutant bunnies have 3 ears. Write two methods mutantbunnyears that given the number of mutant bunnies returns the number of ears of the bunnies. Implement the methods once recursively and once sequentially. For example: mutantbunnyears(1) would return 3 mutantbunnyears(2) would return 3+2 = 5 mutantbunnyears(3) would return 3+2+3 = 8 a) Recursive Method public static int mutantbunnyears(int x){ if(x == 1) return 3; else if(x%2 == 0) return 2 + mutantbunnyears(x-1); else return 3 + mutantbunnyears(x-1); b) Sequential Method (without loops nor recursion) public static int mutantbunnyearsseq(int numbunnies){ int answer = 5 * numbunnies / 2; answer += 3 * numbunnies % 2; // another solution int t = 3*((numBunnies+1)/2) + 2*(numBunnies/2); System.out.println(t); return answer;

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 5 Exercise 5 (15 Marks) At McDonalds one can buy chicken nuggets in packages containing 6, 9 or 20 pieces. Write a Java method that takes as input an integer, num, and decides about the number of packages of nuggets to buy. For example, nuggets(41) should display: 2 package(s) of 6 pieces, 1 package(s) of 9 pieces and 1 package(s) of 20 pieces. nuggets(50) should display: 2 package(s) of 6 pieces, 2 package(s) of 9 pieces and 1 package(s) of 20 pieces. 5 package(s) of 6 pieces, 0 package(s) of 9 pieces and 1 package(s) of 20 pieces. nuggets(14) should display You cannot buy 14 nuggets public static void nuggets(int num){ boolean flag = false; for(int a =0 ; a <= num/6+1; a++) for(int b=0; b <= num/9+1; b++) for(int c = 0; c <= num/20+1; c++) if (6*a + 9*b + 20*c == num) { flag = true; System.out.println(a +" package(s) of 6 pieces, "+ b +" package(s) of 9 pieces and "+ c +" package(s) of 20 pieces."); if(!flag) System.out.println("You cannot buy "+num+" nuggets")

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 6 Scratch paper

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 7 Scratch paper

CSEN202: Introduction to Computer Science, Midterm Exam, April 6, 2017 Page 8 Scratch paper