CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

Similar documents
Computer Organization & Systems Exam I Example Questions

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

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Bits, Bytes and Integers

Bits, Bytes, and Integers Part 2

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

CS , Fall 2001 Exam 1

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

CSE 351 Midterm - Winter 2015 Solutions

Fundamentals of Programming

Introduction to Computer Science Midterm 3 Fall, Points

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

CS , Fall 2002 Exam 1

CS 354 Midterm 1a, 33.33% Monday, October 9th, 2000 Solution

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

15-213, Fall 2007 Midterm Exam

BASIC ELEMENTS OF A COMPUTER PROGRAM

DEPARTMENT OF MATHS, MJ COLLEGE

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Pointer Casts and Data Accesses

EE 312 Fall 2017 Midterm 1 October 12, 2017

Data Types. Data Types. Integer Types. Signed Integers

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

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

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

CMSC 313 Spring 2010 Exam 3 May 17, 2010

Question Points Score Total: 100

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

Fundamental of Programming (C)

15-213/18-243, Fall 2010 Exam 1 - Version A

Operators in C. Staff Incharge: S.Sasirekha

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

Reserved Words and Identifiers

Computer Systems Programming. Practice Midterm. Name:

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Data Representation and Storage. Some definitions (in C)

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

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Integers II. CSE 351 Autumn 2018

CSE 351 Midterm - Winter 2017

CSC201, SECTION 002, Fall 2000: Homework Assignment #2

Integers. Today. Next time. ! Numeric Encodings! Programming Implications! Basic operations. ! Floats

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Computer Architecture I Midterm I

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Operators & Expressions

Integers. Dr. Steve Goddard Giving credit where credit is due

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

CS242 COMPUTER PROGRAMMING

CS , Fall 2007 Exam 1

NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313.

Chapter 4 Homework Individual/Team (1-2 Persons) Assignment 15 Points

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng

Survey. Motivation 29.5 / 40 class is required

CDA 3103 Computer Organization Exam 1 (Sep. 22th, 2014)

8*4 + 4 = 36 each int is 4 bytes

A flow chart is a graphical or symbolic representation of a process.

Arrays and Pointers (part 1)

CSE 351 Midterm - Winter 2015

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Computer Systems CEN591(502) Fall 2011

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Lecture 03 Bits, Bytes and Data Types

Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integer Representation Floating point Representation Other data types

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

ECE264 Fall 2013 Exam 3, November 20, 2013

Binary Representations and Arithmetic

Unit 3. Operators. School of Science and Technology INTRODUCTION

Representing and Manipulating Integers. Jo, Heeseung

Integers Sep 3, 2002

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

Systems 1. Integers. Unsigned & Twoʼs complement. Addition, negation, multiplication

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Chapter 2: Introduction to C++

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

Bits, Bytes, and Integers

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

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

CS16 Exam #1 7/17/ Minutes 100 Points total

Lecture 5-6: Bits, Bytes, and Integers

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

Integer Encoding and Manipulation

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Multidimension array, array of strings

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

CS61c Summer 2014 Midterm Exam

Systems Programming and Computer Architecture ( )

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

The type of all data used in a C++ program must be specified

Q1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

Arithmetic and Bitwise Operations on Binary Data

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Lecture 17 Bit Operations

Chapter 2 THE STRUCTURE OF C LANGUAGE

Transcription:

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009 Name Score UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. For short answer questions your answer should be short, clear and to the point, not long and rambling. c. For True / False question, write the word TRUE or FALSE; do not use the letters T and F. Using T and F will result in a 2-point deduction. d. There are no intentional syntax errors in any code provided with this exam. If you think you see an error that would affect your answer, please bring it to my attention. e. You may assume that any necessary.h files have been #included where necessary. 1

True / False (2 points each) 1. When an array is passed to a function a copy of the array elements is made for the function to manipulate. 2. The sizeof( ) operator is used to determine the number of bytes required to store a program object. 3. The compiler will detect any attempt to use an invalid array index. 4. If p is a pointer, then the expression p + 1 adds the size of p's type to p. 5. For any two's complement integer, -X = ~X + 1 6. Both scanf( ) and fscanf( ) can be used to read user input from the standard input. 7. The size of a struct is at least as big as the sum of the sizes of its members. 8. In C, functions are uniquely identified by their name, so no two.c files may have functions with the same name. 9. The string "Frodo LIVES!" requires 12 bytes of memory. 10. In C, all functions have global scope. 2

Short Answer 11. (4 points) Write two C statements that assign the value 42 to the 56th element of an array of integers named ages. a. b. 12. (4 points) If not used carefully, C library functions for manipulating strings such as strcpy( ) and strccat( ) can lead to subtle errors or program termination (segmentation fault). Explain why this is so. 13. (5 points) Give a brief description of what this function accomplishes on the lines provided. DO NOT describe each line of code. void mystery( double *dp, int n) int k, N = n - 1; for (k = 0; k < n / 2; --N, ++k) double temp = *(dp + N); *(dp + N) = *(dp + k); *(dp + k) = temp; 3

14. (4 points ) Examine the code in the boxes, then answer the questions below /** main.c **/ extern int randomint; static void printrandoms( int n) int k; for (k = 0; k < n; k++) getrandomint( 12345 ); printf("%d\n", randomint); /** random.c **/ int randomint; void getrandomint( int max ) static long lastrandom = 100001; lastrandom = (lastrandom * 125) % 2796203; randomint = (lastrandom % max) + 1; int main( ) printrandoms( 5 ); return 0; a. What is the scope of randomint? b. What is the lifetime of randomint? c. What is the lifetime of lastrandom? d. What is the scope of lastrandom? 4

15. (30 points - 2 points for each blank) Events at a gymnastics meet (high bar, rings, floor exercise, etc) are scored from 0.0 to 10.0 by each of 10 judges. The gymnast's score for the event is calculated by removing the highest and lowest of the judge's scores and then averaging the remaining 8 scores. Fill in the blanks for the functions below that calculate a gymnast's score for an event. #define NR_SCORES 10 /* Calculates and returns a gymnast's score for one event ** from an array of scores provided by the user ** This function calls helper function SumScores( ) and ** GetHiLowScores( ) which are found on the next page */ Gymnastics ( float ) float eventscore, hiscore, lowscore; eventscore = SumScores( scores ); GetHiLowScores(scores,, ); eventscore -= ; eventscore -= ; eventscore /= ; return eventscore; 5

/* Continuation from previous page ** Sums the values of an array of gymnasts scores */ SumScores( float ) float sum = 0; int s; for (s = 0; s < NR_SCORES; s++) sum += ; return sum; /* "returns" the highest and lowest score via paremeters from an array ** of gymnastic scores which are known to be in the range 0.0-10.0 */ GetHiLowScores (float scores[ ], hiscore, lowscore) float hi = -1.0, low = 11.0; int s; for (s = 0; s < NR_SCORES; s++) if ( scores[s] > hi ) hi = scores[s]; if (scores[s] < low ) low = scores[s]; = hi; = low; 6

16. (6 points) Convert the following values as indicated a. Binary 0110 0101 to hex b. Hex 0x2B to decimal c. Binary 0011 0110 to decimal 17. ( 4 points) Perform two's complement addition on each pair of 8-bit binary numbers. In each case, indicate whether overflow has occurred. 1101 0011 + 0110 0001 = Overflow? 0110 0110 + 1000 0011 = Overflow? 18. ( 8 points ) Consider a 5-bit two s complement representation. Fill in the empty boxes in the following table. Addition and subtraction should be performed based on the rules for 5-bit, two s complement arithmetic Number Decimal Representation Bit Representation N / A -2 N / A 9 N / A 1 0011 N / A 0 1100 TMax TMin 7

19. ( 10 points ) Assuming 8-bit integers using two's complement representation, let int A have the value represented by the bit pattern 0110 1100, and unsigned int B have the value represented by the bit pattern 1000 0110. Fill in the empty boxes in the table below. Expression Value (A & 0xF0) >> 2 (hex) A 0x3 (hex) ((A ^ B) << 3) && 0x7 (decimal) ~B B (hex) (A & B) >> 2 (hex) 20. ( 5 points ) Assuming 32-bit integers using two's complement representation, and given the declarations on the left, determine whether each statement in the table is always true. Circle YES if the statement is always true, circle NO if the statement is not always true. Statement Always True? int x = foo( ); int y = bar( ); unsigned int ux = x; unsigned in uy = y; x > 0 => x * 2 > 0 YES NO uy >> 3 == uy / 8 YES NO ux >= 0 YES NO x & 7 == 7 (x<<30) < 0 YES NO x > 0 && y > 0 => x + y > 0 YES NO 8