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

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

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

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.

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

Name SECTION: 12:45 2:20. True or False (12 Points)

C++ Final Exam 2017/2018

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

FORM 2 (Please put your name and form # on the scantron!!!!)


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

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

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

Name Section: M/W or T/TH. True or False (14 Points)

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

The following expression causes a divide by zero error:

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

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

CS242 COMPUTER PROGRAMMING

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

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

True or False (14 Points)

C++ Programming: From Problem Analysis to Program Design, Third Edition

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

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Why Is Repetition Needed?

True or False (15 Points)

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

Chapter 2: Basic Elements of Java

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ basics Getting started with, and Data Types.

Objectives. In this chapter, you will:

Definition Matching (10 Points)

Functions. Lecture 6 COP 3014 Spring February 11, 2018

FORM 2 (Please put your name, form #, and section # on the scantron!!!!)

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

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

Programming Language. Functions. Eng. Anis Nazer First Semester

CS2141 Software Development using C/C++ C++ Basics

REPETITION CONTROL STRUCTURE LOGO

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

CS2255 HOMEWORK #1 Fall 2012

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

True or False (12 Points)

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

Homework #3 CS2255 Fall 2012

C++ Programming: From Problem Analysis to Program Design, Third Edition

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

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

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

CSCE Practice Midterm. Data Types

CIS 130 Exam #2 Review Suggestions

Preview 8/28/2018. Review for COSC 120 (File Processing: Reading Data From a File)

Computer Programming : C++

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

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

Chapter 2: Basic Elements of C++

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

CS101 PLEDGED SPRING 2001

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

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Chapter 4 - Notes Control Structures I (Selection)

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

True or False (15 Points)

C++ Functions. Last Week. Areas for Discussion. Program Structure. Last Week Introduction to Functions Program Structure and Functions

1) You want to determine whether time has run out. The following code correctly implements this:

Week 1: Hello World! Muhao Chen

Pointers, Dynamic Data, and Reference Types

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Input And Output of C++

Creating a C++ Program

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Fundamentals of Programming CS-110. Lecture 2

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

CSCE 110 PROGRAMMING FUNDAMENTALS

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

CS 115 Exam 3, Spring 2010

Computing and Statistical Data Analysis Lecture 3

CSCE Practice Midterm. Data Types

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


Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

CS Spring 05 - MidTerm

CS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3.

CSci 1113 Midterm 1. Name: Student ID:

Chapter 11: Pointers

Chapter 2 Basic Elements of C++

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

Full file at

CSCE 206: Structured Programming in C++

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

CS 007A Midterm 1 Practice Chapters 1 5

Transcription:

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result), storage, and performance of arithmetic and logical operations. 2. A function may return more than one item. 3. To develop a program to solve a problem, you start by analyzing the problem. 4. When you compile your program, the compiler identifies the logic errors and suggests how to correct them. 5. Assume all variables are properly declared. The output of the following code is 2 3 4 5. n = 1; while (n < 5) { n++; cout << n << " "; 6. In C++, both! and!= are relational operators. 7. An operator that has only one operand is called a unique operator. 8. A void function can be used in an assignment. 9. If input failure occurs in a C++ program, the program terminates immediately and displays an error message. 10. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!gooddata) 11. The value of the expression 6 < 5 'g' > 'a' && 7 < 4 is. 12. If a C++ arithmetic expression has no parentheses, operators are evaluated from left to right. 13. You can use the function getline to read a string containing blanks.

14. Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++) cout << i; 15. A comma is also called a statement terminator. 16. If the parameter list of a function is empty, the parentheses after the function name are not needed. 17. The following while loop terminates when j > 20. j = 0; while (j < 20) j++; Multiple Choice (3 pts each) 18. is a valid char value. a) "-129" b) A c) "A" d) 129 19. What is the value of x after the following statements? int x; x = x + 30; a) 0 b) 30 c) 33 d) Unknown 20. Suppose that x is an int variable. Which of the following expressions always evaluates to true? a) (x > 0) ( x <= 0) b) (x >= 0) (x == 0) c) (x > 0) && ( x <= 0) d) (x > 0) && (x == 0) 21. Before using the data type string, the program must include. a) <stdlib> b) <iostream> c) <string> d) <cstring>

22. Suppose str = " Hello There. ". The output of the statement cout << str.length() << endl; is. a) 11 b) 12 c) 13 d) 14 23. Given the following code fragment, which of the following expressions is always true? int x; cin >> x; a) if( x < 3) b) if( x==1) c) if( (x / 3) >1 ) d) if( x = 1) 24. What should be the output from this code segment? int main() { for( int i = 0; i < 10; i++) { cout << hello << endl; cout << i << endl; return 0; a) 10 b) 9 c) 0 d) The variable i is undefined in this scope, so this should not compile 25. An example of a floating point data type is. a) int b) char c) double d) short 26. A function prototype is. a) a definition, but not a declaration b) a declaration and a definition c) a declaration, but not a definition d) a comment line

27. What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; cout << count << " " << num << endl; a) 24 0 b) 24 1 c) 25 0 d) 25 1 28. Functions that do not have a return type are called functions. a) zero b) null c) void d) empty 29. Suppose sum, num, and j are int variables, and the input is 4 7 12 9-1. What is the output of the following code? cin >> sum; cin >> num; for (j = 1; j <= 3; j++) { cin >> num; sum = sum + num; cout << sum << endl; a) 24 b) 25 c) 41 d) 42 30. The expression (int)(6.9) + (int)(7.9) evaluates to. a) 13 b) 14 c) 14.8 d) 15

31. Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s). a) alpha = 1 - beta; b) alpha = beta - 1; c) beta = beta - 1; alpha = beta; d) alpha = beta; beta = beta - 1; 32. The pow(x) and sqrt(x) functions are found in which include file? a) <cmath> b) <iostream> c) <cctype> d) <cstdlib> 33. The rules of a programming language tell you which statements are legal, or accepted by the programming language. a) semantic b) logical c) syntax d) grammatical 34. Which of the following function prototypes is valid? a) int functest(int x, int y, float z){ b) functest(int x, int y, float){; c) int functest(int, int y, float z) d) int functest(int, int, float); 35. Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0)? x : y;. a) 2 b) 3 c) 4 d) 6 36. Given the following function prototype: int myfunc(int, int);, which of the following statements is valid? Assume that all variables are properly declared. a) cin >> myfunc(y); b) cout << myfunc(myfunc(7, 8), 15); c) cin >> myfunc('2', '3'); d) cout << myfunc(myfunc(7), 15);

37. Given the following function: int strange(int x, int y) { if (x > y) return x + y; else return x y; what is the output of the following statement? cout << strange(4, 5) << endl; a) -1 b) 1 c) 9 d) 20 38. If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5; if (a > b) a = 4; if ( b > c) a = 5; else a = 6; cout << a < endl; a) 3 b) 4 c) 5 d) 6, the cout statement belongs to the else and so is skipped. 39. Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a) Sunny \nday b) Sunny \nday endl c) Sunny Day d) Sunny \n Day

Extra Credit (2 pts each) 40. In C++, reserved words are the same as predefined identifiers. 41. The function main is always compiled first, regardless of where in the program the function main is placed. 42. What is the final value of x after the following fragment of code executes? int x=0; do { x++; while(x > 0); a) 9 b) 10 c) 11 d) infinite loop. 43. What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 5) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y 3; cout << y << endl; a) 5 b) 6 c) 8 d) 10

44. Given the following function: int next(int x) { return (x + 1); what is the output of the following statement? cout << next(next(5)) << endl; a) 5 b) 6 c) 7 d) 8