Write code that simulates one roll of a 6-sided die and prints out the

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

Question 1. [5 points] Circle and briefly explain the error(s) in the following code:

CS 101, Spring 2017 Apr 11th Exam 3

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

Question 1. [5 points] Consider the following partially-complete program, which begins on the left and continues on the right: HERE

CS 101, Spring 2016 March 22nd Exam 2

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

cd h: mkdir -p CS101 cd CS101 curl -O unzip zipfile cd CS101_Exam4

EECE.2160: ECE Application Programming Spring 2018

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

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

16.216: ECE Application Programming Fall 2011

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 4

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

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

Question 2. [5 points] State a big-o upper bound on the worst case running time of the given

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

EECE.2160: ECE Application Programming Fall 2017

16.216: ECE Application Programming Fall 2013

Question 2. [5 points] Given the following symbolic constant definition

CS 201, Fall 2016 Dec 2nd Exam 3

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

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

Lab 1 Introduction to UNIX and C

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

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

Assignment: TwoMethods Submitted to WebCat

15-110: Principles of Computing, Spring 2018

CS 455 Final Exam Fall 2013 [Bono] December 12, 2013

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

YOUR NAME PLEASE: *** SOLUTIONS ***

CS1800 Discrete Structures Final Version A

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

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

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CS 209 Sec. 52 Spring, 2006 Lab 4-A: Arrays Instructor: J.G. Neal Objectives: Lab Instructions: Obtain file ArrayDemoConsole.java

CS1004: Intro to CS in Java, Spring 2005

Midterm I of Computer Communication , Winter 2004 Electrical and Computer Engineering Department, University of Windsor

CSE 1223: Exam II Autumn 2016

Go to click on the Online Giving icon at the bottom of the page, A new window will open up that looks like this:

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

Final Exam. COMP Summer I June 26, points

Lecture 3. More About C

EMS Students! Follow These Steps to Take. The NREMT Exam

UNIT 4. CONTROL FLOW. Programming Year Grade in Industrial Technology Engineering. Paula de Toledo. David Griol

CS50 Supersection (for those less comfortable)

Lab 1 Introduction to UNIX and C

CS171 Midterm Exam. October 29, Name:

CGS 3460 Summer 07 Midterm Exam

CS 201, Fall 2016 Oct 28th Exam 2. Question 1. [5 points] Consider the following static method:

Common Loop Algorithms 9/21/16 42

C: How to Program. Week /Mar/05

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

CS 112: Intro to Comp Prog

Church Dashboard User Guide Updated: 07/24/2018

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

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

Spring Semester 08, Dr. Punch. Exam #1 (2/12), form 1 B

Personal Online Banking Quick Start Guide

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

CSE 131S Introduction to Computer Science Summer SON Exam I

Spring Semester 08, Dr. Punch. Exam #1 (2/12), form 1 A

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

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

CS 201, Fall 2016 Sep 28th Exam 1

Introduction. Overview of 201 Lab and Linux Tutorials. Stef Nychka. September 10, Department of Computing Science University of Alberta

Midterm Review. Short Answer. Short Answer. Practice material from the Winter 2014 midterm. Will cover some (but not all) of the questions.

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

CS 1301 Exam 1 Fall 2010

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

Engr 123 April 25, 2018 Final Exam Review. 3. Write a method which will accept a string and return the number of three-letter words in the string.

CS1110 Lab 6 (Mar 17-18, 2015)

CSE332 Summer 2010: Final Exam

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

Syntax of for loop is as follows: for (inite; terme; updatee) { block of statements executed if terme is true;

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

Midterm 1 Study Guide

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Project 1. due date Sunday July 8, 2018, 12:00 noon

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

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

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

Final Exam. CSC 121 Fall 2015 TTH. Lecturer: Howard Rosenthal. Dec. 15, 2015

CS 1301 Exam 1 Answers Fall 2009

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 1

Name Section: M/W T/TH Number Definition Matching (8 Points)

Decision Making and Loops

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Test #2 October 8, 2015

COS 126 General Computer Science Spring Written Exam 1

University of Massachusetts Amherst, Electrical and Computer Engineering

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

Transcription:

CS 101, Spring 2017 Mar 14th Exam 2 Name: Question 1. [5 points] If i = 4 and j = 2, what will print: true or false? Briefly explain. if ((i!= 3) (j < 2)) { printf("true"); else { printf("false"); Question 2. [5 points] Briefly explain the bug(s) in the following code, which is intended to compute the sum of the integers from 1 to 10: int sum; for (int i = 1; i < 10; i++) { sum = sum + i; printf("sum is %i\n", sum); Question 3. [5 points] Circle which one of the following is most likely to be correct if used in C programming? a. for (int i = 0; i < 10, i++); b. while (int i = 0; i < 10; i++) c. for (int i = 0; i < 10; i++) d. for (int i = 0, i < 10, i++) e. for (int i = 10; i >= 10; i++) Question 4. [8 points] resulting value. Write code that simulates one roll of a 6-sided die and prints out the

Question 5. [5 points] Briefly explain the bug(s) in the following code, which is intended to print the integers from 1 to 5: int i = 0; while (i <= 5) { printf("%i\n", i); Question 6. [5 points] What output is printed by the following code? (Note: make sure you read carefully!) int x = 0; int y = 1; while (x = 0) { printf("%i\n", y); y = y + 1; if (y = 5) { x = 1; printf("done\n"); Question 7. [2 points] What is the Boolean operator in C for logical OR?

Question 8. [5 points] Consider the following partially-specified code: int n; printf("enter a positive integer: "); scanf("%i", &n); for (int i = 1; i <= n; i++) { int x = Missing ; printf("%i\n", x); The goal is to complete the code so that it prints out the first n positive odd integers, starting from 1. Example run (user input in bold): Enter a positive integer: 5 1 3 5 7 9 What code should be substituted for Missing? Note that you should not define any new variables. Hint: give an expression which uses i, the loop variable. Question 9. [10 points] Write the output of this code as it executes. double sum = 0; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j <= 3; j++) { sum += i*j; printf("i = %i, j = %i, sum = %i\n",i,j,sum);

Programming Questions Note: For all of the programming questions, you should use scanf to read the input value(s) required by the program. Note: Make sure your programs produce the output in exactly the format described, including capitalization and punctuation. You may not receive credit for programs that produce incorrectlyformatted output. Getting started: Start Cygwin Terminal and Notepad++ and make sure ALL TABS are closed. (Note: do not open any other programs.) Your instructor will give you the name of a zip file. In your terminal, run the following commands: cd h: mkdir -p CS101 cd CS101 curl -O http://faculty.ycp.edu/~dhovemey/spring2017/cs101/zipfile unzip zipfile cd CS101_Exam02 Note that in the curl command, the -O has the letter O, not the digit 0. Substitute the name of the zip file for zipfile. Editing code: Use your text editor to open the source file (e.g., question10.cpp) referred to in the question. Do not open any files other than the ones for the exam. Compiling: To compile the program for Question 10, run the following command in the terminal: make question10.exe Change the number as appropriate for the other questions (e.g., question11.exe). Running: To run the program for Question 10, run the following command in the terminal:./question10.exe Change the number as appropriate for the other questions (e.g., question11.exe). To submit: In Cygwin Terminal, run the command make submit Enter your Marmoset username and password when prompted. Good luck!

Question 10. [25 points] Complete the program in question10.cpp so that it reads a single int value N from the user and then prints a line with the form Sum is X where X is the sum of the first N odd integers. For example, if the input value N is 3, then the program should print the output Sum is 9 because 1, 3, and 5 are the first three odd integers and 1 + 3 + 5 = 9 Example run (user input in bold): Enter a positive integer: 3 Sum is 9 Example run (user input in bold): Enter a positive integer: 7 Sum is 49 Hints: Write a loop that executes N times Each iteration of the loop must compute the next odd number and add it to the sum. You may NOT use the modulo operator to determine the odd integers The sum variable should be defined and initialized before the loop starts

Question 11. [25 points] Complete the program in question11.cpp so that it repeatedly reads integer values until a -1 value is read. After the -1 value is read, the program should print a message of the form Even integers: N where N is the total number of even integers entered. Example run (user input in bold): Enter integers: 11 12 16 13 19 6 4-1 Even integers: 4 Hints: Make sure your loop variable(s) are initialized correctly You will need at least two loop variables (one to count even input values and one to control the loop)