CGS 3460 Summer 07 Midterm Exam

Similar documents
UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

C Program Development and Debugging under Unix SEEM 3460

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;

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

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

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

Practice problems Set 2

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

Introduction to Computer Systems. Exam 2. April 11, Notes and calculators are permitted, but not computers.

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

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

Storage class and Scope:

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

Programming in C - Part 2

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

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

AMCAT Automata Coding Sample Questions And Answers

Subject: Fundamental of Computer Programming 2068

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

C Programming Review CSC 4320/6320

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

Final CSE 131B Spring 2004

Write a C program using arrays and structure

Goals of this Lecture

1. Basics 1. Write a program to add any two-given integer. Algorithm Code 2. Write a program to calculate the volume of a given sphere Formula Code

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

UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04

The C standard library

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

CSC209H1S Day Midterm Solutions Winter 2010

Personal SE. Functions, Arrays, Strings & Command Line Arguments

Topic 6: A Quick Intro To C

Compiling and Running a C Program in Unix

CS 101, Spring 2016 March 22nd Exam 2

Programming in C Quick Start! Biostatistics 615 Lecture 4

CIS 190: C/C++ Programming. Lecture 2 Pointers and More

PROGRAMMAZIONE I A.A. 2017/2018

Functions. Arash Rafiey. September 26, 2017

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

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

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Question 2. [2 points] True False By default, structures are passed-by-reference.

Problem: Read 10 numbers from the keyboard and store them

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

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

CpSc 1111 Lab 9 2-D Arrays

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

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

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

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

Arrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)

Principles of C and Memory Management

Chapter 11 Introduction to Programming in C

Functions. Systems Programming Concepts

CSE 333 Autumn 2013 Midterm

Array Initialization

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Creating, Compiling and Executing

Intermediate Programming, Spring 2017*

Final CSE 131B Spring 2005

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

Lecture07: Strings, Variable Scope, Memory Model 4/8/2013

ECE 15B COMPUTER ORGANIZATION

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

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Lecture 02 C FUNDAMENTALS

Introduction: The Unix shell and C programming

Question 2. [2 points] Which of the following is a correct statement to obtain user input? (Assume that fleems is an int variable.

{C} Programming. Part 1/2 Basics Variables, Conditions, Loops, Arrays, Pointer basics

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

CS 223: Data Structures and Programming Techniques. Exam 2

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

UNIVERSITY OF TORONTO SCARBOROUGH Computer and Mathematical Sciences. APRIL 2016 EXAMINATIONS CSCB09H3S Software Tools & Systems Programming

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

CS 101, Spring 2014 April 1st Exam 2 Question 1. [3 points] What output is printed by the following code?

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

Computer Programming. The greatest gift you can give another is the purity of your attention. Richard Moss

Arrays and Pointers in C. Alan L. Cox

Intermediate Programming, Spring 2017*

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

ARRAYS(II Unit Part II)

BSM540 Basics of C Language

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

CS270 Homework 5 (HW5)

Why arrays? To group distinct variables of the same type under a single name.

CSE 333 Midterm Exam 5/10/13

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C


Introduction to C Language (M3-R )

CS 0449 Sample Midterm

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Programming in C Lab

Transcription:

Short Answer 3 Points Each 1. What would the unix command gcc somefile.c -o someotherfile.exe do? 2. Name two basic data types in C. 3. A pointer data type holds what piece of information? 4. This key word is used to create a variable local to a function that won t die when the function returns. In other words, it can only be accessed in the function it is declared in, and once initialized, its values remains for the life of the program. 5. What would be the value of x after the following statement? float x = 3.4 * (1 + 1) - 0.7; 6. What would be the value of x after the following statement? int x = 3 * 5 % 4 + 4; 7. What would the following evaluate to? (4 > 8 && 30 < 10) 5!= 9 8. What would the following evaluate to? 4 > 8 && (30 < 10 5!= 9) 9. Given the following structure definition, give TWO different ways to initialize the month field to April, the day field to 20, and the year to 1972. typedef struct char month[10]; int day; int year; Date; 1

CODE SNIPPET 1 CODE SNIPPET 2 CODE SNIPPET 3 int x = 7; if(x > 8) printf("peas "); printf("and Carrots\n"); double x = 72.5; if(x > 90) printf("a\n"); else if(x > 80) printf("b\n"); else if(x > 70) printf("c\n"); else if(x > 60) printf("d\n"); else printf("better luck next semester\n"); int i = 1; for(i = 1; i < 9; i *= 2) printf("%i\n", i); printf("is your letter grade\n"); 10. What does CODE SNIPPET 1 print to the screen? 11. What does CODE SNIPPET 2 print to the screen? 12. What does CODE SNIPPET 3 print to the screen? 2

CODE SNIPPET 4 CODE SNIPPET 5 CODE SNIPPET 6 int i; int sum = 0; int N = 10; i = 1; while(i < 10) sum += i; i = i + 2; printf("%i\n", sum); int a[10], i; for(i = 0; i < 10; i++) a[i] = 2 * i; printf("%i\n", a[7]); int c[10], i, s; int a[10] = 2, 5, 3, 7, 3; int b[10] = [0] = 1, [4] = 5, [6] = 8, [9] = 23; for(i = 0; i < 10; i++) c[i] = a[i] + b[i]; s = c[4] + c[9]; printf("%i\n", s); 13. What would be the output of CODE SNIPPET 4? 14. Write a program that does the same thing as CODE SNIPPET 4 but uses a for loop instead of a while loop. 15. What would be the output of CODE SNIPPET 5? 16. What would be the output of CODE SNIPPET 6? 3

#include <string.h> CODE SNIPPET 7 CODE SNIPPET 8 CODE SNIPPET 9 void FUBAR(char str1[], char str2[]) int j; for(j = 0; j < strlen(str1); j++) str2[j] = str1[strlen(str1) - 1 - j]; str2[j] = '\0'; int main() char s[50] = "I AM"; char t[50] = "CAPTAIN PLANET"; printf("%s %s\n", s, t); FUBAR(s, t); printf("%s %s\n", s, t); 1. 2. int V = 4; 3. void foo(int W) 4. 5. int X = 3; 6. V = 7; 7. W = 7; 8. X = 7; 9. Y = 7; 10. Z = 7; 11. 12. int main() 13. 14. int Y; 15. int Z; 16. foo(z); 17. V = 7; 18. W = 7; 19. X = 7; 20. Y = 7; 21. Z = 7; 22. 23. void YOOHOO(int x, int y) int temp = x; x = y; y = temp; int main() int a = 7, b = 12; printf("%i, %i\n", a, b); YOOHOO(a, b); printf("%i, %i\n", a, b); 17. For CODE SNIPPET 7, describe in English what the function FUBAR does? 18. What would be the output of CODE SNIPPET 7? 19. Which lines in CODE SNIPPET 8 would cause compilation errors(note the numbers to the left are line numbers for identification, not part of the code.)? 20. What would be the output for CODE SNIPPET 9? 4

CODE SNIPPET 10 1. 2. #include <string.h> 3. main() 4. 5. /*This program is supposed to prompt for a string and make all lower case 6. characters there upper case equivalent you don't need to worry about how 7. it works for these questions, just find the errors, use the comments to 8. figure out how to fix them*/ 9. /*only one character needs to be added/removed/changed for 10. each error */ 11. char str[50]; 12. int i; 13. print("enter a string: "); 14. scanf("%s", &str); 15. for(i = 0; i < strlen(str); i++) 16. 17. //if str[i] is between 'a' and 'z' then set it to str[i] - 'a' + 'A' 18. //otherwise set it to str[i] 19. str[i] = (str[i] >= 'a' && str[i] <= 'z')? str[i] - 'a' + 'A' str[i]; 20. 21. printf("the modified string is %s\n", str); 22. return 0 23. 21. When you try to compile CODE SNIPPET 10, you get the error main.c:19: error: parse error before "str" Identify the error and what needs to be done to fix it. 22. You also get the error main.c:23: error: parse error before '' token Identify the error and what needs to be done to fix it. 23. Assuming you fixed those errors correctly, when you recompile, you get the error Undefined first referenced symbol in file print /var/tmp//cccdmvlb.o ld: fatal: Symbol referencing errors. No output written to a.out collect2: ld returned 1 exit status 5

Identify the error and what needs to be done to fix it. 6

Coding 15.5 Points Each Choose 2 of the 4 questions below and write the C code to create a program that meets the specified criteria. 24. Write a program that prompts the user for three integers. The program then calls a function called sortthem. sortthem takes three parameters. (The parameter type is for you to decide.) The return type of sortthem is void. When the function returns, the three arguments are in ascending order, so the first argument is the smallest, the second argument is the second smallest and the last argument the largest. After it returns, main then prints out the variables in sorted order. 7

25. Write a program that prompts the user for an integer and then prints out a multiplication table for the integers from 1 to N where N is the number entered. A multiplication is a table where the rows and columns are numbered from 1 to 5 and the intersection of the i th row and the j th column is i * j. So if the user entered 5, your program would print out: 1 2 3 4 5 1 1 2 3 4 5 2 2 4 6 8 10 3 3 6 9 12 15 4 4 8 12 16 20 5 5 10 15 20 25 The spacing should be such that each number takes up 8 spaces. Don t forget to put an extra space at the intersection of the header row and header column (i.e. the first cell in your table).. 8

26. Write a program that prompts the user for an unsigned integer. It then takes that number and prints out every other digit. So if the user enters 123456, the output would be 135. If the user entered 5788743 the output would be 5873. Notice it starts with the first digit and skips every other digit after that. You may not use the string library or sprintf. You may assume you have access to the following functions. unsigned length(unsigned x); - returns the number of digits in x unsigned power(unsigned a, unsigned b); - returns a raised to the b th power (a b ). 9

27. Write a program that prompts the user for 100 floating point numbers. (You may assume the user will input the correct data.). After the user enters all of the data, the program then prints out, the minimum value entered, the maximum value entered, then the mean and variance of all of the values entered. Recall that for N numbers, x 1, x 2,, x N: Mean N N x i AND = i = 1 Var N = i = 1 2 ( x Mean) i N 10