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

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

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

CS 1044 Programming in C++ Test 1 Spring 2011 Form B Page 1 of 12 READ THIS NOW!

Spring 2002 Page 1 of 8 READ THIS NOW!

Do not start the test until instructed to do so!

Fall 2002 Page 1 of 9 READ THIS NOW!

Do not start the test until instructed to do so!

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.

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

CS 1704 Intro Data Structures and Software Engineering Test 2 Fall 2001 READ THIS NOW!

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

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

Week 3: File I/O and Formatting 3.7 Formatting Output

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Streams. Parsing Input Data. Associating a File Stream with a File. Conceptual Model of a Stream. Parsing. Parsing

WARM UP LESSONS BARE BASICS

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

Introduction to Programming EC-105. Lecture 2

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

Getting started with C++ (Part 2)

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

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

Fundamentals of Programming CS-110. Lecture 2

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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++

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

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

Setting Justification

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

I/O Streams and Standard I/O Devices (cont d.)

Lab # 02. Basic Elements of C++ _ Part1

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

CSCE 206: Structured Programming in C++


2 nd Week Lecture Notes

Definition Matching (10 Points)

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

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

What we will learn about this week:

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

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

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

We will exclusively use streams for input and output of data. Intro Programming in C++

EECS 183 Fall 2015 Exam 2 Free Response (134 points)

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

CS 1044 Project 1 Fall 2011

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

CS 1044 Program 2 Spring 2002

Computer Programming : C++

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

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

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

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Chapter 4 - Notes Control Structures I (Selection)

CS101 PLEDGED SPRING 2001

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Chapter 2 C++ Fundamentals

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

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

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

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

For questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed

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

Chapter 2 Basic Elements of C++

Lecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type-

CMSC 202 Midterm Exam 1 Fall 2015

C++ Input/Output: Streams

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

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

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

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Objectives. In this chapter, you will:

File I/O Christian Schumacher, Info1 D-MAVT 2013

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 (20 questions * 6 points per question = 120 points)

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Creating a C++ Program

Lab 6. Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

BITG 1233: Introduction to C++

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

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

Introduction to Programming using C++

1. Which of the following best describes the situation after Line 1 has been executed?

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

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 (!

Introduction to C++ (Extensions to C)

CS242 COMPUTER PROGRAMMING

C++ Final Exam 2017/2018

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Transcription:

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Failure to adhere to these directions will not constitute an excuse or defense. Print your name in the space provided below. Print your name and ID number on the Opscan form; be sure to code your ID number correctly on the Opscan form. Code Form B on the Opscan; code your section group number: Struble Engel 223 1 Henry Smyth 146 2 Tucker Litton-Reeves 1670 3 McQuain Litton-Reeves 1870 4 Engel 223 5 Choose the single best answer for each question some answers may be partially correct. If you mark more than one answer to a question, you will receive no credit for any of them. Unless a question involves determining whether given C++ code is syntactically correct, assume that it is. Unless a question specifically deals with compiler #include directives, you should assume the necessary header files have been included. Be careful to distinguish integer values from floating point (real) values (containing a decimal point). In questions/answers which require a distinction between integer and real values, integers will be represented without a decimal point, whereas real values will have a decimal point, [ 1044 (integer), 1044.0 (real)]. When you have finished, sign the pledge at the bottom of this page and turn in the test and your Opscan. This is a closed-book, closed-notes examination. No calculators or other electronic devices may be used during this examination. You may not discuss (in any form: written, verbal or electronic) the content of this examination with any student who has not taken it. You must return this test form when you complete the examination. Failure to adhere to any of these restrictions is an Honor Code violation. There are 30 equal-valued multiple-choice questions. The answers you mark on the Opscan form will be considered your official answers. Do not start the test until instructed to do so! Name (Last, First) printed Pledge: On my honor, I have neither given nor received unauthorized aid on this examination. signature Fall 2000 Page 1 of 7

For the next 2 questions, assume the input file stream ifile is connected to an input file whose contents are: 47 A321 (There's a single space separating the '7' from the 'A'.) Consider execution of the following code fragment immediately after the file stream has been opened: int i1 = 0; char ch1 = 'x', ch2 = 'y'; ifile >> i1; ifile.get(ch1); ifile >> ch2 >> i1; 1) The resulting value of the variable ch1 would be: 1) '4' 2) '7' 3) ' ' (a space) 4) 'A' 5) '3' 6) '2' 7) '1' 8) '\n' 2) The resulting value of the variable i1 would be: 1) 4 2) 47 3) 3 4) 32 5) 321 6) ASCII code for 'A' 7) none of these For the next 2 questions, consider writing a program that must read lines of data formatted in the following way. Each line will contain the name of a team, followed by a tab, followed by a score, followed by a tab, followed by another team name, followed by a tab, followed by another score, followed by a newline. For example: Washington Deadskins<tab>21<tab>Dallas Plowboys<tab>27<newline> Assume that an input stream variable, In, has just been opened on such a file, and that the following variables have been declared: string Team1, Team2; int Score1, Score2; 3) Which of the following statements will correctly read the first team name into the variable Team1? 1) In >> Team1; 2) getline(in, Team1); 3) getline(in, Team1, '\t'); 4) 1, 2 and 3 5) 1 and 2 only 6) 1 and 3 only 7) 2 and 3 only 4) Assuming that the first team name, and the tab following it, have been read, which of the following statements will correctly read the first score into the variable Score1? 1) In >> Score1; 2) getline(in, Score1); 3) getline(in, Score1, '\t'); 4) 1, 2 and 3 5) 1 and 2 only 6) 1 and 3 only 7) 2 and 3 only Fall 2000 Page 2 of 7

For the next 3 questions, select the value assigned to the relevant variable, given the declarations: int IntVar; double DecVar; 1 2 3 4 5 5) IntVar = 19 / 5; 3 3.0 3.8 4 none of these 6) DecVar = 5 + 2.7; 7 7.7 8 8.0 none of these For the following 3 questions, select the value of the given C++ arithmetic expression. Note that the presence of a decimal indicates a double value, rather than an int. 1 2 3 4 5 7) 7/4 3/4 1 2.5 3 4 none of these 8) 15/3*2+1 1 2 3 4 none of these 9) 4.0 + 5/2 6 6.0 6.5 not allowed none of these For the following 4 questions, suppose the (file) input stream In contains the following 5 lines of data (there's one tab character between columns and a newline character immediately after the last character on each line): 55 23 72 40 Gomer 17 30 95 28 Goober 6 34 82 66 Opie 19 62 36 21 Floyd 8 49 45 33 Bea What is the value of each of the indicated variables after the execution of the following program segment? int Zero = 0, One = 1, Two = 2, Three = 3, Four = 4; string First = "Andy", Second = "Barney"; In >> Zero >> One >> Two; In.ignore(100, '\n'); In >> Two >> One >> Zero; In >> Four; In.ignore(100, '\t'); In >> First; In.ignore(100, '\n'); In >> Second; 1 2 3 4 5 10) Zero 55 72 30 95 none of these 11) Four 40 28 30 17 none of these 12) First "\t" "Goober" "Opie" "6" none of these 13) Second "Opie" " 6" "6" "34" none of these Fall 2000 Page 3 of 7

For the next 4 questions, assume the input file stream Fred is connected to an input file whose contents are: 3.14 2.71828 43 0 27 24 1.8-12 3 5 51 8 45.738 17.9 19 32 91 (There's a newline character at the end of each line, and a single space separating values on the same line.) Consider execution of the following code fragment immediately after the file stream has been opened: int anint1, anint2, anint3, anint4; float afloat1, afloat2; Fred.setf(ios::floatfield, ios::fixed); Fred.setf(ios::showpoint); Fred >> afloat1 >> anint1; cout << afloat1 << anint1; // A Fred.ignore(100, '\n'); Fred.ignore( 5, '\n'); Fred >> anint1 >> afloat2 >> anint3; Fred.ignore( 80, '\n'); cout << anint1 << setprecision(1) << afloat2 << anint3; // B Fred >> afloat2; cout << setprecision(2) << afloat2; // C 14) In the statement labeled A, the value printed for the variable anint1 would be: 1) 3 2) 0 3) 2 4) 24 5) 1 6) 8 7) 12 8) 45 15) In the statement labeled B, the value printed for the variable afloat2 would be: 1) 1.8 2) 0.8 3) 12.0 4) 3.0 5) 5.0 6) 51.0 7) 8.0 8) -12 16) In the statement labeled B, the value printed for the variable anint3 would be: 1) 43 2) 0 3) 27 4) 24 5) 1 6) 8 7) 12 8) 45 17) In the statement labeled C, the value printed for the variable afloat2 would be: 1) 45 2) 45.0 3) 45.7 4) 45.73 5) 45.74 6) 45.738 7) 46 8) 46.0 Fall 2000 Page 4 of 7

For the next 2 questions, assume the input file stream ifile is connected to an input file whose contents are: 47 A321 (There's a single tab separating the '4' from the '1'.) Consider execution of the following code fragment immediately after the file stream has been opened: int i1; char ch1 = 'x', ch2 = 'y', ch3 = 'z'; ifile >> ch1 >> i1 >> ch2 >> ch3; 18) The resulting value of the variable i1 would be: 1) 4 2) 47 3) 7 4) 3 5) 32 6) 2 7) 321 19) The resulting value of the variable ch2 would be: 1) '4' 2) '7' 3) ' ' (a space) 4) 'A' 5) '3' 6) '2' 7) '1' 8) '\n' 20) What is the value of the variable Z after the following code is executed? int W = 5, X = 9, Y = 5, Z = 1; if (X % Y >= 2 + W) { Z++; if (Y 3*W >= -X) Z--; else Z++; else { Z = -1; 1) 1 2) 0 3) 1 4) 2 5) 3 6) the code contains a syntax error 7) none of the above 21) What is the first step in Polya's four-step process? 1) Design a solution. 2) Understand the problem. 3) Test the solution. 4) Implement the solution. 5) Find an excuse. 6) none of these Fall 2000 Page 5 of 7

For the next 2 questions, assume the declarations: string FName = "Mickey", LName = "Mouse"; int Age = 74; 22) What would be printed by the statement: cout << LName + ", " + FName; 1) Mickey Mouse 2) Mickey, Mouse 3) Mouse, Mickey 4) The statement is not allowed. 5) None of these 23) Which of the following statements would print the name Mickey, followed by the value of Age, so that the value 74 would be right-justified to column 15? 1) cout << FName << Age; 2) cout << FName << setw(15) << Age; 3) cout << FName << setw(15 FName.length()) << Age; 4) All of these 5) 2 and 3 only 6) None of these For the next 3 questions, assume the following variable declarations and initializations: bool Burke, Hare = false; int a = 0, b = 1, c = 3; Determine the value assigned by each of the following statements to the relevant Boolean variable, or if there's something (syntactically) wrong with the expression; choose from the following answers: 24) Burke = 2 + b < c ; 1 true 2 false 3 syntax error 25) Hare =!( Hare ); 26) Burke = (a + b < c a + b == c); 27) What output will the following program produce? (Be careful this may be tricky.) #include <iostream> using namespace std; void main( ) { int Score = 87, Rank = 2; if (Score >= 95) if (Rank <= 5) cout << "Nice job!"; else cout << "Good job!"; Fall 2000 Page 6 of 7

1) Nice job! 2) Good job! 3) "Nice job!" 4) "Good job!" 5) both 1 and 2 6) both 3 and 4 7) No output is produced. 28) What is the value printed for the variable Delta if the following code is executed? int Delta = 0, X = 4; if ( X / 2 == 1 ) Delta = Delta + X; X--; if ( X / 2 == 0 ) Delta = Delta + X; X--; if ( X / 2 == 0 ) Delta = Delta + X; cout << "Delta = " << Delta << endl; 1) 0 2) 1 3) 2 4) 3 5) 4 6) 5 7) 6 8) None of these For the next 2 questions, consider execution of the following switch statement: int Enter = 10; cin >> Enter; switch (Enter) { case 1: Enter = -4; case 2: Enter = -6; case 4: break; case 6: Enter = -8; break; default: Enter = -1; What would the value of Enter be after execution of this code if the value read for Enter were: Enter 1 2 3 4 5 6 29) 2-1 -4-6 -8 10 none of these 30) 5-1 -4-6 -8 10 none of these Fall 2000 Page 7 of 7