Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

Similar documents
Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

CSCI 2132 Software Development. Lecture 19: Generating Permutations

CSCI 2132 Software Development Lecture 18: Implementation of Recursive Algorithms

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5)

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

CSCI 2132 Software Development. Lecture 17: Functions and Recursion

CSCI 2132 Software Development Lecture 35: Dynamically Allocated Arrays, Course Review

CSCI 2132 Final Exam Solutions

Computer Science Foundation Exam

COS 126 General Computer Science Spring Midterm 1

CSCI 2132 Software Development. Lecture 18: Functions

Computer Science Foundation Exam

CSE 143 SAMPLE MIDTERM

Midterm 1 1 /8 2 /9 3 /9 4 /12 5 /10. Faculty of Computer Science. Term: Fall 2018 (Sep4-Dec4) Student ID Information. Grade Table Question Score

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

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

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store)

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

CSCI 2132 Final Exam Solutions

ECE264 Fall 2013 Exam 1, September 24, 2013

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

CSCI 2132 Software Development. Lecture 20: Program Organization

BSM540 Basics of C Language

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

16.216: ECE Application Programming Fall 2011

Functions BCA-105. Few Facts About Functions:

United States Naval Academy Electrical and Computer Engineering Department EC312-6 Week Midterm Spring 2016

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

Functions. Arash Rafiey. September 26, 2017

CS 122/132 Midterm Exam Winter 2003

Announcements. Recursion and why study it. Recursive programming. Recursion basic idea

Binary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal

Decimal Representation

CSE 5A Final Fall 2006

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

We first learn one useful option of gcc. Copy the following C source file to your

UIC. C Programming Primer. Bharathidasan University

CSE413 Midterm. Question Max Points Total 100

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

Compiling and Running a C Program in Unix

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

CSE 303, Winter 2007, Midterm Examination 9 February Please do not turn the page until everyone is ready.

COS 126 General Computer Science Spring Written Exam 1

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

Subject: Fundamental of Computer Programming 2068

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

COS 126 General Computer Science Fall Written Exam 1

16.216: ECE Application Programming Fall 2013

CPSC 311, 2010W1 Midterm Exam #2

Q1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

Question 1. [15 marks]

CS 132 Midterm Exam Winter 2002

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

CIS 110 Introduction to Computer Programming Summer 2014 Final. Name:

EECE.2160: ECE Application Programming Fall 2017

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

EECE.2160: ECE Application Programming Spring 2018

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

MIDTERM TEST EESC 2031 Software Tools June 13, Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

ECE 2400 Computer Systems Programming, Fall 2017 Programming Assignment 3: Sorting Algorithms

This exam is to be taken by yourself with closed books, closed notes, no calculators.

COS 126 Midterm 1 Written Exam Fall 2011

CS Operating system

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Data Structure & Algorithms Laboratory Manual (CS 392)

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

C0MP1911 Final Exam 1337 Computing 1

CS 314 Principles of Programming Languages. Lecture 9

War Industries Presents: An Introduction to Programming for Hackers Part III - Advanced Variables & Flow Control.


CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Fundamentals of Programming Session 8

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

McGill University Faculty of Science School of Computer Science. MIDTERM EXAMINATION - Sample solutions. COMP-250: Introduction to Computer Science

20-CS Programming Languages Fall 2016

More examples for Control statements

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

Unit 7. Functions. Need of User Defined Functions

CS16 Exam #1 7/17/ Minutes 100 Points total

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

CSE 143 SAMPLE MIDTERM SOLUTION

Transcription:

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24 Student Name: Student ID Number: FCS Username (CSID): Signature: Please Note: These solutions are for students in the Winter 2018 version of CSCI 2132 only. They may not be photocopied or distributed in any way, including electronically, to any other person without permission of the instructor. Instructions (Read Carefully): 1. Aids allowed: one 8.5 by 11 piece of paper with anything written or printed on it (both sides). No textbooks, computers, calculators, or other aids. 2. This exam has 7 pages, including this page. Ensure that you have a complete paper. 3. Understanding the exam questions is part of the exam. Therefore, questions will not be interpreted. Proctors will confirm or deny any error or ambiguities only. If you are unsure of your own understanding, clearly state reasonable assumptions that will not trivialize the questions. 4. Marks will not be given for documentation, though feel free to add documentation if you feel necessary. You however should make your code readable to facilitate marking. 5. Questions are NOT sorted from the easiest to the most difficult. 1

1. [6 marks] True-false: 2 marks each. No justification necessary. (a) In the C programming language, function arguments are passed by value. true (b) In black box testing, we use internal knowledge of implementation to guide the selection of test cases. false (c) The stack frame of a C function stores external variables that are used by statements of this function. false 2. [6 marks] Multiple-choice no justification necessary. Circle the single best answer. 3 marks each. (a) If ch is a variable of type char, which one of the following statements is illegal? A. i += ch; /* i has type int */ B. ch++; C. ch = getchar(); D. printf(ch); (b) Which of the following is the fourth of the five steps in the Waterfall Model that was proposed to describe software development life cycle? A. Implementation; B. Verification; C. Requirements Analysis; D. Software Design. 2

3. [8 marks] Give concise answers to the following questions. 4 marks each. (a) Suppose that we have compiled a C program and generated an executable program named binary which is ready to be debugged using gdb. We have also entered gdb binary to debug it. Write down four gdb commands to perform the following tasks: i. Set a break point at the main function. ii. Run this program using gdb. iii. When the program pauses, run a gdb command such that each time we run one line of the program, the value of the variable middle in the program will be printed automatically by gdb. iv. Execute the next statement of the program. There are two commands that can perform this task. You are just required to give one of them and you are not required to state the difference between these two commands. break main run display middle step For the fourth command, you can also use next (make sure that you know the difference). You are allowed to use abbreviations of these commands. (b) For the following pair of scanf format strings, indicate whether or not the two strings are equivalent: "%d-%d-%d" versus "%d -%d -%d" If they are, simply say yes and no justification is required. If not, show how they can be distinguished by providing one input. You need not explain why this input distinguishes them. No 1-1-1 3

4. [8 marks] Show the output produced by each of the following program fragments. You need not justify your answers. 4 marks each. (a) int i = 1; int j = 2; if (i) { int i; i = j; j = 0; printf("%d %d\n", i, j); Solution: 1 0 (b) #include <stdio.h> int mystery(int n); int main() { int n = 3; printf("%d %d\n", n <= 1, mystery(n)); return 0; int mystery(int n) { if (n <= 1) return 1; return (mystery(n-1) + n); Solution: 0 6 4

5. [11marks]Apalindromicnumberisanumberthatremainsthesamewhenitsdigitsare reversed. For example, 14941 and 2332 are palindromic. 27671 is not: when reversing its digits, we get the number 17672 which is different from the original number. The following C program asks a user to enter a positive integer, and then tells whether this number is palindromic. Part of the program is given, and you are required to complete the program by filling in the missing code. There are two sub-problems: (a) In the main function, write the code that computes the digits of num, and store these digits in array digits. The variable num_digits will store the number of digits of num. For example, if num is assigned 14941, then after the execution of your code, num_digits will be 5 and the first five elements of digits will be 1, 4, 9, 4 and 1. The remaining elements are not used. (b) Implement the function palindromic (on the next page) as a recursive function that will check whether the digits digits[lower], digits[lower+1],..., digits[upper] form a palindromic number, so that the function call in the main function (next page) would correctly complete the program. Error handling is not required. Two marks will be deducted if your implementation of the function palindromic is not recursive. You are allowed to define new variables in main, though there exists a correct solution that does not require you to do so. #include <stdio.h> #define LEN 30 int palindromic(int digits[], int lower, int upper); int main() { int num; int digits[len]; int num_digits = 0; printf("enter a positive number: "); scanf("%d", &num); while (num!= 0) { digits[num_digits++] = num % 10; num /= 10; if (palindromic(digits, 0, num_digits-1)) printf("it is a palindromic number.\n"); 5

printf("it is not a palindromic number.\n"); return 0; int palindromic(int digits[], int lower, int upper) { if (lower >= upper) return 1; if (digits[lower] == digits[upper]) return palindromic(digits, lower+1, upper-1); return 0; 6. [11 marks] In class we learned mergesort. Part of the mergesort algorithm merges two arrays that are already sorted into one sorted array. This task is called two-way merge, as we merge two sorted arrays into one. This question asks you to implement a function that performs 3-way merge. That is, this function merges three sorted arrays (in increasing order), and stores the resulting sorted sequence in a fourth array. More precisely, implement a function whose prototype is given below: void merge_3way(int array1[], int len1, int array2[], int len2, int array3[], int len3, int array[]); In this prototype, array1, array2 and array3 are sorted arrays (in increasing order) of lengths len1, len2 and len3, respectively. This function merges them and stores the result in array array. No error handling is required; you can assume that array1, array2 and array3 are sorted and array is large enough to store the result. Do not provide a main function; implement merge_3way only. There is an extra page for your solution. void merge_3way(int array1[], int len1, int array2[], int len2, int array3[], int len3, int array[]) { int i = 0, j = 0, k = 0, l = 0; while (i < len1 && j < len2 && k < len3) { if (array1[i] <= array2[j] && array1[i] <= array3[k]) { array[l] = array1[i]; i++; 6

if (array2[j] <= array1[i] && array2[j] <= array3[k]){ array[l] = array2[j]; j++; { array[l] = array3[k]; k++; l++; while (i < len1 && j < len2) { if (array1[i] <= array2[j]) array[l++] = array1[i++]; array[l++] = array2[j++]; while (j < len2 && k < len3) { if (array2[j] <= array3[k]) array[l++] = array2[j++]; array[l++] = array3[k++]; while (i < len1 && k < len3) { if (array1[i] <= array3[k]) array[l++] = array1[i++]; array[l++] = array3[k++]; while (i < len1) array[l++] = array1[i++]; while (j < len2) array[l++] = array2[j++]; while (k < len3) array[l++] = array3[k++]; 7

8