University of California San Diego Department of Electrical and Computer Engineering. ECE 15 Final Exam
|
|
- Laurence Heath
- 6 years ago
- Views:
Transcription
1 University of California San Diego Department of Electrical and Computer Engineering ECE 15 Final Exam Tuesday, March 21, :00 p.m. 6:00 p.m. Room 109, Pepper Canyon Hall Name Class Account: ee15w Student ID Number Signature Grading 1. 6 points INSTRUCTIONS The exam consists of six problems worth a total of 100 points. Write your answers in the spaces provided. If you need extra space, please use the back of the previous page. Partial credit will be given only for substantial progress. Good luck! 2. 9 points points points points points TOTAL
2 Problem 1 (6 points) Consider the following simple function: int isequal(int x, int y) if (x == y) return 1; else return 0; Rewrite this function below without using the keywords if and else. You are also required to use the keyword return exactly once. int isequal(int x, int y) Hint: Use the ternary conditional operator? :.
3 Problem 2 (9 points) Consider the following simple function: void foo(int n) if (n %2 == 0) printf("2"); else if (n %3 == 0) printf("3"); else if (n %5 == 0) printf("5"); else if (n %7 == 0) printf("7"); else printf("no divisors!"); Rewrite this function below without using the keywords else or switch. You also cannot use the keyword if more than once in your source code. void foo(int n) Hint: Store the numbers 2, 3, 5, 7 in an array, and process this array in a loop.
4 Problem 3 (12 points) Consider the following C program that contains global, local, and static variables: #include <stdio.h> #define N 5 int i,j; /* global variables */ /* Forward function declarations */ void f1(int); int *f2(int *); int f3(int); int main() int a = N; int myarray[n] = ; int *p = myarray; for (i = 0; i < N; i++) int j = i % 2; /* local variable */ if (i == 0) f1(a); else if (j == 0) p = f2(p); else if (j == 1) a = f3(a); *p = a; // most of the action happens here! for (j = 0; j < N; j++) printf("%d ", myarray[j]); printf("\n"); return 0; void f1(int a) a += ++j; int *f2(int *a) return a += j++; int f3(int a) static int i = 0; return a+i++;
5 You should assume that the program compiles and runs successfully. Your task is to determine the output of the program. Write your answers in the space provided. Explanations are not required.
6 Problem 4 (20 points) In this problem, you are given several exercises, each containing a short C program. You should assume that the program compiles and runs successfully. Your task is to determine, in each case, the output of the program. Write your answers in the space provided. Explanations are not required. a. #include <stdio.h> int main() int x,y,z; x = y = z = 1; ++x && ++y ++z; printf("a. x = %d, y = %d, z = %d\n", x,y,z); x = y = z = 1; x += y += z; printf("b.? = %d, ", (x < y)? x++ : y++); printf("x = %d, y = %d\n", x,y); x = 1; y = 2; z = 3; printf("c.? = %s\n", (z > y > x)? "True" : "False"); return 0; The program output is: a. x =, y =, z = b.? =, x =, y = c.? =
7 b. #include <stdio.h> void foo(int, int *, int *); int main() int a[3] = 1729,42,0; int *ptr = a; int x = 10, z = 12; foo(x, ptr, &z); printf("x = %d, z = %d\n", x,z); printf("array elements: %d, %d, %d\n", a[0],a[1],a[2]); return 0; void foo(int x, int *y, int *z) printf("x = %d, z = %d\n", x,*z); x++; (*z)++; printf("x = %d, z = %d\n", x,*z); x = *(y++); *z = *(y++); (*y)++; The program output is: x =, z = x =, z = x =, z = Array elements:
8 c. #include <stdio.h> int main() int i,j; int M[5][5] = 0; for (i = 0; i < 5; i++) for (j = 0; j < 5; j++) if ((i*j) % 2) *(*(M+i)+j) = i*j; *((*M+i)+j) = i*j; for (i = 0; i < 5; i++) for (j = 0; j < 5; j++) printf("%d ", M[i][j]); if (j == 4) printf("\n"); return 0; The program output is:
9 Problem 5 (18 points) Write a C program, called anagrams.c, that prompts the user to enter two strings of characters S 1 and S 2, and then determines whether these strings are anagrams of each other. The strings S 1 and S 2 are said to be anagrams of each other if the characters in S 1 can be re-arranged to produce S 2. For example, the words student and stunted are anagrams, as are the words admirer and married. On the other hand, the words cats and stack are not anagrams. Clearly, a necessary condition for S 1 and S 2 to be anagrams is that they have the same length. Note that the strings S 1 and S 2 do not have to consist of letters. For example, ! and 9876!54321 are valid anagrams. On the other hand, the words Admirer and Married are not anagrams, since our definition of anagrams is case sensitive. Write a C program that prompts the user to enter two strings (terminated by the newline character \n), determines whether these strings are anagrams of each other, and reports the results to the user. Here are several sample runs of this program: /home/userxyz/ece15/final> anagrams Enter the first string: ! Enter the second string: 9876!54321 Your strings " !" and "9876!54321" are anagrams! /home/userxyz/ece15/final> anagrams Enter the first string: admirer Enter the second string: married Your strings "admirer" and "married" are anagrams! /home/userxyz/ece15/final> anagrams Enter the first string: Admirer Enter the second string: Married Your strings "Admirer" and "Married" are NOT anagrams! /home/userxyz/ece15/final> anagrams Enter the first string: cats Enter the second string: stack Your strings "cats" and "stack" are NOT anagrams! Hint: For each character in S 1, count how many times this character appears in S 1 and S 2, respectively. The strings are anagrams if and only if these counts coincide for every character of S 1. Notes: You can assume that the user input to your program is always valid. That is, when prompted, the user always enters a string (without whitespace) terminated by the newline character \n. You can also assume that the longest string the user will enter does not exceed MAXLENGTH characters, where MAXLENGTH is a symbolic constant.
10 #include <stdio.h> #include <string.h> #define MAXLENGTH 80 int main() return 0;
11 Problem 6 (35 points) Your goal in this problem is to write a C program, called life.c, that implements the Game of Life invented by John H. Conway in For the purposes of this problem, the Game of Life is played on an n n two-dimensional square grid (or board, or matrix, or array) of cells, where n is a variable the program should read from its input. Each cell can be in one of two possible states: alive or dead. Every cell interacts with its 8 neighbors (or 5 neighbors, or 3 neighbors, if the cell is close to an edge or a corner of the grid). The neighbors of a cell grid[i, j] are the cells that are horizontally, vertically, or diagonally adjacent to the cell grid[i, j]. Note that grid[i, j] is not considered its own neighbor. The game begins with an initial configuration, called the seed, that specifies the state of every cell in the grid. The program should read this initial configuration from its input. The game then evolves in a sequence of generations according to the following rules: Any live cell with 2 or 3 live neighbors lives on to the next generation. Any live cell with more than 3 live neighbors dies (by overcrowding), and any live cell with less than 2 live neighbors also dies (from loneliness). Any dead cell with exactly 3 live neighbors becomes a live cell in the next generation (by reproduction). Any dead cell with more than 3 or less than 3 live neighbors remains dead. The initial seed is considered the 0-th generation. The first generation is created by applying the above rules simultaneously to every cell in the seed array. The rules then continue to be applied repeatedly to create further generations, where each generation is completely determined by the previous one. Your C program should read its input from the file life input.dat. The first line of the input file contains a positive integer that specifies the dimension n of the n n grid on which the game is played. The second line contains another positive integer that specifies the number of generations you are required to compute. The following n lines specify the initial seed configuration of the grid, where a dead cell is given as 0 and a live cell is given as 1. Here is a sample input file: You can assume that the input file will conform to the specifications above. You can also assume that the required number of generations (second line of input) will be at most However, you should not assume anything regarding the size n of the grid (first line), except that allocating a few n n arrays of int will not exhaust the available memory. After reading the input file, the C program should iteratively compute the required number of generations and print them to stdout, starting
12 with the 0-th generation (read from the input file). Here is a sample run of the program, assuming the input file life input.dat is exactly as shown on the previous page: /home/userxyz/ece15/final> life Generation 0: ---** *-*-- -*-----*- -**---*-- --*-* *----- Generation 1: ---*** ***--- -**--***- -** *** * *----- Generation 2: ----* *-*--- -*---**-- *-----*-- -*-* **---- Generation 3: ----* * *** **-- ***--**-- --*** ***---- Generation 4: ---** *-*-- -*-----*- -**---*-- --*-* *----- Generation 5: ---*** ***--- -**--***- -** *** * *----- Note that in the program output above dead cells are represented by - while live cells are represented by * (also note that, in this example, the generations repeat in a cycle starting with the 4-th one).
13 a. Provided below is part of the source code that implements the C program you are asked to write. This part contains all the global variable(s), all the forward function declarations, and the complete implementation of the function main(). #include <stdio.h> #include <stdlib.h> FILE *input; // // int **alloc int matrix(int n); void read int matrix(file *input, int **grid, int n); void print int matrix(int **grid, int n); void copy int matrix(int **from, int **to, int n); int inbounds(int i, int j, int n); int new state(int **grid, int i, int j, int n); void new generation(int **grid, int n); int main() int **grid; // int n,generations,i; // // if ((input = fopen("life input.dat","r")) == NULL) return 1; // fscanf(input,"%d",&n); fscanf(input,"%d",& generations); // grid = alloc int matrix(n); read int matrix(input,grid,n); // printf("generation 0:\n"); print int matrix(grid,n); // for (i = 1; i <= generations; i++) new generation(grid,n); printf("\ngeneration %d:\n",i); print int matrix(grid,n); return 0; Add comments above, where indicated by // or anywhere else you wish, in order to show your understanding of what the various pieces of code do. In particular, indicate which variables are local and which are global, and for pointer variables state their type.
14 b. The function main() calls the function read int matrix(input,grid,n), which reads the initial seed configuration of the grid from the file pointed to by input into a twodimensional square array of int, of a given size n by n. The function main() also calls the function print int matrix(grid,n) that prints the current state of the grid array (using * for a live cell and - for a dead cell) to stdout. Implement these functions below. void read int matrix(file *input, int **grid, int n) void print int matrix(int **grid, int n) Notes: Both functions should assume that the two-dimensional int array grid is already allocated. No need to worry about memory allocation here. Comments are not required, but could help you receive partial credit: programs that are not correct and are difficult to understand will receive zero credit, even if partially correct.
15 c. The function main() calls the function alloc int matrix(n). The latter function dynamically allocates a memory structure that can serve as a two-dimensional array of int of size n by n, and then returns a pointer to this structure. Implement this function below. int **alloc int matrix(int n) Notes: You can call either malloc or calloc standard library functions. The corresponding header file <stdlib.h> is already included in part (a). Do not forget to check for the situation where the requested block of memory is not available, and then deal with this situation if it arises.
16 d. We will need the functions inbounds(i,j,n) and copy int matrix(from,to,n) later in this program. Let us implement these functions here. The function inbounds(i,j,n) simply checks if the pair i,j is a valid index for a twodimensional array of size n by n. This function returns 1 (True) if i,j is a valid index and 0 (False) otherwise. The function copy int matrix(from,to,n) simply copies a twodimensional array of int of size n by n from one place (pointed to by from) to another place (pointed to by to). Implement the two functions below. int inbounds(int i, int j, int n) void copy int matrix(int **from, int **to, int n)
17 e. Implement the function new state(grid,i,j,n). This function receives as arguments (a pointer to) a two-dimensional array grid, a pair of integers i,j that is assumed to be a valid index for the array, and an integer n that specifies the size of the array. The function uses the current cell states stored in the array grid to compute the state of the cell grid[i][j] in the next generation. This new state of grid[i][j], namely dead (0) or alive (1), is returned by new state(grid,i,j,n). Implement this function below. int new state(int **grid, int i, int j, int n) Notes: This is where the rules of life and/or death in the next generation are implemented. See the description of the Game of Life at the beginning of this problem. To correctly count the number of live neighbors, it would be useful to call inbounds. Also note that a cell is not a neighbor of itself.
18 f. Now implement the last and most important function new generation(grid,n). This function receives as arguments (a pointer to) a two-dimensional array grid and an integer n that specifies its size. It computes the new state (the state in the next generation) for each cell in the grid, by invoking the function new state(grid,i,j,n). It then overwrites the values of all the cells in the grid with their state in the next generation. void new generation(int **grid, int n) Notes: This function should also call copy int matrix() and alloc int matrix(). It would be helpful to understand why this is so before proceeding. The function needs to dynamically allocate memory to itself. But beware of memory leaks over many generations! There are two ways to proceed. One option is to free the memory every time before the function terminates. A better option is to allocate the memory only once only the first time the function is called (hint: use static variables).
University of California San Diego Department of Electrical and Computer Engineering. ECE 15 Midterm Exam
University of California San Diego Department of Electrical and Computer Engineering ECE 15 Midterm Exam Tuesday, February 17, 2015 12:30 p.m. 1:50 p.m. Room 109, Pepper Canyon Hall Name Class Account:
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationUNIT 9C Randomness in Computation: Cellular Automata Principles of Computing, Carnegie Mellon University
UNIT 9C Randomness in Computation: Cellular Automata 1 Exam locations: Announcements 2:30 Exam: Sections A, B, C, D, E go to Rashid (GHC 4401) Sections F, G go to PH 125C. 3:30 Exam: All sections go to
More informationCOP 3223 Introduction to Programming with C - Study Union - Spring 2018
COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More informationEECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017
EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017 Name: Lecture time (circle 1): 8-8:50 (Sec. 201) 12-12:50 (Sec. 203) 1-1:50 (Sec. 202) For this exam, you may use only one 8.5
More information16.216: ECE Application Programming Fall 2011
16.216: ECE Application Programming Fall 2011 Exam 2 Solution 1. (24 points, 6 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling
More informationEECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution
EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 16, 2013 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Korst, J.
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 14, 2012 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Li, M. Sadoghi,
More informationQ1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10
EECE.2160: ECE Application Programming Spring 2016 Exam 1 February 19, 2016 Name: Section (circle 1): 201 (8-8:50, P. Li) 202 (12-12:50, M. Geiger) For this exam, you may use only one 8.5 x 11 double-sided
More informationDepartment of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04
Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Topic: Arrays and Strings Practice Sheet #04 Date: 24-01-2017 Instructions: For the questions consisting code segments,
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationESC101N: Fundamentals of Computing End-sem st semester
ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.
More informationCS , Fall 2003 Exam 2
Andrew login ID: Full Name: CS 15-213, Fall 2003 Exam 2 November 18, 2003 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write
More informationSignature: ECE 551 Midterm Exam
Name: ECE 551 Midterm Exam NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual work.
More informationCS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015
CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:
More information2-D Arrays. Of course, to set each grid location to 0, we have to use a loop structure as follows (assume i and j are already defined):
2-D Arrays We define 2-D arrays similar to 1-D arrays, except that we must specify the size of the second dimension. The following is how we can declare a 5x5 int array: int grid[5][5]; Essentially, this
More informationECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.
ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.
More informationLab Exam 1 D [1 mark] Give an example of a sample input which would make the function
CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:
More informationECE15: Lab #4. Problem 1. University of California San Diego
University of California San Diego ECE15: Lab #4 This lab is a cumulative wrap-up assignment for the entire course. As such, it relates to the material covered in Lecture Units 1 5 and 7 9 in class. Here
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 7 January Takako Nemoto (JAIST) 7 January 1 / 13 Usage of pointers #include int sato = 178; int sanaka = 175; int masaki = 179; int *isako, *hiroko;
More informationDynamic Memory Allocation
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility, there are four library routines known as memory management
More informationTecniche di Progettazione: Design Patterns
Tecniche di Progettazione: Design Patterns GoF: Visitor 1 Polymorphism reminded: overriding and dynamic binding 2 Polymorphism reminded: overloading and static dispatch 3 Polymorphism reminded: overloading
More informationEECE.2160: ECE Application Programming Fall 2017
EECE.2160: ECE Application Programming Fall 2017 1. (34 points) Structures Exam 3 Solution a. (14 points) Show the output of the short program below exactly as it will appear on the screen. Be sure to
More informationMake sure the version number is marked on your scantron sheet. This is Version 1
Last Name First Name McGill ID Make sure the version number is marked on your scantron sheet. This is Version 1 McGill University COMP 208 -- Computers in Engineering Mid-Term Examination Tuesday, March
More informationEECE.2160: ECE Application Programming Fall 2017
EECE.2160: ECE Application Programming Fall 2017 1. (35 points) Functions Exam 2 Solution a. (15 points) Show the output of the short program below exactly as it will appear on the screen. Be sure to clearly
More informationCSE 333 Lecture 2 - arrays, memory, pointers
CSE 333 Lecture 2 - arrays, memory, pointers Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia 1 ex0 was due 30 minutes ago! Solution posted after class -
More informationAssignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)
Assignment 4 Aggregate Objects, Command-Line Arguments, ArrayLists COMP-202B, Winter 2011, All Sections Due: Tuesday, March 22, 2011 (13:00) You MUST do this assignment individually and, unless otherwise
More informationCSE 303 Midterm Exam
CSE 303 Midterm Exam October 29, 2008 Name Sample Solution The exam is closed book, except that you may have a single page of hand written notes for reference. If you don t remember the details of how
More information//If target was found, then //found == true and a[index] == target.
230 CHAPTER 5 Arrays //If target was found, then //found == true and a[index] == target. } if (found) where = index; return found; 20. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 21. int a[4][5]; int index1, index2;
More informationHigh Performance Programming Programming in C part 1
High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the
More informationMemory Management. a C view. Dr Alun Moon KF5010. Computer Science. Dr Alun Moon (Computer Science) Memory Management KF / 24
Memory Management a C view Dr Alun Moon Computer Science KF5010 Dr Alun Moon (Computer Science) Memory Management KF5010 1 / 24 The Von Neumann model Memory Architecture One continuous address space Program
More informationECE264 Spring 2013 Final Exam, April 30, 2013
ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationFinal 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
Faculty of Computer Science Page 1 of 21 Final Exam Term: Fall 2018 (Sep4-Dec4) Student ID Information Last name: First name: Student ID #: CS.Dal.Ca userid: Course ID: CSCI 2132 Course Title: Instructor:
More informationMidterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017
Section 1: Multiple choice (select any that apply) - 20 points 01. Representing 10 using the 4 byte unsigned integer encoding and using 4 byte two s complements encoding yields the same bit pattern. (a)
More informationName: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015
CMSC 202 Section 06 Fall 2015 Computer Science II Midterm Exam I Name: Username: Score Max Section: (check one) 07 - Sushant Athley, Tuesday 11:30am 08 - Aishwarya Bhide, Thursday 11:30am 09 - Phanindra
More informationQ1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10
16.216: ECE Application Programming Spring 2015 Exam 1 February 23, 2015 Name: ID #: For this exam, you may use only one 8.5 x 11 double-sided page of notes. All electronic devices (e.g., calculators,
More informationThe 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;
p. 2 of 9 Q1. [5 marks] The following program compiles and runs with no problems. Indicate what the output of the program is going to be (no explanation necessary). 1 #include 2 main() { 3 int
More informationContent. In this chapter, you will learn:
ARRAYS & HEAP Content In this chapter, you will learn: To introduce the array data structure To understand the use of arrays To understand how to define an array, initialize an array and refer to individual
More informationQ1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100
ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam Three November 20 th 2013 Name: Q1: /8 Q2: /30 Q3: /30 Q4: /32 Total: /100 1/10 For functional call related questions, let s assume
More informationQuestion 1. [15 marks]
Note to Students: This file contains sample solutions to the term test together with the marking scheme and comments for each question. Please read the solutions and the marking schemes and comments carefully.
More informationVariation of Pointers
Variation of Pointers A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before
More informationArrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.
Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example
More informationComputer Science Foundation Exam
Computer Science Foundation Exam December 16, 2016 Section I A DATA STRUCTURES NO books, notes, or calculators may be used, and you must work entirely on your own. SOLUTION Question # Max Pts Category
More informationLecture 04 Introduction to pointers
Lecture 04 Introduction to pointers A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct access to a memory location through its address. A variable
More informationUnited States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017
United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes
More informationForest Fire Simulation Using Multiple Processes and Pipes
CEG 434/634: Concurrent Software Design (Fall 2002) PROGRAMMING ASSIGNMENT I Forest Fire Simulation Using Multiple Processes and Pipes Distribution date: October 1 (Tuesday) Due Date: October 15 (Tuesday)
More informationLab Exam 1 D [1 mark] Give an example of a sample input which would make the function
Grade: / 20 Lab Exam 1 D500 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return 0? Answer: Anything that is not a floating point number such as 4.567 or
More informationCS2 Practical 1 CS2A 22/09/2004
CS2 Practical 1 Basic Java Programming The purpose of this practical is to re-enforce your Java programming abilities. The practical is based on material covered in CS1. It consists of ten simple programming
More informationComputer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];
Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data
More informationPDS Class Test 2. Room Sections No of students
PDS Class Test 2 Date: October 27, 2016 Time: 7pm to 8pm Marks: 20 (Weightage 50%) Room Sections No of students V1 Section 8 (All) Section 9 (AE,AG,BT,CE, CH,CS,CY,EC,EE,EX) V2 Section 9 (Rest, if not
More informationThe University of Calgary. ENCM 339 Programming Fundamentals Fall 2016
The University of Calgary ENCM 339 Programming Fundamentals Fall 2016 Instructors: S. Norman, and M. Moussavi Wednesday, November 2 7:00 to 9:00 PM The First Letter of your Last Name:! Please Print your
More informationLecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch
Lecture 3 CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions Review Conditions: if( ) / else switch Loops: for( ) do...while( ) while( )... 1 Examples Display the first 10
More informationLecture07: Strings, Variable Scope, Memory Model 4/8/2013
Lecture07: Strings, Variable Scope, Memory Model 4/8/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Outline Review pointers New: Strings New: Variable Scope (global vs. local variables)
More informationCSE 374 Midterm Exam 2/6/17 Sample Solution. Question 1. (12 points, 4 each) Suppose we have the following files and directories:
Question 1. (12 points, 4 each) Suppose we have the following files and directories: $ pwd /home/user $ ls -l -rw-r--r-- 1 user uw 10 Feb 4 15:49 combine.sh drwxr-xr-x 2 user uw 2 Feb 4 15:51 hws -rw-r--r--
More informationLecture 5: Multidimensional Arrays. Wednesday, 11 February 2009
Lecture 5: Multidimensional Arrays CS209 : Algorithms and Scientific Computing Wednesday, 11 February 2009 CS209 Lecture 5: Multidimensional Arrays 1/20 In today lecture... 1 Let s recall... 2 Multidimensional
More informationCSE 333 Lecture 3 - arrays, memory, pointers
CSE 333 Lecture 3 - arrays, memory, pointers Steve Gribble Department of Computer Science & Engineering University of Washington Administrivia HW 0.5 (a 4-question survey) - out today, due Monday HW 1.0
More informationECE15: Lab #2. Problem 1. University of California San Diego
University of California San Diego ECE15: Lab #2 This lab relates to the material covered in Lecture Units 4 and 5 in class, and in Chapters 3 and 5 of the Kernighan and Ritchie textbook. Similar material
More informationDEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING PROGRAMMING TECHNIQUES I EE271
UNIVERSITY OF SWAZILAND FACULTY OF SCIENCE AND ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING MAIN EXAMINATION: 2015 TITLE OF PAPER: COURSE NUMBER: TIME ALLOWED: PROGRAMMING TECHNIQUES
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 20, 2011 6:15 p.m. 8:00 p.m. (105 minutes) Examiners: J. Anderson, T. Fairgrieve,
More informationLOÏC CAPPANERA. 1. Memory management The variables involved in a C program can be stored either statically or dynamically.
C PROGRAMMING LANGUAGE. MEMORY MANAGEMENT. APPLICATION TO ARRAYS. CAAM 519, CHAPTER 7 This chapter aims to describe how a programmer manages the allocation of memory associated to the various variables
More informationESC 101N: Fundmentals of Computing ( IInd Semester) Mid Sem II Examination PM, Monday 7th March, 2011
ESC 101N: Fundmentals of Computing (2010-11-IInd Semester) Mid Sem II Examination 3.30-4.30PM, Monday 7th March, 2011 Instructions 1. Write your name, roll number and section below and also in the space
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationQ1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10
EECE.2160: ECE Application Programming Spring 2017 Exam 2 March 29, 2017 Name: Section (circle 1): 201 (Dr. Li, MWF 8-8:50) 202 (Dr. Geiger, MWF 12-12:50) For this exam, you may use only one 8.5 x 11 double-sided
More informationECE264 Fall 2013 Exam 1, September 24, 2013
ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationOutline Arrays Examples of array usage Passing arrays to functions 2D arrays Strings Searching arrays Next Time. C Arrays.
CS 2060 Week 5 1 Arrays Arrays Initializing arrays 2 Examples of array usage 3 Passing arrays to functions 4 2D arrays 2D arrays 5 Strings Using character arrays to store and manipulate strings 6 Searching
More informationChapter 2 (Dynamic variable (i.e. pointer), Static variable)
Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= #
More informationDynamic Memory Allocation (and Multi-Dimensional Arrays)
Dynamic Memory Allocation (and Multi-Dimensional Arrays) Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan
More informationMidterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.
Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem
More informationDynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1
Dynamic Memory Dynamic Memory Allocation Strings September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Pointer arithmetic If we know the address of the first element of an array, we can compute the addresses
More informationProgramming Language A
Programming Language A Takako Nemoto (JAIST) 22 October Takako Nemoto (JAIST) 22 October 1 / 28 From Homework 2 Homework 2 1 Write a program calculate something with at least two integer-valued inputs,
More informationWarmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2
Warmup January 9th, 2018 What is the value of the following C expression? 8*9 % 10/ 2 Warmup January 11th, 2018 What is the value of the following C expression? ( -42 3!= 3) && ( -3 < -2 < -1) Warmup January
More informationSOFTWARE Ph.D. Qualifying Exam Fall 2017
(i) (4 pts.) SOFTWARE Ph.D. Qualifying Exam Fall 2017 Consider the following C program. #include #define START 2 #define LIMIT 60 #define STEP 7 #define SIZE 3 int main(void) { int i = START,
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 15, 2014 9:30 a.m. 12:00 p.m. (150 minutes) Examiners: B. Li, J. Rose, H. Timorabadi,
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationLesson 7. Reading and Writing a.k.a. Input and Output
Lesson 7 Reading and Writing a.k.a. Input and Output Escape sequences for printf strings Source: http://en.wikipedia.org/wiki/escape_sequences_in_c Escape sequences for printf strings Why do we need escape
More informationEECE.2160: ECE Application Programming Spring 2018 Exam 3 May 10, 2018
EECE.2160: ECE Application Programming Spring 2018 Exam 3 May 10, 2018 Name: Lecture time (circle 1): 8-8:50 (Sec. 201) 12-12:50 (Sec. 202) For this exam, you may use only one 8.5 x 11 double-sided page
More information#3. (Recursion) Write a recursive function to compute f(x) = f(x - 1) + f(x - 2) with f(0) = 0 and f(1) = 1.
EGN 3210 Sample Test 2 Dr. Fernando Gonzalez NAME S.S.# #1. (Functions) Write a function that receives 3 integers, and returns the value of the largest one through the function name. #2. (Functions) What
More informationCSE351 Winter 2016, Final Examination March 16, 2016
CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,
More informationProgramming Assignment #4 Arrays and Pointers
CS-2301, System Programming for Non-majors, B-term 2013 Project 4 (30 points) Assigned: Tuesday, November 19, 2013 Due: Tuesday, November 26, Noon Abstract Programming Assignment #4 Arrays and Pointers
More informationArrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]
(November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I
More informationFORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. The declaration below declares three pointer variables of type pointer to double that is
More informationECE551 Midterm Version 2
Name: ECE551 Midterm Version 2 NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual
More informationDynamic memory allocation
Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes
More informationArrays and Pointers in C. Alan L. Cox
Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using
More informationCSE 374 Midterm Exam 11/2/15. Name Id #
Name Id # There are 8 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationClass Information ANNOUCEMENTS
Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to
More informationEngineering program development 6. Edited by Péter Vass
Engineering program development 6 Edited by Péter Vass Variables When we define a variable with its identifier (name) and type in the source code, it will result the reservation of some memory space for
More informationCSE 333 Midterm Exam 7/25/16 Sample Solution. Question 1. (10 points) Preprocessor. Suppose we have the following two files:
Question 1. (10 points) Preprocessor. Suppose we have the following two files: defs.h: #define DIV(a,b) a / b #define INCDIV(c,d) DIV(c + 1, d + 1) main.c: #include #include "defs.h" int main()
More informationCS 241 Data Organization using C Project 3: Tron Spring 2017
CS 241 Data Organization using C Project 3: Tron Spring 2017 Instructor: Joel Castellanos e-mail: joel@unm.edu Web: http://cs.unm.edu/~joel/ 4/29/2017 Tron Spring 2017: Project Outline (1 of 3) 1) The
More informationFinal Intro to C Review
Final Exam Content: Final Intro to C Review - Pass by reference Functions - General Syntax - Structures - Recursion(maybe?) - Programming by nature is cumulative so any past material is up for grabs as
More informationch = argv[i][++j]; /* why does ++j but j++ does not? */
CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and
More information15-122: Principles of Imperative Computation, Spring Written Homework 12. Due: Sunday 15 th April, 2018 by 10pm. Name: Andrew ID: Section:
15-122: Principles of Imperative Computation, Spring 2018 Written Homework 12 Due: Sunday 15 th April, 2018 by 10pm Name: Andrew ID: Section: This written homework provides practice with C features such
More informationECE264 Spring 2013 Exam 1, February 14, 2013
ECE264 Spring 2013 Exam 1, February 14, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationProcedural programming with C
Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical
More informationLanguage Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science
Language Design COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Language Design Issues Syntax: how programs look Names and reserved words Instruction
More informationCSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads
CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads Overview This homework is due by 11:59:59 PM on Tuesday, April 10,
More information