SOFTWARE Ph.D. Qualifying Exam Fall 2017

Similar documents
SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program, which includes three function definitions, including the main function.

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

Decimal Representation

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Approximately a Test II CPSC 206

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

ESC101N: Fundamentals of Computing End-sem st semester

COMP1917 Computing 1 Written Exam Sample Questions

CSCI 2132 Final Exam Solutions

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

CS360 Midterm 1 - February 21, James S. Plank. Put all answers on the answer sheet. In all of these questions, please assume the following:

Approximately a Final Exam CPSC 206

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

Pointers. Pointer Variables. Chapter 11. Pointer Variables. Pointer Variables. Pointer Variables. Declaring Pointer Variables

Foundation Exam - Sample Problems for New Topics

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

CS 0449 Sample Midterm

CS61, Fall 2012 Section 2 Notes

EECE.2160: ECE Application Programming Fall 2017

ECE551 Midterm Version 1

ENCM 339 Fall 2017 Tutorial for Week 8

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

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

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

EECE.2160: ECE Application Programming Fall 2017

... Lecture 12. Pointers

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Lab 3. Pointers Programming Lab (Using C) XU Silei

Arrays and Pointers in C. Alan L. Cox

Dynamic memory. EECS 211 Winter 2019

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

ECE551 Midterm Version 2

Signature: ECE 551 Midterm Exam

Goals of this Lecture

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Grade Distribution. Exam 1 Exam 2. Exams 1 & 2. # of Students. Total: 17. Total: 17. Total: 17

The output will be: marks all or nothing. 1 #include <stdio.h> 2 main() { 3 int i; int j; 4 int *p; int *q; 6 p = &i; 7 q = &j; 8 i = 1;

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

Procedural programming with C

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Student Number: Computer Science 211b Final Examination. 28 April hours

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

Variation of Pointers

Array Initialization

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

ECE264 Fall 2013 Exam 3, November 20, 2013

Outline Arrays Examples of array usage Passing arrays to functions 2D arrays Strings Searching arrays Next Time. C Arrays.

CS 33. Introduction to C. Part 5. CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

BSM540 Basics of C Language

Fundamental of Programming (C)

return return else return

Arrays Arrays and pointers Loops and performance Array comparison Strings. John Edgar 2

Output of sample program: Size of a short is 2 Size of a int is 4 Size of a double is 8

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

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

CS 61c: Great Ideas in Computer Architecture

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

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

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

CSC209H1S Day Midterm Solutions Winter 2010

Contents. A Review of C language. Visual C Visual C++ 6.0

CIS 2107 Computer Systems and Low-Level Programming Fall 2010 Midterm

Dynamic Memory CMSC 104 Spring 2014, Section 02, Lecture 24 Jason Tang

ECE264 Fall 2013 Exam 2, October 24, 2013

16.216: ECE Application Programming Fall 2015 Exam 2 Solution

ECE264 Fall 2013 Exam 1, September 24, 2013

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Administrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6

ECE264 Spring 2013 Final Exam, April 30, 2013

Fundamental of Programming (C)

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CS 241 Data Organization Pointers and Arrays

15 122: Principles of Imperative Computation. Practice Exam August 4, 2015

PROGRAMMAZIONE I A.A. 2017/2018

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University

today cs3157-fall2002-sklar-lect05 1

Memory Allocation. General Questions

Lecture 04 Introduction to pointers

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

The output: The address of i is 0xbf85416c. The address of main is 0x80483e4. arrays.c. 1 #include <stdio.h> 3 int main(int argc, char **argv) 4 {

Final Intro to C Review

else return for return

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

This is CS50. Harvard University Fall Quiz 0 Answer Key

The University of Calgary. ENCM 339 Programming Fundamentals Fall 2016

Solution for Data Structure

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

20 Dynamic allocation of memory: malloc and calloc

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Transcription:

(i) (4 pts.) SOFTWARE Ph.D. Qualifying Exam Fall 2017 Consider the following C program. #include <stdio.h> #define START 2 #define LIMIT 60 #define STEP 7 #define SIZE 3 int main(void) { int i = START, j = 0; int sum = 0, count = 0; int divisors[size] = {4, 5, 7; while (i < LIMIT) { printf("%d\n", i); for (j = 0; j < SIZE; j++) { if ((i % divisors[j]) == 0) { sum += i; count++; i += STEP; printf("count = %d, sum = %d\n", count, sum); return 0; Show the complete output as it appears on standard output. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on this page and (if more space is needed) the next page. In case of an illegal dereferencing of a pointer (e.g., dereferencing of an uninitialized pointer, null pointer, or pointer that goes beyond the boundaries of an array), show all of the output from the printf calls that are executed up to the point just before the illegal pointer dereference, and then write "illegal pointer operation" on the following line.

This page is reserved as extra space for working on and writing your solution to Question (i).

(ii) (6 pts.) Consider the following C program, which consists of three function definitions including the main function. #include <stdio.h> #include <stdlib.h> struct data { int v; struct data *next; ; void setup(struct data **h, int *a, int len) { struct data *p = NULL; struct data *prev = NULL; struct data *start = NULL; int i = 0; for (i = 0; i < len; i++) { p = malloc(sizeof(struct data)); p->v = a[i]; if (prev == NULL) { start = p; else { prev->next = p; prev = p; p->next = start; (*h) = start; int f(struct data *h, int limit) { if (limit <= 0) { return h->v; else { limit -= h->v; printf("[%d / %d]", h->v, limit); return h->v + f(h->next, limit); int main(void) { int values[] = {9, 3, 8, 3, 5, 5, 2; const int length1 = 7, length2 = 4, limit1 = 15, limit2 = 30; struct data *h = NULL; int result = 0; setup(&h, values, length1); result = f(h, limit1); printf("\nresult = %d\n", result); setup(&h, values, length2); result = f(h, limit2); printf("\nresult = %d\n", result); return 1;

Show the complete output as it appears on standard output. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on this page and (if more space is needed) the previous page. In case of an illegal dereferencing of a pointer (e.g., dereferencing of an uninitialized pointer, null pointer, or pointer that goes beyond the boundaries of an array), show all of the output from the printf calls that are executed up to the point just before the illegal pointer dereference, and then write "illegal pointer operation" on the following line.

(iii) (5 pts.) Consider the following C program. #include <stdio.h> int main(void) { char c1 = 'x'; char *p1; char c2 = 'd'; char *p2 = &c2; *p2 = c2 + 1; c1 = *p2 + 1; p1 = &c1; printf("c1 = %c, c2 = %c, *p1 = %c, *p2 = %c\n", c1, c2, *p1, *p2); return 0; Suppose that each character occupies one byte of memory. Suppose also that the value assigned to c1 is stored in (hexadecimal) address D45 and the value assigned to c2 is stored in address CC7. PART A: Show the output of this program exactly as it appears on standard output. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on this page and (if more space is needed) the next page. In case of an illegal dereferencing of a pointer (e.g., dereferencing of an uninitialized pointer, null pointer, or pointer that goes beyond the boundaries of an array), show all of the output from the printf calls that are executed up to the point just before the illegal pointer dereference, and then write "illegal pointer operation" on the following line. PART B: a) What value is represented by &c1? b) What value is represented by &c2? c) What value is assigned to p1? d) What value is assigned to p2? Show your work and your solution for this problem (both Parts A and B) only on this page, and (if more space is needed) the next page.

This page is reserved as extra space for working on and writing your solution to Question (iii).

(iv) (5 pts.) Consider the following function prototype and associated header comment. /********************************************************************* Perform a specified operation on a given string s, and display the result on standard output. The name of the specified operation is specified by the string pointed to by the "operation" argument. The following are the valid (case-sensitive) operation names: "test_numeric", "flip", and "capitalize". If the specified operation name is not one of these valid names or if the string s is an empty string (contains no non-null characters), then print a meaningful error message to standard error. Otherwise, print to standard output the result of applying the specified operation to the given string. The result of the "test_numeric" operation is the string "true" if s consists only of decimal numbers (that is, it contains only the characters 0, 1,, 9 ); the result is the string "false" otherwise. No modification is made to the string s in this case, only the true/false result is printed to standard output. The result of the flip operation is to reverse the characters in the string (for example, abcd becomes ( dcba ). The result of the "capitalize" operation is to convert all lower case alphabetic letters to their corresponding upper case letters (for example c becomes C ); characters that are not lower case letters are unchanged. *********************************************************************/ void stringops(char *s, char *operation); Note that no error checking is required in this function beyond what is stated in the header comment. Part A: Consider the C program below, which illustrates correct usage of the function stringops. int main(void) { char s1[] = "377966"; char s2[] = "35xyx48"; char s3[] = "A;;_bcD"; stringops(s1, "test_numeric"); stringops(s2, "test_numeric"); stringops(s1, "flip"); stringops(s2, "flip"); stringops(s2, "capitalize"); stringops(s3, "capitalize"); Show the complete output of this program as it appears on standard output.

Part B: Develop a complete C code implementation of the function stringops. In your implementation, make appropriate use of features that are provided through the standard library header file <string.h>. Show your work and your solution for this problem (both Parts A and B) only on this page, the previous page, and (if more space is needed) the next page.

This page is reserved as extra space for working on and writing your solution to Question (iv).

Software Qualifying Exam Solutions Fall 2017 Dept. of ECE, University of Maryland, College Park 9/10/2017 Problem 1: 2 9 16 23 30 37 44 51 58 count = 3, sum = 90 Problem 2: [9 / 6][3 / 3][8 / -5] result = 23 [9 / 21][3 / 18][8 / 10][3 / 7][9 / -2] result = 35 Problem 3: PART A: c1 = f, c2 = e, *p1 = f, *p2 = e PART B: (a) 0xD45, (b) 0xCC7, (c) 0xD45, (d) 0xCC7 Problem 4: PART A: true false 669773 84xyx53 84XYX53 A;;_BCD

PART B: void stringops(char *s, char *operation) { int length = strlen(s); int i = 0, j = 0; char tmp = '\0'; if (length == 0) { fprintf(stderr, "empty string\n"); return; if (strcmp(operation, "test_numeric") == 0) { for (i = 0; i < length; i++) { if (!isdigit(s[i])) { printf("false\n"); return; printf("true\n"); return; else if (strcmp(operation, "flip") == 0) { for (i = 0, j = (length - 1); i < j; i++, j--) { tmp = s[i]; s[i] = s[j]; s[j] = tmp; printf("%s\n", s); return; else if (strcmp(operation, "capitalize") == 0) { for (i = 0; i < length; i++) { s[i] = toupper(s[i]); printf("%s\n", s); return; else { fprintf(stderr, "invalid stringops operation\n");