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

Similar documents
BSc. (Hons.) Software Engineering. Examinations for / Semester 2

Supplementary Test 1

Chapter 3: Operators, Expressions and Type Conversion

Programming with Java

APCS Semester #1 Final Exam Practice Problems

Operators Questions

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

BSc ( Hons) Computer Science with Network Security. Examinations for / Semester 2

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

CIS March 1, 2018

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

CIS October 19, 2017

Question: Total Points: Score:

Question: Total Points: Score:

CP122 CS I. Iteration

BEng (Hons.) Telecommunications. BSc (Hons.) Computer Science with Network Security

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

BEng (Hons) Electronic Engineering. BEng (Hons) Telecommunications. Examinations for / Semester 2

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

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

Operators in java Operator operands.

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

BENG (HONS) ELECTRONIC ENGINEERING BENG (HONS) TELECOMMUNICATIONS. Cohort: BEE/10A/FT, BEE/10B/FT &BTEL/10B/FT

COMPUTER APPLICATIONS

COMPUTER APPLICATIONS

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

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

Control Structures II. Repetition (Loops)

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

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

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

Zheng-Liang Lu Java Programming 45 / 79

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

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

Building Java Programs

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

Selenium Class 9 - Java Operators

Chapter. Let's explore some other fundamental programming concepts

JAVA OPERATORS GENERAL

Lesson 36: for() Loops (W11D1)

Full file at

Chapter 1: Introduction to Computers, Programs, and Java

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Arrays. 1 Index mapping

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

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

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

Getting started with Java

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

Fundamentals of Programming Data Types & Methods

Final Examination Semester 2 / Year 2011

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

Computers Programming Course 6. Iulian Năstac

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

Lab Assignment Three

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

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

Prof. Navrati Saxena TA: Rochak Sachan

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

CIS October 16, 2018

Building Java Programs

NAMIBIA UNIVERSITY OF SCIENCE AND TECHNOLOGY

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

Topic 4 Expressions and variables

Final Exam. COMP Summer I June 26, points

16. Give a detailed algorithm for making a peanut butter and jelly sandwich.

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Some Practice Midterm Problems

Repetition, Looping. While Loop

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

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

Introduction to Programming Using Java (98-388)

Loops. CSE 114, Computer Science 1 Stony Brook University

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

Algorithms and Problem Solving

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

Control Statements. Musa M. Ameen Computer Engineering Dept.

University of Palestine. Mid Exam Total Grade: 100

Java is an objet-oriented programming language providing features that support

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

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

King Saud University College of Computer and Information Sciences Computer Science Department

OBJECT ORIENTED PROGRAMMING

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

COMPUTER SCIENCE Paper 1

CSIS10B Exam1 Review Solutions One (double sided) sheet of Notes Closed Computer

Building Java Programs

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

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

Building Java Programs Chapter 2

Java Basic Programming Constructs

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

BEng (Hons) Telecommunications. Examinations for 2016 / Semester 2

The University of Nottingham

Introduction to Java & Fundamental Data Types

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

Transcription:

BSc (Hons) Computer Science with Network Security/ BSc (Hons) Software Engineering/ BSc (Hons) Web Technologies Cohort: BCNS/16A/FT BSE/16A/FT- BWT/16A/FT Examinations for 2016 Semester 1 Resit Examination for BCN/15B/FT MODULE: PROGRAMMING CONCEPTS MODULE CODE: PROG1101C Duration: 3 Hours Instructions to Candidates: 1. Answer ALL questions 2. Questions may be answered in any order but your answers must show the question number clearly. 3. Always start a new question on a fresh page. 4. Use of calculator is allowed. 5. Total marks 100. This question paper contains 5 questions and 10 pages. Page 1 of 10

QUESTION 1: (20 MARKS) ANSWER ALL QUESTIONS a) Explain the terms : i. Machine Language ii. Assembly Language iii. High Level Language (3 Marks) b) The machine language for the Java Virtual Machine is called Java bytecode. Give one advantage of bytecode. c) Explain briefly the two ways used to solve a problem using an algorithm? d) A student scored 77 marks in English examination paper. From the algorithm below, give the award classification he got for this subject. Input mark If mark >= 80 Display 'Distinction Else If mark >= 60 AND mark<80 Display Merit Else If mark >=40 AND mark <60 Display Pass Else If mark < 40 Display Fail Page 2 of 10

e) Draw a flowchart to represent the algorithm for finding the average of eight numbers and the sum of the numbers. (5 Marks) f) Write a pseudo-code to describe an algorithm which will accept two numbers from the keyboard and calculate the sum and the division displaying the answer on the monitor screen. (8 Marks) Page 3 of 10

QUESTION 2: (20 MARKS) a) What is the difference between a primitive Java data type and a complex Java data type? Give an example of each. b) What is the difference between a float and a double in Java? c) You are writing a simple Java function to calculate the factorial of a number. The factorial of a number is defined as n! = 1*2*3*...*(n-2)*(n-1)*(n). i. What is the largest value of n whose factorial can be stored in an integer? ii. What happens if you try to store the result of a factorial of 1 greater than the n you answered in (2c i) above. d) What do you understand by the following terms i. A Java Statement. ii. A Java Expression. e) Rewrite the following Java instructions using compound statements. i. int result = result - 1; ii. int result = result / 3; f) What is the difference between a prefix increment and a postfix increment? Page 4 of 10

g) Given the following Java snippet, what is printed on the screen? int i = 10; i += 5; System.out.println(++i); System.out.println(i--%4); h) Write a simple Java program which prints numbers 1 to 100 inclusive on a separate line. For every multiple of 3 the program must print Fizz, instead of that number and for every multiple of 5 the program must print Buzz, instead of that number. For numbers which are multiples of both 3 and 5, the program must print FizzBuzz, instead of that number. (6 Marks) Page 5 of 10

QUESTION 3: (20 MARKS) a) What is the main difference between a Loop statement and IF statement? b) What are the types of loops that Java provide, give a brief explanation on each of them? (6 Marks) c) What do you understand by the term infinite loop? d) Explain the difference between the terms i++ and i-- used when doing loop statements? e) What is the output for the code snippet below? int coreint = 100; for (int i = 4; i> 0; i--) { coreint -= i; System.out.println(coreInt); (4 Marks) Page 6 of 10

f) What is the output for the code snippet below? public class do_while_loop { public static void main(string args[]){ int x = 1; do{ System.out.println("value of x : " + ((x * x)- 1)); x++; while( x < 5 ); g) What is the output for the below snippet of code? public class if_statement { public static void main(string args[]){ int x = 5; int y = 3; if (x > 0 && x < 5) { if (y!= 3){ System.out.println(x-y); else System.out.println(x + 2); else System.out.println(((x + y) * 3) - 2); (2 marks) Page 7 of 10

QUESTION 4: (20 MARKS) a) Explain clearly with a suitable example what is an array? b) Create an array named temperatures which will hold 7 temperatures in degrees centigrade. (3 Marks) c) In what way does an array differ from an ordinary variable? d) Given int[] numbers = {1,2,3,4,5; What is the output of the following? i. numbers[1] =? ii. numbers[5] =? e) Describe, with an example, how to access all elements of an array using a for loop? (3 Marks) f) Declare a two dimensional array called surname of data type String. The array should be initialize with Mr., Mrs., Ms. in the first bracket and with Smith and Jane in the second bracket. Write a java program such that it will display the output as shown below: Mr. Smith Ms. Jane (8 Marks) Page 8 of 10

QUESTION 5: (20 MARKS) a) What is the purpose of using functions (methods) in Java? b) How do you define a function (method) signature in Java? c) What is the return type of a Java function (method) which does not return anything? d) What is the purpose of the main() function (method) in a Java Program? (3 Marks) e) Given the following, what is the output when fun3(fun1(10), 2*5,30); is executed? int fun1(int a) { System.out.println(a); return (a+=10); double fun2(double a) { System.out.print(a); return (a/=5); void fun3(int a, int b, int c) { System.out.println(fun2(fun1(a*3+b+(c/4)))); (4 Marks) Page 9 of 10

f) You need to capture an integer followed by a string from the keyboard input. The integer is to be stored in a variable named productqty and the string is to be stored in a variable named productname. Fill in the appropriate Java instruction(s) at X and Y to achieve this. System.out.println( Enter quantity of product : ); X System.out.println( Enter product name : ); Y (4 Marks) g) You are writing a Java program which will enable a user to convert from miles per gallon (mpg) to liters per 100 km (l/100) and vice versa. You are given the following conversions 1 mile = 1.609 km and 1 gallon = 4.546 liters. Write a simple Java function which will convert from mpg to l/100. Do not use magic numbers, instead declare and use constants where appropriate. (5 Marks) ***END OF QUESTION PAPER*** Page 10 of 10