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

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

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

Programming with Java

Section 2.2 Your First Program in Java: Printing a Line of Text

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

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

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Lesson 10: Quiz #1 and Getting User Input (W03D2)

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

CS111: PROGRAMMING LANGUAGE II

CEN 414 Java Programming

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

Full file at

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Question: Total Points: Score:

b. Suppose you enter input from the console, when you run the program. What is the output?

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

Chapter 2. Elementary Programming

Arrays. Eng. Mohammed Abdualal

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Elementary Programming

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Question: Total Points: Score:

Introduction to Programming Using Java (98-388)

Place your name tag here

Chapter 2: Basic Elements of Java

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

Control Statements: Part 1

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

JAVA Programming Concepts

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

PRIMITIVE VARIABLES. CS302 Introduction to Programming University of Wisconsin Madison Lecture 3. By Matthew Bernstein

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII

Object Oriented Programming. Java-Lecture 1

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Section 2.2 Your First Program in Java: Printing a Line of Text

Welcome1.java // Fig. 2.1: Welcome1.java // Text-printing program.

JAVA Ch. 4. Variables and Constants Lawrenceville Press

2: Basics of Java Programming

Building Java Programs

Introduction to Computer Programming

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

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

AP Computer Science Unit 1. Programs

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Topic 4 Expressions and variables

Computer Science 145 Midterm 1 Fall 2016

Chapter 2 ELEMENTARY PROGRAMMING

Algorithms and Conditionals

Operators in java Operator operands.

2.8. Decision Making: Equality and Relational Operators

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

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

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

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CS110: PROGRAMMING LANGUAGE I

Tutorial 03. Exercise 1: CSC111 Computer Programming I

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

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

CS 177 Spring 2010 Exam I

AP CS Unit 3: Control Structures Notes

Introduction to Java Applications

4 WORKING WITH DATA TYPES AND OPERATIONS

Introduction to Computer Science Unit 2. Exercises

Mr. Monroe s Guide to Mastering Java Syntax

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

Question: Total Points: Score:

COMP 202 Java in one week

Building Java Programs

Midterm Examination (MTA)

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

Question: Total Points: Score:

Chapter 8 Multi-Dimensional Arrays

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

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

Chapter 02: Using Data

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CSE 142, Summer 2014

Building Java Programs

Supplementary Test 1

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

CS2141 Software Development using C/C++ C++ Basics

Data Conversion & Scanner Class

Selection Statements and operators

CS141 Programming Assignment #6

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

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

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

Transcription:

Mid Term Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Student Name: Total Marks: 50 Obtained Marks: Instructions: Do not open this exam booklet until you are directed to do so. This exam will end in ONE Hour (60 Mins). Write your full name and Student registration No. clearly on the first page. When the exam is started, write your complete Student Registration No. clearly on the top of *EVERY* page. Write your solution in the space provided. If you need more space, write on the back of the sheet containing the problem. If still you need more space then you can use extra sheets. In the case of extra sheet, clearly mention the question number whose answer you are giving and you student registration number on the extra sheet. Plan your time wisely. Do not spend too much time on any one problem. Read through all of them first and attack them in order that allows you to make the most progress. Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the clarity and method correctness with which you express your answer. Good luck. 1

Question 1: Fill in the blanks (30) a) What is a Register? (2) A small memory area in the processor b) Can the following conversions involving type castings are allowed? If yes, find the converted results. (4) NOTE: ASCII value of A is 65, B is 66, C is 67, D is 68 and so on. ASCII value of a is 97, b is 98, c is 99, d is 100 and so on. ASCII value of 0 is 48, 1 is 49, 2 is 50 and so on. (1) i = 71 (2) x = 945 (3) y = 475 (4) c = 6 char c = 'G'; int i = (int)c; float f = 945.34f; int x = (int)f; double d = 475.34; int y = (int)d; int i = 54; char c = (char)i; c) How would you write the following arithmetic expression in Java? (2) 4/(3*(r+34)) 9*(a + b*c) + (3 + d * (2 + a))/(a + b * d) d) What is the default data type of the literal value 0.46? (1) double 2

e) What is the default data type of the literal value 46? (1) int f) Identify and fix the errors in the following code: (6) public class Test{ public void main (String []args){ i = 100; double j j = 45.78; k = j + i; System.out.prtin( the value of k is k); Solution: public class Test{ int i = 100; double j; j = 45.78; double k = j + i; System.out.print( the value of k is + k); g) What is the output of the following code: (5) 11 50 111 12 51 System.out.println("1" + 1); System.out.println('1' + 1); System.out.println("1" + 1 + 1); System.out.println("1" + (1 + 1)); System.out.println('1' + 1 + 1); h) Declare a double variable named miles with initial value 100; (1) double miles = 100; 3

i) Declare a double constant named MILES_PER_KILOMETER with value 1.609; (1) final double MILES_PER_KILOMETER = 1.609; j) Consider the following code: public class test{ public static int i = 10; int m = 12 * i++; int j = 34; int n = 23 + --j; What are the values of the following variables after the execution of the above code? (4) i = 11 m = 120 j = 33 n = 56 k) Syntax errors are those errors that are detected by compiler. (1) l) Division by Zero is run time error. (1) m) Logical errors are done by the programmer and are hard to identify. (1) 4

Question 2: Programming (20) a) Write a Java program TicTacToeBoardPrinter that prints a Tic Tac Toe board like (10) public class TicTacToeBoardPrinter{ b) Finding runway length: Given an airplane s acceleration a and take-off speed v, you can compute the minimum runway length needed for an airplane to take off using the following formula: Write a Java program that prompts the user on console to enter v in meters/second (m/s) and the acceleration a in meters/second squared and displays the minimum runway length. (10) import java.util.scanner; public class RunwayLength{ double v, a, length; Scanner input = new Scanner(System.in); System.out.print ( Enter the value of Speed of Airplane in meter per second : ); v = input.nextdouble(); System.out.print ( Enter the value of Acceleration of Airplane in meter per second square : ); a = input.nextdouble(); length = (v * v)/(2 * a); System.out.print( The minimum length of the runway is + length); 5