CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 6

Similar documents
CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 7

[6 marks] All parts of this question assume the following C statement. Parts (b) through (e) assume a variable called ptrs.

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm)

CSC209H1S Day Midterm Solutions Winter 2010

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Student Number: Instructor: Reid Section: L0201 (12:10-1:00pm)

Jacobs University Bremen February 7 th, 2017 Dr. Kinga Lipskoch. Practice Sheet. First Name:... Last Name:... Matriculation Number:...

Pointers, Arrays, and Strings. CS449 Spring 2016

25.2 Opening and Closing a File

CSC209H Lecture 4. Dan Zingaro. January 28, 2015

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

ECE551 Midterm Version 2

ECE551 Midterm Version 1

CSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS

Getting Started. Project 1

csc/cpe 357 C Quiz Archive

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

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

CSE 374 Midterm Exam 11/2/15. Name Id #

UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus APRIL 2012 EXAMINATIONS

Student Number: Lab day:

Chapter 5, Standard I/O. Not UNIX... C standard (library) Why? UNIX programmed in C stdio is very UNIX based

Princeton University Computer Science 217: Introduction to Programming Systems. Modularity design principles

UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus DECEMBER 2017 EXAMINATIONS. CSC 209H1F Liu, Reid 3 hours. No Examination Aids

Lecture 05 Pointers ctd..

File and Console I/O. CS449 Spring 2016

C Programming Language Review and Dissection III

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

SYSTEM AND LIBRARY CALLS. UNIX Programming 2015 Fall by Euiseong Seo

CSE 303 Midterm Exam

CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science

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

File and Console I/O. CS449 Fall 2017

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.

Shells & Shell Programming (Part B)

File IO and command line input CSE 2451

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

Input/Output and the Operating Systems

CSE374 Winter 2016, Midterm Examination February 8, 2016 Please do not turn the page until the bell rings.

Shell programming. Introduction to Operating Systems

Assignment clarifications

Princeton University Computer Science 217: Introduction to Programming Systems. Modularity design principles

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number:

CSE 374 Midterm Exam Sample Solution 2/11/13. Question 1. (8 points) What does each of the following bash commands do?

CMPE-013/L. File I/O. File Processing. Gabriel Hugh Elkaim Winter File Processing. Files and Streams. Outline.

University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman

Principles of C and Memory Management

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

Programming in C. 4. Misc. Library Features, Gotchas, Hints and Tips. Dr. Neel Krishnaswami University of Cambridge

University of Calgary Department of Electrical and Computer Engineering ENCM 339 Lecture Section 01 Instructor: Steve Norman

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

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

Arrays and Strings. CS449 Fall 2017

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

C-Refresher: Session 10 Disk IO

ECE551 Midterm Version 1

ECE 551D Spring 2018 Midterm Exam

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

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Procedural Programming

File I/O. Preprocessor Macros

Princeton University Computer Science 217: Introduction to Programming Systems. Modules and Interfaces

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

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number:

CSE 374 Midterm Exam 11/2/15 Sample Solution. Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:

CS201 Lecture 2 GDB, The C Library

CSE 303 Winter 2008 Midterm Key

File (1A) Young Won Lim 11/25/16

File Handling. Reference:

CSC209H1F Test 2 Solutions Fall 2009

MARKS: Q1 /20 /15 /15 /15 / 5 /30 TOTAL: /100

structs as arguments

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Algorithms & Programming. Midterm Examination # 2. Student Name: Student ID Number: Duration of examination:

Please wait to turn the page until everyone is told to begin.

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Fundamentals of Programming & Procedural Programming

Characters and Strings

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

Midterm Review. What makes a file executable? Dr. Jack Lange 2/10/16. In UNIX: Everything is a file

System Programming. Standard Input/Output Library (Cont d)

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number:

Shell Programming (bash)

File Access. FILE * fopen(const char *name, const char * mode);

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CP2 Revision. theme: file access and unix programs

Consider the following program.

Signature: ECE 551 Midterm Exam

C Programming 1. File Access. Goutam Biswas. Lect 29

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Shells and Shell Programming

CSC209 Review. Yeah! We made it!

by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM

UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus APRIL 2016 EXAMINATIONS. CSC 209H1S Michelle Craig, David Liu 3 hours

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

CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia

Transcription:

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0101 Instructor: Reid Do not turn this page until you have received the signal to start. (Please fill out the identification section above, write your name on the back of the test, and read the instructions below.) Good Luck! This midterm consists of 4 questions on 6 pages (including this one). When you receive the signal to start, please make sure that your copy is complete. Comments are not required except where indicated, although they may help us mark your answers. They may also get you part marks if you can t figure out how to write the code. If you use any space for rough work, indicate clearly what you want marked. # 1: / 6 # 2: / 7 # 3: / 7 # 4: / 5 TOTAL: /25 Total Pages = 6 Page 1 cont d...

Question 1. Part (a) [5 marks] [6 marks] The C program below has errors. When run, the output was: 123456789Anwar Patel: Anwar Patel completed 10 courses with CGPA: 3.700000 123456789Anwar Patel: Anwar Patel completed 10 courses with CGPA: 3.700000 Make changes by printing neatly directly on the code (or beside it) so that it will work as intended. Change as little as necessary. The problem is not the math in the calculation. #include <stdio.h> #include <string.h> struct student { char id[9]; char name[20]; double CGPA; int courses; ; void print(struct student s) { printf("%s: %s\t completed %d courses with CGPA: %f\n", s.id, s.name, s.courses, s.cgpa); void complete_course(struct student s, double mark) { /* calculate the new CGPA by weighting the old CGPA appropriately */ double new_cgpa = ((s.cgpa * s.courses) + mark ) / (float) (s.courses + 1); s.cgpa = new_cgpa; s.courses++; int main() { /* create a record for Anwar Patel (student number 123456789) who has a CGPA of 3.7 on his first 10 courses. */ struct student s1; strncpy(s1.id, "123456789", 9); strncpy(s1.name, "Anwar Patel", strlen("anwar Patel")); s1.cgpa = 3.7; s1.courses = 10; print(s1); complete_course(s1, 4.0); /* Anwar just got a 4.0 in CSC209! */ print(s1); return 0; Page 2 of 6 cont d...

Part (b) [1 mark] Would your code above still work if the name of the student was Clement Schiano de Collela? Explain why or why not and any additional changes to the code that would be required. Question 2. [7 marks] In each subquestion below, fill in the box with the declaration for an appropriate mystery function so that the following code would compile without error. Each subquestion is independent. Part (a) [3 marks] char ** students; int class_size = 100; if(mystery1(class_size, &students) > 0) printf("there were errors\n"); Part (b) [4 marks] char ** authors; char * most_famous; int books[4] = {4,12,16,22; int * p = books; most_famous = mystery2(books[0], &p, *authors); Page 3 of 6 cont d...

Question 3. [7 marks] Write a shell program that you might use to clean up your CSC209 directory. The script takes any number of filenames as command line arguments and moves all of the files with names ending in.sh to a subdirectory called scripts. If this subdirectory doesn t already exist, your script should create it. If your script is called with an argument that doesn t correspond to an existing regular file, you should just ignore that argument. You do not need to worry about further error checking. For example, you may assume that any regular files corresponding to the commandline arguments are readable. Page 4 of 6 cont d...

Question 4. [5 marks] Consider the C program below with an array of strings names. Write a C function zero strings that will set each name to an empty string and return the number of names that were changed in the process. Inside the box below, fill in the call to your function inside main. You need to determine the appropriate signature for your function. int main() { int n = XXXXX NOT SHOWN ON TEST XXXX char ** names = malloc(n * sizeof(char*)); int i; for (i = 0; i < n; i++ ) { names[i] = malloc(namesize); /* code not shown where some of names get set to non-empty strings */ /* call your zero_strings function and print the return value */ return 0; Page 5 of 6 cont d...

C function prototypes and structs: int fclose(file *stream) char *fgets(char *s, int n, FILE *stream) FILE *fopen(const char *file, const char *mode) size t fread(void *ptr, size t size, size t nmemb, FILE *stream); int fseek(file *stream, long offset, int whence) size t fwrite(const void *ptr, size t size, size t nmemb, FILE *stream); char *index(const char *s, int c) void perror(const char *s) int sprintf(char *s, const char *format,...) char *strchr(const char *s, int c) size t strlen(const char *s) char *strncat(char *dest, const char *src, size t n) int strncmp(const char *s1, const char *s2, size t n) char *strncpy(char *dest, const char *src, size t n) char *strrchr(const char *s, int c) char *strstr(const char *haystack, const char *needle) Shell comparison operators Shell Description -d filename Exists as a directory -f filename Exists as a regular file. -r filename Exists as a readable file -w filename Exists as a writable file. -x filename Exists as an executable file. -z string True if empty string str1 = str2 True if str1 equals str2 str1!= str2 True if str1 not equal to str2 int1 -eq int2 True if int1 equals int2 -ne, -gt, -lt, -le For numbers!=, >, >=, <, <= For strings -a, -o And, or. expr match STRING REGEXP expr ARG1 + ARG2 Useful Unix programs for shell programs: head, tail cat, cut, wc, grep, sort, sort -n (for numerical sorting), Print your name in this box. Page 6 of 6 End of Examination