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

Similar documents
I. True/False: (2 points each)

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

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall What is your name?: (3 points for writing it on your answer sheet)

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

I. True/False: (2 points each)

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

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

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

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

I. True/False: (2 points each)

I. True/False: (2 points each)

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

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

CSCE 206: Structured Programming in C++

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

Exam 3 Chapters 7 & 9

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

CSCE 2004 Midterm Exam Spring 2017

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Getting started with C++ (Part 2)

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

BASIC ELEMENTS OF A COMPUTER PROGRAM

CS Spring 05 - MidTerm

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

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

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

C++ Final Exam 2017/2018

Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007.

CSci 1113 Midterm 1. Name: Student ID:

CSC 1300 Exam 4 Comprehensive-ish and Structs

CS242 COMPUTER PROGRAMMING

CS Final Exam Review Suggestions - Spring 2014

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

ENJOY! Problem 2 What does the following code do, in a brief English sentence? int mystery(int k) { int i = 0; if (k < 0) return -1;

Reviewing all Topics this term

Chapter Two MULTIPLE CHOICE

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Midterm Practice Exam

CMSC 202 Midterm Exam 1 Fall 2015

LAB 4.1 Relational Operators and the if Statement

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

CSci 1113 Midterm 2. Name: Student ID:

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Practice Midterm 1. Problem Points Score TOTAL 50

Introduction to Computer Science Midterm 3 Fall, Points

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Largest Online Community of VU Students

CSCE Practice Midterm. Data Types

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

READ THIS NOW! Do not start the test until instructed to do so!

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Unit 7. 'while' Loops

Chapter 2 C++ Fundamentals

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number:

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

Do not turn to the next page until the start of the exam.

CS31 Discussion 1E Spring 17 : week 08

Definition Matching (10 Points)

Add Subtract Multiply Divide

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

Review Summer CSC1322 Adv Programming in C++ Professor: Zhang

CS 1044 Programming in C++ Test 1 READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

1. In C++, reserved words are the same as predefined identifiers. a. True

Programming. C++ Basics

C: How to Program. Week /Mar/05

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

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

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

Chapter 2 - Control Structures

Lecture 3 Tao Wang 1

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Transcription:

CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03 What is your name?: (0 points) There are two sections: I. Short Questions.........40 points; (40 questions, 1 point each) II. Short Sections of Code...24 points; ( 6 questions, 4 points each) II. Longer Sections of Code..36 points; ( 3 questions, 12 points each) --------------- 100 points total This test is worth 10% of your final grade. For all problems you must put your answers on the bubble form using a #2 pencil. This test is open book and open notes. You have 50 minutes. For the True/False questions, if the answer is True, fill in a on your answer form. If the answer is False, fill in b on your answer form. For the multiple choice problems, select the best answer for each one and select the appropriate letter on your answer sheet. Be careful - more than one answer may seem to be correct. Some questions are tricky. Several problems ask you to determine whether something is valid. Something is valid if it would not generate a compiler error and would execute without the program crashing. I. Short Questions: (1 pt. each) T F 1. In UNIX, the command man ls could used to give more information on the ls command. T F 2. Both C++ comments (//) and C-style comments (/* */) can be used in the same program, but they can t appear on the same line. T F 3. An infinite loop is best represented using a while loop. T F 4. C++ has three different looping structures for convenience. Anything written with one of the looping structures could be written with a different looping structure, with some modification of the code. T F 5. An if - else statement can always be rewritten as two if statements. T F 6. Once a program is longer than 1024 lines, the C++ compiler requires that it be broken up into functions. T F 7. A function that determines whether or not a program is done will most likely have a return type of bool. T F 8. Using the VC++ debugger it is possible to run your program a step at a time, displaying the values of all variables along the way. T F 9. The following sequence will halt the execution of your program. int x = -1; assert ( 1 < x < 4); CS 102 - Intro. to Programming, Midterm Exam #1, page 1 of 6

T F 10. To ensure a character stored in variable c is upper case, we could use the following: if( (c>= a ) && (c<= z )) c = c - ( a - A ); T F 11. To ensure a character stored in variable c is upper case, we could use the following: #include <cctype> //... rest of program c = toupper(c); T F 12. The following cout statement outputs the letter 'A', followed by the newline character, followed by the letter 'B', followed by the tab character, followed by the letter 'C'. cout << 'A' << "\nb" << "\tc"; For questions 13 through 20 determine if each is a valid identifier. T F 13. first_and_second T F 14. expen$ive T F 15. 2bOrNot T F 16. tobeornot2b T F 17. supercalifragilisticexpialidocious T F 18. a T F 19. Main T F 20. salt&pepper For questions 21 through 29 assume that intnum is an integer, realnum is a real (floating point), and achar is a character, and there are no other variables declared. Determine if each is a valid assignment statement. T F 21. achar = "A1"; T F 22. achar = (intnum < 0)? Y : N ; T F 23. achar = achar + ( a - A ) ; T F 24. achar = 65; T F 25. intnum + 1 = intnum; T F 26. intnum = achar; T F 27. intnum = ++intnum; T F 28. realnum = intnum - - - achar; T F 29. realnum = A ; CS 102 - Intro. to Programming, Midterm Exam #1, page 2 of 6

For questions 30 through 37 determine if each is a valid statement or statements. T F 30. char c= A ; if ( c) cout << "Yes"; T F 31. cout<< Hey...\n ; T F 32. int x( 6); if ( 0 < x < 5) cout << " Between 0 and 5"; T F 33. char pi = 3.1415 ; T F 34. char Output = A ; char text = B ; cout << Output text << endl; T F 35. cout<<"w"<<"e"<<"i"<<"r"<<"d"; T F 36. cout<< O << K <<? ; T F 37. int z=0; for( z/=z; z=1; z=1) ; // semicolon only on this line before this comment 38. Assume that program9 is a directory in your current working directory. What is the command to remove program9 and all files and directories inside program9? a) removedir program9 b) rmdir program9 c) rm -r program9 d) del program9 39. Which of the following is the correct UNIX command to compile the C++ program game.cpp into an executable file called game? a) g++ game.cpp b) g++ game c) g++ -o game game.cpp d) g++ -o game.cpp game 40. Consider the following segment of code: int number = (2/5)*5; cout <<"The answer is: "<< number; What is the output? a) 2 b) The answer is 2 c) The answer is: 2 d) The answer is: 0 CS 102 - Intro. to Programming, Midterm Exam #1, page 3 of 6

II. Short Sections of Code: (4 pts. each) T F 41. The output of the program segment below is the text: Was 1 to 3. int num = 3; switch ( num) case 1: case 2: case 3: cout << "Was 1 to 3\n"; case 4: cout << "Was 4\n"; default: printf("unknown"); cout<<"."; T F 42. The output of the program segment below is the text: Is pi float pi = 3.14159; switch ( pi) case 3.14159: cout << "Is pi\n"; break; default: cout << "Not pi\n"; break; T F 43. The output of the program segment below is the text: Was equal int x = 0; if ( x = 1) cout<<"was equal"; else cout<<"not equal "; cout<<" *** "; T F 44. The output of the program segment below is the text: greater than Done. int x = 3; if ( x <= 3) if ( x < 3) cout << "less than "; else cout<<"greater than "; cout<<"done."; 45. Consider the program segment given below. Its output can best be described as: char a= b ; char b= c ; char c=a; cout<< a <<b<< c <<a<< b <<c; a) abcabc b) accbbb c) aacbbc d) accabb CS 102 - Intro. to Programming, Midterm Exam #1, page 4 of 6

46. Consider the program given below. for ( int i=1; i<5; i++) cout << i << ; for ( int i=4; i>=1; i--) cout << i << ; This program compiles and runs using: a) VC++ but not g++ b) g++ but not VC++ c) both VC++ and g++ d) neither VC++ or g++ III. Longer Sections of Code: (12 points each) 47. Consider the program given below. Its output can best be described as: int x; cout<<"please enter a 3-digit positive integer: "; cin>> x; while (x > 0) cout<< x % 10; x /= 10; cout<<"\n"; a) The remainder of the digits after dividing by 10\ b) The input digits in reverse order c) A tenth of the original input d) All of the digits except the rightmost digit. CS 102 - Intro. to Programming, Midterm Exam #1, page 5 of 6

48. Consider the program given below. If its output is: 2 4 6 8 3 6 9 12 What was the input? int i, j, k, n, r; cin >> k >> n >> r; for( j=k; j<=n; j++) for( i=1; i<=r; i++) cout << i*j << "\t"; cout << "\n"; a) 2 4 3 b) 3 2 4 c) 3 4 2 d) 2 3 3 49. What is the output of the program given in the two columns below? int a,b,c; void confuse1(int b, int a) a += 1; b += 1; c += 1; void confuse2(int b, int &a) a += 2; b += 2; c += 2; void confuse3(int &b, int c) a += 3; b += 3; c += 3; int a,c; a=b=c=1; confuse1( a, b); confuse2( b, c); confuse3( a, c); cout << a << b << c << endl; a) 879 b) 414 c) 745 d) 251 CS 102 - Intro. to Programming, Midterm Exam #1, page 6 of 6