University of Maryland College Park Dept of Computer Science CMSC106 Fall 2013 Midterm I Key

Similar documents
University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

University of Maryland College Park Dept of Computer Science

COS 126 MIDTERM 1, FALL

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

COS 126 General Computer Science Spring Midterm 1

ESC 101N: Fundmentals of Computing ( IInd Semester) Mid Sem II Examination PM, Monday 7th March, 2011

University of California San Diego Department of Electrical and Computer Engineering. ECE 15 Midterm Exam

16.216: ECE Application Programming Fall 2011

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

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

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Control Flow, Functions and Basic Linkage

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Problem Score Max Score 1 Syntax directed translation & type

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5)

COS 126 General Computer Science Fall Midterm 1

ECE 15 Fall 15 Midterm Solutions

ITEC114 Structured Programming Midterm Exam, Spring 2015/ April Instructor: Akile Oday Research Assistant: Mohammed Abubakar SOLUTIONS

16.216: ECE Application Programming Fall 2015 Exam 1 Solution

Hacking C Code - Local Machine

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

Programming Language A

ECE15: Introduction to Computer Programming Using the C Language. Lecture Unit 4: Flow of Control

"'"' .;, b) F or ( c = l ; c <= 10,"' c++ ) X { JJ. ~. Computer Programming I COME Midterm Examination. Fall November 2016

Introduction: The Unix shell and C programming

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

DECISION CONTROL AND LOOPING STATEMENTS

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

UIC. C Programming Primer. Bharathidasan University

Introduction. Pretest and Posttest Loops. Basic Loop Structures ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

ECE 15 Fall 16 Midterm Solutions

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

EECE.2160: ECE Application Programming Spring 2018

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

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CS302: Self Check Quiz 2

Computer Science 217 Final Exam January 25, :30-4:30pm

CMSC 330, Fall 2018 Midterm 1

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

1. The Mac Environment in SIE 1222

CSE 303, Winter 2007, Midterm Examination 9 February Please do not turn the page until everyone is ready.

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

EECE.2160: ECE Application Programming Fall 2017

Approximately a Final Exam CPSC 206

16.216: ECE Application Programming Fall 2013

CMSC 104 -Lecture 9 John Y. Park, adapted by C Grasso

ECE 15 Fall 15 Final Solutions

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

Subject: PIC Chapter 2.

Engineering 12 - Spring, 1998

DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING PROGRAMMING TECHNIQUES I EE271

1. The keyword main in C language is used for

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

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

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

CS 101 Spring 2007 Midterm 2 Name: ID:

CpSc 1111 Lab 5 Formatting and Flow Control

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.

CMSC330 Spring 2014 Midterm #2. Score 1 OCaml types & type

Chapter 11 Introduction to Programming in C

1. The Mac Environment in Sierra Hall 1242

CMSC 330, Fall 2018 Midterm 1

COS 126 General Computer Science Spring Written Exam 1

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

Programming Language A

16.216: ECE Application Programming Fall 2011

Chapter 11 Introduction to Programming in C

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -CONTROL FLOW : LOOP- SPRING 2015, SEON-JU AHN, CNU EE

Decision Making and Loops

Programming and Data Structures Mid-Semester - Solutions to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

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

Introduction to Computer Methods Midterm Examination Fall Term 2002 October 29, Open book, notes and calculator Time allowed: 50 minutes

Arithmetic Expressions Lesson #1 Outline

Control Structure: Selection

Chapter 13 Control Structures

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

CMSC 330 Exam #2 Fall 2008

CSE 303 Midterm Exam

ESC101N: Fundamentals of Computing End-sem st semester

Chapter 11 Introduction to Programming in C

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

Week 1 Questions Question Options Answer & Explanation A. 10 B. 20 C. 21 D. 11. A. 97 B. 98 C. 99 D. a

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow

Couple Notes about Boolean Expressions in C

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

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

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

CS 1301 Exam 3 Fall 2014

Class Information ANNOUCEMENTS

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

Fundamental of Programming (C)

COS 126 Midterm 1 Written Exam Fall 2011

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

Chapter 11 Introduction to Programming in C

Transcription:

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2013 Midterm I Key Last Name (PRINT): First Name (PRINT): University Directory ID (e.g., umcpturtle) I pledge on my honor that I have not given or received any unauthorized assistance on this examination. Your signature: Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 50 minutes exam. Please use a pencil to complete the exam. WRITE NEATLY. You don t need to use meaningful variable names; however, we expect good indentation. Grader Use Only #1 Problem 1 (Miscellaneous) (40) #2 Problem 2 (Conditionals) (20) #3 Problem 3 (Loops) (20) #4 Problem 4 (Loops) (20) Total Total (100) (100) 1

Problem #1 (40 pts) 1. (2 pts) Circle those identifiers considered valid in C? a. phone b. Lauren c. 17cat d. --age e. System### f. Sounds12 a., b. f 2. (2 pts) Is the following an infinite loop? Briefly explain (yes or no answers will receive no credit). while(10 == 0) { printf( Here\n ); No 3. (2 pts) The body of a do while will be executed: a. At least three times b. At least twice c. More than three times d. Never e. None of the above e. 4. (2 pts) In a for loop statement curly brackets are not required if we are executing: a. Only one statement b. Two statements c. Three statements d. None of the above a 5. (2 pts) How many values can you represent with 5 bits? 32 6. (2 pts) Write a Unix command that will copy the file data.in present in the directory /system to your home directory. cp /system/data.in ~ 7. (2 pts) Write a Unix command that will compile the program my_test.c. gcc my_test.c 2

8. (2 pts) Which of the following prints the % symbol? a. printf("%%"); b. printf("%"); c. printf("\%"); d. a. and b. e. a. and c. f. None of the above a. 9. (2 pts) Which of the following format specifiers skips spaces by default? a. %d b. %c c. %f d. a. and b. e. a. and c. f. None of the above e 10. (2 pts) Modify the following printf statement (not data) so we can generate the output: 7.276 float data = 7.2758; printf("%.3f", data); Everyone gets credit for this one. 11. (2 pts) Write the output generated by the following code fragment. int x = 400, y = 3; if (x == 200 --y) printf("%d %d", x, y); else printf("800\n"); 400 2 12. (2 pts) Rewrite the following code using a single if statement. if (day > 31) if (day <= 60) printf("february\n"); if (day > 31 && day <= 60) printf ( February\n ); 3

13. (8 pts) Rewrite the following code using a switch statement. if (y == 10) { printf("case 1\n"); else if (y == 100) { printf("case 2\n"); else { printf("unknown\n"); switch(y) { case 10: printf("case 1\n"); break; case 100: printf("case 2\n"); break; default: printf("unknown\n"); 14. (2 pts) Write the output generated by the following code fragment if the value of x is 800. if (x < 100) if (x < 80) printf("dog\n"); else printf("cat\n"); printf("done"); Done 15. (2 pts) Rewrite the following statement using a single compound assignment operator. y = y * 3; y = y * 4; y *= 12; 4

16. (4 pts) Rewrite the following code using a single while loop. int x, y; for (x = 1, y = 2; x < 10; x++, y++) { printf("%d %d\n", x, y); x = 1, y = 2; while(x < 10) { printf("%d %d\n", x, y); x++; y++; 5

Problem #2 (20 pts) Write a complete C program that prints the route someone should take based on the hour of the day (hours will be between 1pm and 10pm). The program will read an integer value representing the hour and it will print a message according to the following rules: Alternate Route if the hour is between 1 and 7 (inclusive) Highway if the hour is after 7 and before 10 (inclusive) Any route any other value For this program: You can use the message Enter value to read a value. You do not need to write pseudocode. #include <stdio.h> int main() { int hour; printf("enter value: "); scanf("%d", &hour); if (hour >= 1 && hour <= 7) { printf("alternate Route"); else if (hour > 7 && hour <= 10) { printf("highway"); else { printf("any route"); return 0; 6

Problem #3 (20 pts) Write a C program that prints the powers of odd values between 1 and an integer value provided by the user. Use the message Enter value: to read the integer value. The following is an example that illustrates the functionality of your program when the user enters 10. Notice that your program must work for other scenarios and not just the example below. For this problem you must use a while loop otherwise you will lose significant credit. Enter value: 10 1 1 3 9 5 25 7 49 9 81 #include <stdio.h> int main() { int value, i = 1; printf("enter value: "); scanf("%d", &value); while(i <= value) { if (i % 2!= 0) { i++; printf("%d %d\n", i, i * i); return 0; 7

Problem #4 (20 pts) Write a program that reads a year value. The program expects a year value between 1 (inclusive) and 110 (inclusive). The program will generate the error message Invalid year and keep asking for a year value as long as the user provides an invalid one. Once a correct value has been provided, the program will print the number of days associated with the provided year value. Use the message Total days: followed by the number of days in order to display your answer. The following is an example that illustrates the functionality of your program. Notice that your program must work for other scenarios and not just the example below. For this problem you must use a do while otherwise you will lose significant credit. Enter years: -1 Invalid year Enter years: 200 Invalid year Enter years: 2 Total days: 730 #include <stdio.h> int main() { int years, valid; do { printf("enter years: "); scanf("%d", &years); valid = (years >= 1 && years <= 110); if (!valid) { printf("invalid year\n"); while(!valid); printf("total days: %d\n", years * 365); return 0; 8