Supplementary Test 1

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

AP Computer Science Unit 1. Programs

Programming with Java

Fundamentals of Programming Data Types & Methods

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Introduction to Computer Science Unit 2. Notes

2.8. Decision Making: Equality and Relational Operators

download instant at

a) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.

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

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

CS141 Programming Assignment #6

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java

AP Computer Science Unit 1. Writing Programs Using BlueJ

Introduction to Computer Science Unit 2. Exercises

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

Midterm Examination (MTA)

Computational Expression

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

Introduction to Java Applications

Introduction to Java Unit 1. Using BlueJ to Write Programs

Introduction to Computer Science Unit 2. Notes

AP Computer Science Unit 1. Writing Programs Using BlueJ

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

AP CS Unit 3: Control Structures Notes

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

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

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

Basic Problem solving Techniques Top Down stepwise refinement If & if else.. While.. Counter controlled and sentinel controlled repetition Usage of

CIS260 Summer Exam 1 First Name Last Name: 2) is the brain of a computer. 2) A) Memory B) Hardware C) Disk D) CPU

ITERATION WEEK 4: EXMAPLES IN CLASS

Anatomy of a Java Program: Comments

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

RANDOM NUMBER GAME PROJECT

Array. Array Declaration:

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

ing execution. That way, new results can be computed each time the Class The Scanner

A token is a sequence of characters not including any whitespace.

Reading Input from Text File

Data Conversion & Scanner Class

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

Midterms Save the Dates!

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

Lecture 8 " INPUT " Instructor: Craig Duckett

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

CS 200 Using Objects. Jim Williams, PhD

Bjarne Stroustrup. creator of C++

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

Object Oriented Programming. Java-Lecture 1

Using Java Classes Fall 2018 Margaret Reid-Miller

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Practice Midterm 1. Problem Points Score TOTAL 50

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

Arrays. Eng. Mohammed Abdualal

CMSC131. Introduction to your Introduction to Java. Why Java?

What did we talk about last time? Examples switch statements

Control Statements: Part 1

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

( &% class MyClass { }

2.5 Another Application: Adding Integers

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

Problem Grade Total

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

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

Practice Midterm 1 Answer Key

Computational Expression

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

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

Algorithms and Conditionals

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

THE JAVA FOR STATEMENT

Example: Monte Carlo Simulation 1

A Quick and Dirty Overview of Java and. Java Programming

Peer Instruction 1. Elementary Programming

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

Oct Decision Structures cont d

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

A+ Computer Science -

COMP 202 Java in one week

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

Full file at

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

University of Cape Town Department of Computer Science. Computer Science CSC115F

Introduction to Java Applications

CS110: PROGRAMMING LANGUAGE I

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

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

COMP 202. Java in one week

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

Java Classes: Math, Integer A C S L E C T U R E 8

Sri Vidya College of Engineering & Technology

Full file at

Introduction to Java & Fundamental Data Types

Arrays OBJECTIVES. In this chapter you will learn:

Welcome to the Primitives and Expressions Lab!

Transcription:

Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Supplementary Test 1 Question Max Mark Internal External 1 10 2 10 3 10 TOTAL 30 Marks : 30 Time : 40 minutes Instructions: a) Answer all questions. b) Write your answers in the space provided.

c) Show all calculations where applicable. 2

Question 1 [10] a) In computer hardware, what is a multicore CPU? [1] a CPU that can execute multiple instructions simultaneously [1] b) What is the purpose of the memory in a typical Von Neumann architecture? [1] store data and instructions while computer is turned on c) What is a variable? [1] location in memory that holds a value d) What is an algorithm? [1] an algorithm is any sequences of instructions to solve a problem [1] e) Why are modern computer programs not usually written in low level languages? [1] difficult for humans to understand [1] geared towards machines [1] f) Give 3 examples of low level programming languages. [2] assembler, machine code, bytecode [2 for all, 1 for 1 2, 0 for none] g) Describe the steps in the process of compiling and executing a Java program. [3] compiler compilers program into bytecode. [1] JVM translates bytecode into machine code. [1] Machine code is executed on CPU.[1] 3

Question 2 [10] Consider the following program and answer the questions that follow. import java.util.scanner; class test { public static void main ( String [] args ) { Scanner input = new Scanner (System.in); int a = input.nextint(); int b = input.nextint(); } } if (a / b == b / a) System.out.println ( yes ); else System.out.println ( no ); a) What is the output of this program if the input is the numbers 3 and 7? [1] no b) Give an example of the name of a variable, from the program. [1] a, b, input,... c) What real world hardware does the input object correspond to? [1] keyboard or keyboard buffer d) What is the purpose of the nextint method? [1] gets an integer from keyboard e) For what values of a and b will the program not work? [1] a=0 or b=0 f) In the if statement above, if the == symbol was converted to!=, what changes would be needed to maintain the meaning of the program? [1] swap the two output statements g) What is the dangling else problem? [2] When you have nested ifs without braces [1] and Java cannot match an else to its corresponding if [1] 4

h) Comments are missing in this program. Write out typical comments to be inserted at the top of the program. [2] // program to check equality of 2 numbers [1] // hussein suleman [1/2] // 12 march 2009 [1/2] 5

Question 3 [10] a) Briefly describe an algorithm to find the maximum of a set of 5 integers. You may write a textual description of the solution or a fragment of a program. Assume the numbers have been input already and are stored as variables a, b, c, d and e. [3] assume a is the maximum. Compare max with b and update max if necessary. Compare max with c and update max if necessary. Compare max with d and update max if necessary. Compare max with e and update max if necessary. b) Write the Java statement to input the first integer into the variable a. You may assume a is already declared as an int and there is already a Scanner object named input. [1] a = input.nextint(); c) Write the Java statement to calculate maximum as the maximum of the 2 floating point values a and b. You may assume a, b and maximum are already declared as float variables. [2] minimum = Math.max (a, b); [2] if (a>b) maximum=a; else maximum=b; [2] d) Write the Java statement to output The maximum is followed by the value of the variable maximum. [2] System.out.println ( The maximum is + maximum); e) Is your algorithm the most efficient solution? Explain why or why not. [2] Yes. It is possible to use different combinations of comparisons but any combination will involve the same amount of work. [marks for explanation no marks for yes/no] 6