CS 1713 Introduction to Programming II

Similar documents
CS 1713 Introduction to Programming II

CS Operating system

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

C & Data Structures syllabus

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

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

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

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

CS 0449 Sample Midterm

Question 1. [15 marks]

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

COMP2521. Generic ADTs in C

These problems are provided to you as a guide for practice. The questions cover important concepts covered in class.

ECE264 Spring 2013 Exam 1, February 14, 2013

EE 312 Fall 2017 Midterm 1 October 12, 2017

CS 223: Data Structures and Programming Techniques. Exam 2

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

CSE 303 Midterm Exam

CSE 333 Midterm Exam 5/10/13

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

Array Initialization

Midterm Exam 2 Solutions, C programming

CSE 333 Autumn 2014 Midterm Key

Today s Learning Objectives

***PRACTICE EXAM 02 for*** CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Actual exam scheduled for: 11/18/2009

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

CSE 333 Midterm Exam Sample Solution 5/10/13

Largest Online Community of VU Students

EECE.2160: ECE Application Programming Fall 2017

CSE 333 Midterm Exam 7/29/13

CS 455 Midterm Exam 2 Spring 2017 [Bono] Tuesday, April 4, 2017

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

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

COMP 524 Spring 2018 Midterm Thursday, March 1

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Midterm Exam #2 Review. CS 2308 :: Spring 2016 Molly O'Neil

CS Operating system Spring Final -- May 8, You have 120 min. Good Luck!

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

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

Department of Electrical and Computer Engineering The University of Texas at Austin

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

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

PRINCIPLES OF OPERATING SYSTEMS

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

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

15-122: Principles of Imperative Computation, Spring Written Homework 12. Due: Sunday 15 th April, 2018 by 10pm. Name: Andrew ID: Section:

Arrays and Pointers in C. Alan L. Cox

One of Mike s early tests cases involved the following code, which produced the error message about something being really wrong:

DS Assignment I. 1. Set a pointer by name first and last to point to the first element and last element of the list respectively.

CSE 333 Autumn 2013 Midterm

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Midterm #2 CISC 220, Winter 2008

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

Computer Architecture I Mid-Term I

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Review: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc

CS61, Fall 2012 Section 2 Notes

CSE 333 Midterm Exam 2/14/14

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Unit 14. Passing Arrays & C++ Strings

EE 472 Embedded Systems. Name solutions. Instructions:

Computer Science Foundation Exam

NAME: March 4. and ask me. To pace yourself, you should allow on more than 1 minute/point. For

Pointers. Pointer References

C programming for beginners

Supporting Class / C++ Lecture Notes

THE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

CMSC 212 Midterm #2 (Fall 2005) ANSWERS AND GRADING KEY

CS 237 Meeting 18 10/22/12

COMP 2001/2401 Test #1 [out of 80 marks]

Worksheet 11 Multi Dimensional Array and String

ECE 250 / CPS 250 Computer Architecture. C Programming

CS 2301 Exam 3 B-Term 2011

ECE 250 / CS 250 Computer Architecture. C Programming

ECE264 Spring 2013 Final Exam, April 30, 2013

Strings. Compare these program fragments:

Computer Science Foundation Exam

just a ((somewhat) safer) dialect.

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

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CS Operating system Fall Midterm I -- Oct 5, 2017 You have 75 min. Good Luck!

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Answer all questions. Write your answers only in the space provided. Full marks = 50

Exercise Session 2 Simon Gerber

Data Structure (CS301)

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Kurt Schmidt. October 30, 2018

CS 113 MIDTERM EXAM 2 SPRING 2013

CS , Spring 2009 Exam 2

High-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet

CS 237 Meeting 19 10/24/12

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

Final CSE 131B Spring 2005

Transcription:

CS 1713 Introduction to Programming II Spring 2014 Midterm 2 -- April 24, 2014 You have 75 min. Good luck. You can use the 2-page C reference card posted in the class web page. Name: Score:./100 Background Survey (5pt bonus credit) A. Please complete the below table for the computer-programming-related courses that you have taken before Spring 2014. Programming courses CS 1063 Intro to Comp Prog I (in Java) CS 1713 Intro to Comp Prog II (in C) TAKEN AT UTSA, (Yes / No) If you have taken equivalent courses from a different school, please give the school name and the programming language used. (Say NO if this is the first time you are taking it) B. How would you evaluate your programming skills and background? (circle one) 5: excellent, developed some programs, received A in all Intro programming courses. 4: good, developed a few programs, received B in Intro programming courses. 3: fair, developed very simple programs, received C in Intro programming courses 2: beginner, have not take any programming course, never wrote any program. 1: What is "programming"? C. Do you think you had sufficient background to take cs1713? Definitely. Somewhat. I don't know. Not really. Definitely not. D. If you feel that you had (or did not have) sufficient background, what should be done (both on your part and in the curriculum) so that you can be successful in cs1713? (Please comment) 1

Name: 1. (20 pt) Trace the following program, show how values change in the memory, and give the output. #include <stdio.h> main() int x, y, z[3]=8,5,4, *p1, *p2; p1 = &x; *p1 = 9; p2 = z + 2; name Add ress x 12 y 16 z[0] 20 z[1] 24 z[2] 28 MEMORY Content/Value y = *p2--; *(p2-1) = 7; *++p2 = 3; printf("%d %d %d %d %d \n", x, y, z[0], z[1], z[2]); y = f1(&x, *p1, p2-1, &p2); printf("%d %d %d %d %d \n", x, y, z[0], p1, p2 ); printf("%d %d \n", *p1, *p2); p1 32 p2 36 100 a 104 b 108 c 112 d 116 x 120 y 124 int f1(int *a, int b, int *c, int **d) int x=5, y=7; 128 OUTPUT: *a = y % x; *d = c-1; **d = *a + b; return **d + *a; 2

Name: 2. (20pt) You are asked to implement the following function using pointers and pointer arithmetic int substrindex(char *str, char *substr); which returns -1 if substr is not in str; otherwise, it returns the index value for the first appearance of substr in str. You can assume that both str and substr are NULL terminated strings. For example, substrindex("abcabcdef", "abc") returns 0, substrindex("abcabcdef", "abcde") returns 3, substrindex("abc", "xy") returns -1 int substrindex(char *str, char *substr) /* FOR FULL CREDIT DON'T USE ARRAY NOTATION! * IF YOU SOLVE IT USING ARRAY NOTAION, YOUR MAX WILL BE 10Pt */ 3

Name:. 3. (20pt) Develop a function char *my_concat(char *s1, char *s2); that concatenates two strings by joining them end to end. This function should dynamically allocate the memory for the new string and copy the original strings end to end into the new string. For example, after calling s = my_concat("abc", "DE"); s should be pointing to a new string "ABCDE". If needed, you can use the standard string functions from <string.h> library. char *my_concat(char *s1, char *s2) 4

Name:... 4. (20pt) Suppose we have the following structure and variable declarations. typedef struct int x; int y; mydatat; mydatat a, *b, **c; a) (2pt) Set all the fields of variable a to 0. b) (3pt) Let b = &a; Then through pointer b set all the fields to 1. c) (5pt) Allocate an array of 50 pointers to mydatat and save the address of that array into c. d) (5pt) Suppose the memory allocation in part (c) is successful and c is now the array of 50 pointers to mydatat. Now, dynamically allocate an actual mydatat structure for each element of the array c and save its address in c[i]. e) (5pt) Free all the memory that you allocated in part (c) and part (d). 5

Name:... 5. (20pt) We maintain two files to store the IDs and homework grades of the students in two sections. At the end of the semester, I need to merge these two files into a single file. Each student has nine homework grades after his/her ID, but the number of students in a file could be anything! Also the IDs in the input files are already sorted. Now you are asked to write a program that takes three file names as command line arguments, and merges the data in the first two files into the third file while keeping the IDs sorted. Here is an example. Suppose we have the following two files: section1.txt and section2.txt 12 3 5 2 5 3 5 2 5 3 18 5 2 5 3 3 5 2 5 3 25 3 5 2 5 3 2 5 3 5 When we execute your prog as follows > prog section1.txt section1.txt section-all.txt it should print out the following lines into section-all.txt 12 3 5 2 5 3 5 2 5 3 14 3 5 2 5 3 5 2 5 3 17 5 2 5 3 3 5 2 5 3 18 5 2 5 3 3 5 2 5 3 22 3 5 2 5 3 2 5 3 5 25 3 5 2 5 3 2 5 3 5 30 5 3 3 5 2 5 3 5 2 14 3 5 2 5 3 5 2 5 3 17 5 2 5 3 3 5 2 5 3 22 3 5 2 5 3 2 5 3 5 30 5 3 3 5 2 5 3 5 2 Implement your program by completing the following program also use the next page. #include <stdio.h> int main(int argc, char *argv[]) FILE *infp1, *infp2, *outfp; int id1, id2, /* if you need, declare more var */ if (argc!=4) printf("you need to give three file names\n"); return -1; if ( (infp1=fopen(, )) == NULL (infp2=fopen(, )) == NULL (outfp=fopen(, )) == NULL ) printf("some files cannot be opened\n"); return -1; 6

/* Name: */ 7