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

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

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

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

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Final Exam. COMP Summer I June 26, points

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

AP Computer Science A Summer Assignment 2017

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

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

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

Chapter 4: Control structures. Repetition

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

Chapter 4: Control structures

Prelim One Solution. CS211 Fall Name. NetID

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

Course Outline. Introduction to java

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

CS111: PROGRAMMING LANGUAGE II

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

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

Comp 170 Test 1 SAMPLE June 8, 2000

Midterm Examination (MTA)

PROGRAMMING FUNDAMENTALS

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

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

INTRODUCTION TO SOFTWARE SYSTEMS (COMP1110/COMP1140/COMP1510/COMP6710)

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Solutions to the 2005 exam

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

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

I. True/False: (2 points each)

Selected Questions from by Nageshwara Rao

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

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

COMP 202 Java in one week

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

Give one example where you might wish to use a three dimensional array

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Final Examination Semester 2 / Year 2011

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

EECS168 Exam 3 Review

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Programming with Java

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

CS 101 Exam 2 Spring Id Name

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

CS 177 Spring 2010 Exam I

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

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

CS 101 Spring 2007 Midterm 2 Name: ID:

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

CSCI 201L Written Exam #1 Fall % of course grade

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

CS 1331 Exam 1 ANSWER KEY

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

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

APCS Semester #1 Final Exam Practice Problems

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

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

AP COMPUTER SCIENCE A

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures

CS141 Programming Assignment #6

University of Massachusetts Amherst, Electrical and Computer Engineering

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

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

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

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

Chapter 2: Using Data

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

1. Find the output of following java program. class MainClass { public static void main (String arg[])

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

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

Computer Science II (20082) Week 1: Review and Inheritance

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

CS 111X - Fall Test 1

1 Short Answer (10 Points Each)

Introduction to Computer Science Midterm 3 Fall, Points

Java Coding 3. Over & over again!

I. True/False: (2 points each)

COMP 202. Java in one week

CS 113 PRACTICE FINAL

Algorithms and Conditionals

Lecture Set 4: More About Methods and More About Operators

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

( &% class MyClass { }

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

Practice Midterm 1. Problem Points Score TOTAL 50

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Midterm Review Session

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

CS 106 Introduction to Computer Science I

SELECTION. (Chapter 2)

Flow of Control Branching 2. Cheng, Wei COMP May 19, Title

Transcription:

NAME: ID: CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A Instructor: N. Acemian Monday June 27, 2005 Duration: 3 hours INSTRUCTIONS: - Answer all questions on these sheets in the space provided. - No hand calculators, books, notes or extra paper. - No cell phones, pagettes or any other electronic devices. - This exam is 13 pages long, including the cover page. Check that your copy is complete. - This exam is out of 100 points. GRADING (For Professor s use only) Q1 - Q10/ 25 Q11/ 7 Q12/10 Q13/ 10 Q14/ 10 Q15/ 18 Q16/ 10 Q17/ 10 Total /100

Multiple Choice Questions (circle only one answer) - 2.5 points/ question Question 1. Which of the following would be a legal Java identifier? a) i b) class c) ilikeclass! d) idon'tlikeclass e) i-like-class Question 2. What value will z have if we execute the following assignment statement? float z = 5 / 10; a) z will equal 0.0 b) z will equal 0.5 c) z will equal 5.0 d) z will equal 0.05 e) none of the above, a run-time error arises because z is a float and 5 / 10 is an int Question 3. Assume that x, y and z are all ints equal to 50, 20 and 6 respectively. What is the result of x / y / z? a) 0 b) 12 c) 16 d) A syntax error as this is syntactically invalid e) A run-time error because this is a division by 0 Question 4. If you want to store into the String name the value "George Clooney", you would do which statement? a) String name = "George Clooney "; b) String name = new String("George Clooney "); c) String name = "George" + " " + " Clooney "; d) String name = new String("George" + " " + " Clooney "); e) Any of the above would work Question 5. Which of the following would return the last character of the String x? a) x.charat(0); b) x.charat(last); c) x.charat(length(x)); d) x.charat(x.length( )-1); e) x.charat(x.length( )); COMP 248/1 - AA - 2 - Final Exam/ A

Question 6. Given the nested if-else structure below, if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; if x is currently 0, a = 5 and b = 5, what will x become after the above statement is executed? a) 0 b) 2 c) 3 d) 4 e) 5 Question 7. Given the following switch statement where x is an int, switch (x) { case 3 : x += 1; case 4 : x += 2; case 5 : x += 3; case 6 : x++; case 7 : x += 2; case 8 : x--; case 9 : x++ if x is currently equal to 5, what will the value of x be after the switch statement executes? a) 5 b) 6 c) 7 d) 8 e) 10 Question 8. The relationship between a class and an object is best described as a) classes are instances of objects b) objects are instances of classes c) objects and classes are the same thing d) classes are programs while objects are variables e) objects are the instance data of classes COMP 248/1 - AA - 3 - Final Exam/ A

Question 9. Which of the following loops would adequately add 1 to each element stored in an array values? a. for(j=1;j<values.length;j++) values[j]++; b. for(j=0;j<values.length;j++) values[j]++; c. for(j=0;j<=values.length;j++) values[j]++; d. for(j=0;j<values.length 1;j++) values[j]++; e. for(j=1;j<values.length 1;j++) values[j]++; Question 10. Assume that we have the class Airplane. A 3-by-4 two-dimensional array of objects of the class Airplane is actually: a. A 1 dimensional array of 3 elements where each element is a reference to an array of 4 references to Airplane objects b. A 1 dimensional array of 3 objects where each object contains a data member that is a 1 dimensional array of 4 Airplane objects c. A 1 dimensional array of 12 elements where each element is an Airplane object d. We cannot use 2-dimentional arrays in Java COMP 248/1 - AA - 4 - Final Exam/ A

Short Answer Questions Question #11 (7 points) NESTED SELECTION Given the following code segment. If (b1 == b2) System.out.println( b2 and b1 have the same value ); else if (a1 == a2) System.out.println( a1 and a2 have the same value ); else System.out.println( All variables are different ); a) (2 points) What will be printed if all four variables have the same value? b) (5 points) Rewrite the above code so that when all four variables have the same values it prints out the message All variables have the same value as well. COMP 248/1 - AA - 5 - Final Exam/ A

Question #12. (10 points) STRING CLASS Write the necessary statements part of a main method to: - prompt the user for his/her full name (given name followed by their family name separated by a space) which you read into one String variable - print the first letter of the given name, a period, a space and the family name. Your code should work for any name entered. Assume the user enters their name in the correct format. Here is a sample output: Please enter your name: Nancy Acemian Your abbreviated name is: N. Acemian COMP 248/1 - AA - 6 - Final Exam/ A

Question #13. (10 points) ARRAY, LOOPS Write a static Java method alternatingsum that computes the alternating sum of all elements in an array. For example if alternatingsum is called with an array containing 1 4 9 16 9 7 4 9 11 then it will return the sum of 1 4 + 9 16 + 9 7 + 4 9 + 11. COMP 248/1 - AA - 7 - Final Exam/ A

Question 14. (10 points) INTEGER OPERATORS Write a static Java method called reversesame to compare two integers to see if the first integer contains the same digits as the second integer but in reverse order. For example, - if num1 = 1234 and num2 = 4321 then reversesame(num1, num2) returns true - if num1 = 1234 and num2 = 4561 then reversesame(num1, num2) returns false Note: you are only allowed to use additional variables of primitive types. In particular, you are not allowed to use any String variables. COMP 248/1 - AA - 8 - Final Exam/ A

Question 15. (18 points) WRITE A CLASS ARRAYS OF OBJECTS The class Product encapsulates the concept of a product stocked in a supermarket, e.g. a jar of peanut butter. It should contain the following information: the UPC code of the product (all digits), the name of the product, the price of the product, the quantity of the product currently in stock, and an array of 52 boolean indicating if the product was or will be on special during each week of the current year. Include the following constructor and methods in the class. A constructor which creates a new product with a given code, a given name and a given array indicating which week the product will be or was on special.. Initially, the price and the quantity should be set to zero. A method getname that will return the name of the product. A method addstock that will add a specific value to the quantity of the product in stock. A method outofstock that will return true if there is none of this product in stock. Otherwise it will return false. A method equals to determine if 2 products are equal (have the same values for each attribute) a) (3 points) Represent the class with a UML diagram. b) (6 points) Write the class definition for the class Product.. COMP 248/1 - AA - 9 - Final Exam/ A

c) (3 points) Create a store containing 50 Products. The name of each product will simply be the strings product1, product2, product3, product50, the UPC code will all be zero, and the price will all be 50 cents more then the previous product (the first product will cost 50cents). d) (3 points) Write a series of instructions to display the name of all the products in the store. e) (3 points) Write an instruction to add 50 units to the last Product in the store. COMP 248/1 - AA - 10 - Final Exam/ A

Question 16. (10 points)what is the output of the following code? class Pair { int first, second; public Pair(){ first = second = 0; public Pair(int f, int s){ first = f; second = s; int getfirst() { return first; int getsecond() { return second; void setfirst(int f) { first = f; void setsecond(int s) { second = s; void printpair() { System.out.println("Pair: " + first + ", " + second); Output public class PairTest{ public static void main(string[] args) { int i = 5; Pair c1 = new Pair(); Pair c2 = new Pair(2, 3); c1.printpair(); c1.setsecond(i); c1.printpair(); c2.printpair(); c2.setfirst(i * 3); c2.printpair(); System.out.println(c1.getFirst()); Pair c3 = c2; c3.setfirst(i * 4); c2.printpair(); c3.printpair(); if (c2 == c3) System.out.print( here 1 ); c3 = new Pair(4, 3); if (c2 == c3) System.out.print( here 2 ); COMP 248/1 - AA - 11 - Final Exam/ A

Question #17. (10 points) Write the necessary statements (not a complete program) to prompt the user for a number and then print the hour glass figure as illustrated in the two sample outputs below. Your code should work for odd and even numbers. Assume the user enters a number > 2. Following are two sample outputs to illustrate the cases when a user enters an even and an odd number. There is a space between each star. Enter a number? 5 * * * * * * * * * * * * * * * * * Enter a number? 6 * * * * * * * * * * * * * * * * * * * * * * Sample Output1: Odd number entered Sample Output2: Even number entered End OF Exam COMP 248/1 - AA - 12 - Final Exam/ A