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

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

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.

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

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


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

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

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

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

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Definition Matching (10 Points)

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

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

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

Getting started with C++ (Part 2)

WARM UP LESSONS BARE BASICS

C++ Input/Output: Streams

Introduction to Programming EC-105. Lecture 2

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

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.

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

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

Setting Justification

CS 1044 Project 1 Fall 2011

Fundamentals of Programming CS-110. Lecture 2

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

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

CS 1704 Homework 2 C++ Pointer Basics Fall 2002

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

CS101 PLEDGED SPRING 2001

2 nd Week Lecture Notes

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

C++ Final Exam 2017/2018

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

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

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

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

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

A structure is an aggregate data type which contains a fixed number of heterogeneous components.

Creating a C++ Program

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

Computer Programming : C++

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

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

Chapter 2 Basic Elements of C++

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

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

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

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

Introduction to C++ (Extensions to C)

Chapter 2: Basic Elements of C++

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

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

For Teacher's Use Only Q No Total Q No Q No

CS 2505 Computer Organization I

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

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

String Variables and Output/Input. Adding Strings and Literals to Your Programming Skills and output/input formatting

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

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

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

If Control Construct

What we will learn about this week:

C++ for Python Programmers

CSE 131 Introduction to Computer Science Fall Exam I

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

CS242 COMPUTER PROGRAMMING

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

Boolean Algebra Boolean Algebra

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

CS 111X - Fall Test 1

Introduction to Programming using C++

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

CHAPTER 3 Expressions, Functions, Output

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

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

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

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

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

BASIC ELEMENTS OF A COMPUTER PROGRAM

COMPUTER SCIENCE (083)

REVIEW. The C++ Programming Language. CS 151 Review #2

CS 1044 Program 2 Spring 2002

CSCE 121 ENGR 112 List of Topics for Exam 1

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

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

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Transcription:

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Print your name in the space provided below. Print your name and ID number on the Opscan form and code your ID number correctly on the Opscan form. 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 values (containing a decimal point). In questions/answers that 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 (floating point)]. This is a closed-book, closed-notes examination. No laptops, 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 28 equal-valued multiple-choice questions. The answers you mark on the Opscan form will be considered your official answers. When you have finished, sign the pledge at the bottom of this page and turn in the test and your Opscan. 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 2002 Page 1 of 7

For the next 2 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 1) 6 / 4 + 3 / 2.0 1 2 2.5 3.0 None of these 2) 4 * 3 / 6 + 1 1 2 3 4 None of these For the next 2 questions, select the value assigned to the relevant variable, given the declarations: int IntVar; double DecVar; 1 2 3 4 5 3) DecVar = 14 / 5; 2.0 2.8 3.0 4.0 None of these 4) IntVar = 3.0 / 2; 1 1.5 2 3 None of these For the next 3 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 visible 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", Third = "Otis"; In.ignore(100, '\n'); In >> Zero >> One >> Two >> Three; In.ignore(100, '\n'); In.ignore(100, '\t'); In >> Three >> Four >> Zero; In.ignore(100, '\t'); In >> First >> Second; 1 2 3 4 5 5) Four 6 34 82 36 None of these 6) First "Andy" "Goober" "62" "6" None of these 7) Second "Opie" "\n19" "1" "19" None of these Fall 2002 Page 2 of 7

For the next 4 questions, consider writing a program that must read lines of data formatted in the following way. Each line will contain the call number of a book, followed by a tab, followed by a title, followed by a tab, followed by a category name, followed by a tab, followed by a year, followed by a newline: <Call Number><tab><Title><tab><Category><tab><Year><newline> The call numbers and titles are character strings, which may contain any character other than a tab, the category is a single word, and the years are positive integers. Assume that an input stream variable, In, has been opened on such a file, the current stream position is at the beginning of the file, and that the following variables have been declared: string CallNumber, Title, Category; int Year; 8) Which of the following statements will correctly read the first call number into the variable CallNumber? 1) In >> CallNumber; 2) getline(in, CallNumber); 3) getline(in, CallNumber, '\t'); 4) 1, 2 and 3 5) 1 and 2 only 8) None of these 9) Assuming that the first call number, and the tab following it, and the first title and the tab following it have been read, which of the following statements will correctly read the first category into the variable Category? 1) In >> Category; 2) getline(in, Category); 3) getline(in, Category, '\t'); 4) 1, 2 and 3 5) 1 and 2 only 8) None of these For the next 2 questions suppose the input stream contains the following specific data: QA271 P983<tab>How to Solve It<tab>Mathematics<tab>1957<newline> 10) Which of the following would be true after the following statements were executed? getline(in, CallNumber, '\t'); // line 1 getline(in, Title); // line 2 1) CallNumber == "QA271" 2) CallNumber == "QA271 P983" 3) Title == "How to Solve It" 4) Title == "How" 5) Title == "P983" 8) 1 and 4 only 9) 1 and 5 only 10) None of these 11) Which of the following would be true after the following statements were executed, starting over at the beginning of the input stream? getline(in, CallNumber, '\t'); // line 1 In >> Title; // line 2 In >> Category; // line 3 1) Category == "Mathematics" 2) Category == "\tmathematics" 3) Category == "How" 4) Category == "to" 5) Category == "Solve" 6) Category == "It" 7) None of these Fall 2002 Page 3 of 7

For the next 2 questions, assume the input file stream ifile is connected to an input file whose contents are: A3 129B (There's a single tab separating the '3' 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 >> ch2 >> i1 >> ch3; 12) The resulting value of the variable i1 would be: 1) 3 2) 1 3) 12 4) 29 5) 2 6) 129 7) 9 8) Input failure occurs 13) The resulting value of the variable ch2 would be: 1) '3' 2) 'A' 3) ' ' (a space) 4) '1' 5) '2' 6) '9' 7) 'B' 8) Input failure occurs For the next 3 questions, assume the following variable declarations and initializations: bool Burke, Hare = false; int a = 5, b = -2, 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: 1 true 2 false 3 Syntax error 4 Cannot be determined 14) Hare = Hare && Burke; 15) Burke = ( a + c < b a + b == c ); 16) Burke = (a < b) (b < 0) && (c > a); Fall 2002 Page 4 of 7

For the next 4 questions, assume the input file stream In is connected to an input file whose contents are: 3 6.1 2.76 8.28 0.43 0 27 (There's a single space separating each adjacent pair of values.) Consider execution of the following code fragment immediately after the file stream has been opened: int i1; double d1, d2, d3; cout << fixed << showpoint; In >> d1 >> i1; cout << i1 << endl; // A cout << setprecision(2) << d1 << endl; // B In >> d2 >> d3 >> i1; cout << setprecision(1) << d3 << endl; // C cout << i1 << endl; // D 17) In the statement labeled A, the value printed for the variable i1 would be: 1) 3 2) 6 3) 1 4) 61 5) 276 6) 8 7) 828 8) 0 18) In the statement labeled B, the value printed for the variable d1 would be: 1) 3 2) 3.0 3) 3.00 4) 6.1 5) 6.10 6) 36 7) 36.00 8) 8.28 19) In the statement labeled C, the value printed for the variable d3 would be: 1) 2.76 2) 2.7 3) 2.8 4) 2.0 5) 3.0 6) 0.1 7) 8.2 8) 8.3 20) In the statement labeled D, the value printed for the variable i1 would be: 1) 1 2) 2 3) 76 4) 8 5) 28 6) 0 7) 43 8) 27 21) What is the final 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 2002 Page 5 of 7

22) What is the value printed for the variable Delta if the following code is executed? int Delta = 0, X = 2; if ( X % 3 == 2 ) { Delta = Delta + X; X++; if ( X % 3 == 1 ) Delta = Delta + X; X++; if ( X % 3 == 0 ) Delta = Delta + X; cout << "Delta = " << Delta << endl; 1) 0 2) 1 3) 2 4) 3 5) 4 6) 5 7) 6 8) 7 9) 8 10) None of these For the next 3 questions, assume the declarations: string FName = "Donald", LName = "Knuth"; 23) What would be printed by the statement: cout << FName + ":" + LName; 1) Knuth:Donald 2) Knuth : Donald 3) Donald:Knuth 4) Donald : Knuth 5) The statement is not allowed. 6) None of these 24) What would be printed by the statement: cout << LName.length(); 1) Knuth 2) 5 3) 6 4) The statement is not allowed. 5) None of these 25) Which of the following statements would print the name Knuth, followed by the name Donald, so that the two strings will be left-justified and right-justified, respectively, in 20 columns, like this: 12345678901234567890 Knuth Donald 1) cout << LName << setw(20) << FName; 2) cout << LName << setw(20 - FName.length()) << FName; 3) cout << left << setw(10) << LName << right << setw(10) << FName; 4) All of these 5) 1 and 2 only 8) None of these Fall 2002 Page 6 of 7

For the next 2 questions, consider execution of the following switch statement: int Enter = 10; cin >> Enter; switch (Enter) { case 1: Enter = Enter - 4; case 2: Enter = Enter - 6; case 4: break; case 6: Enter = Enter - 8; break; default: Enter = Enter - 1; What would the value of Enter be after execution of this code if the given value were read for Enter? Value read 1 2 3 4 5 6 26) 1-1 -4-6 -8 10 None of these 27) 4-1 -4-6 -8 10 None of these 28) 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 these Fall 2002 Page 7 of 7