Spring 2002 Page 1 of 8 READ THIS NOW!

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

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

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

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

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!

Do not start the test until instructed to do so!

Fall 2002 Page 1 of 9 READ THIS NOW!

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

True or False (14 Points)

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

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.


CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

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

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

CS Spring 05 - MidTerm

COS 126 General Computer Science Spring Written Exam 1

CSCE 206: Structured Programming in C++

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

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

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

CS 1044 Program 2 Spring 2002

C++ Final Exam 2017/2018

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

CSCE Practice Midterm. Data Types

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

gcc o driver std=c99 -Wall driver.c bigmesa.c

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

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

Definition Matching (10 Points)

Final Exam. COMP Summer I June 26, points

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

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

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

Chapter void Test( int, int, int ); // Function prototype int main() // Function heading { int h; // Local variable

CS 1044 Homework Assignment 4 Summer I 2001

Getting started with C++ (Part 2)

CS242 COMPUTER PROGRAMMING

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

CS 1704 Homework 2 C++ Pointer Basics Fall 2002

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

True or False (15 Points)

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

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

CSCE 2004 Midterm Exam Spring 2017

Circle all of the following which would make sense as the function prototype.

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CS101 PLEDGED SPRING 2001

The Program Specification:

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

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

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

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

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

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

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CSCE Practice Midterm. Data Types

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

C++ PROGRAMMING SKILLS Part 4: Arrays

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

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

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

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

Agenda / Learning Objectives: 1. Map out a plan to study for mid-term Review the C++ operators up to logical operators. 3. Read about the tips

Question: Total Points: Score:

The following expression causes a divide by zero error:

Exercise 1.1 Hello world

cast.c /* Program illustrates the use of a cast to coerce a function argument to be of the correct form. */

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

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

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

Differentiate Between Keywords and Identifiers

CSE 131 Introduction to Computer Science Fall Exam I

CS 1044 Program 6 Summer I dimension ??????

CS 2505 Computer Organization I

9. Arrays. Compound Data Types: type name [elements]; int billy [5];

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Coding Standard for ECE3090 August 24, 2005

UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013

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

Programming. C++ Basics

CS 1044 Project 1 Fall 2011

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Chapter 2 C++ Fundamentals

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

EECS 183 Winter 2016 Exam 2

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

Problem Score Max Score 1 Syntax directed translation & type

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

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

CS 2604 Minor Project 1 Summer 2000

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

Arrays. Week 4. Assylbek Jumagaliyev

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.

What we will learn about this week: Declaring and referencing arrays. arrays as function arguments. Arrays

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

Transcription:

Spring 2002 Page 1 of 8 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 and the five-digit course number in the spaces provided below. Print your name and ID number on the Opscan form; be sure to code your ID number on the Opscan form. Code Form A on the Opscan. Choose the single best answer for each question some answers may be partially correct. If you mark more than one answer, it will be counted wrong. Unless a question involves determining whether given C++ code is syntactically correct, assume that it is. The given code has been compiled and tested, except where there are deliberate errors. Unless a question specifically deals with compiler #include directives, you should assume the necessary header files have been included. Note that questions about printed values disregard formatting completely. 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 completed the test, 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 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 Pledge: On my honor, I have neither given nor received unauthorized aid on this examination. signature

Spring 2002 Page 2 of 8 For the next two questions, consider the execution of the following code fragment: int I = 12, J = 0; while (I > 8){ I = I - 1; J = J + I; //Note: I is not the integer 1 cout << "I = " << I << endl; cout << "J = " << J << endl; 1) What value is printed for the variable I: 1) 4 2) 5 3) 6 4) 7 5) 8 6) 9 7) 10 8) none of the above 2) What value is printed for the variable J: 1) 0 2) 4 3) 11 4) 21 5) 30 6) 38 7) 45 8) none of the above 3) Which of the following are iteration mechanisms in C++? 1) while 2) switch 3) for 4) if..else 5) do..while 6) all of the above 7) 1 and 3 only 8) 2 and 4 only 9) 1, 3 and 5 only 10) none of the above For the next two questions, consider executing the following code fragment (assume any additional declarations, etc, needed to make the code syntactically correct): int j = 2; while (j!= 28) { cout << j << endl; j = j + 3; 4) Exactly how many times will the body of the loop be executed? 1) 8 2) 9 3) 10 4) 11 5) none of the above 5) What is the eighth value printed? 1) 2 2) 20 3) 23 4) 26 5) 28 6) 29 7) 47 8) none of these

Spring 2002 Page 3 of 8 For the next three questions, assume the input file stream ifile is connected to a file containing the following data: 5 3-2 4 1 7 Consider the execution of the code fragment given in each question and determine the value that would be printed. Choose from the following answers: 1) 3 2) 5 3) 6 4) 8 5) 10 6) 11 7) 13 8) 18 9) none of the above 6) int sum = 0, count, mystery, value; for (count = 1; count <= mystery; count++) { ifile >> value; sum = sum + value; cout << "sum = " << sum; 7) int sum = 0, mystery; while (ifile) { sum = sum + mystery; cout << "sum = " << sum; 8) int sum = 0, mystery; while (mystery > 0) { sum = sum + mystery; cout << "sum = " << sum; Consider executing the following program: void main() { int i, j, sum; sum = 0; for (i = 1; i <= 3; i++) { for (j = 1; j <= 3; j++) sum++; cout << sum << endl; 9) What is the value printed on the second line of output? 1) 1 2) 2 3) 3 4) 4 5) 5 6) 6 7) 0 8) none of the above

Spring 2002 Page 4 of 8 Now, consider executing the following slightly different program: void main() { int i, j, sum; for (i = 1; i <= 3; i++) { sum = 0; for (j = 1; j <= 3; j++) sum++; cout << sum << endl; 10) What is the value printed on the second line of output? 1) 1 2) 2 3) 3 4) 4 5) 5 6) 6 7) 0 8) none of the above Assume the following declarations: void Fix(int&, float ); int someint = 42; float somefloat = 3.14; 11) Which of the following is an appropriate call of the function Fix? 1) Fix(24, 6.85); 2) Fix(someInt, 6.85); 3) Fix(24, somefloat); 4) Fix(someInt, somefloat); 5) Fix(someInt + 5, somefloat); 6) all of the above 7) 1 through 5 only 8) 1 and 3 only 9) 2 and 4 only 10) none of the above 12) A function parameter should be passed by reference if the parameter s data flow (communication) is: 1) one-way, into the function 2) one-way, out of the function 3) two-way, into and out of the function 4) all of the above 5) 1 and 2 only 6) 1 and 3 only 7) 2 and 3 only 8) none of the above 13) A function, somefunc, has two formal parameters, Alpha and Beta, both of type int. The data flow (communication) for Alpha is one-way, into the function. The data flow for Beta is two-way, into and out of the function. Which of the following is the most appropriate prototype for somefunc? 1) somefunc(int Alpha, int Beta); 2) somefunc(int& Alpha, int Beta); 3) somefunc(int Alpha, int& Beta); 4) somefunc(int& Alpha, int& Beta); 5) all of the above 6) none of the above

Spring 2002 Page 5 of 8 For the next three questions, consider execution of the following program: void DoThis(int& Alpha, int Beta); void main() { int Temp = 15; int Ben = -5, Jerry = 42; DoThis(Ben, Jerry); cout << Ben = << Ben << endl; cout << Jerry = << Jerry << endl; cout << Temp = << Temp << endl; void DoThis(int& Alpha, int Beta) { int Temp; Alpha = Alpha + 100; Temp = Beta; Beta = 999; Temp = 12; 14) What value is printed for the variable Ben? 1) -5 2) 12 3) 42 4) 95 5) 142 6) 999 8) None of the above 15) What value is printed for the variable Jerry? 1) -5 2) 12 3) 42 4) 95 5) 142 6) 999 8) None of the above 16) What value is printed for the variable Temp? 1) -5 2) 12 3) 42 4) 95 5) 142 6) 999 8) None of the above 17) What is the most appropriate function prototype for a function that receives a character letter grade and returns its integer equivalent on a four-point grading scale? 1) void IntEquiv(char ); 2) void IntEquiv(char& ); 3) void IntEquiv(int ); 4) void IntEquiv(int& ); 5) int IntEquiv(char ); 6) int IntEquiv(char& ); 7) all of the above 8) 1 and 5 only 9) 5 and 6 only 10) none of the above 18) What is the output of the following code fragment? int Limit = 10; cout << H ; for (int LoopCount = 8; LoopCount < Limit; LoopCount++) cout << E ; cout << LP ; 1) HLP 2) HELP 3) HEELP 4) HEEELP 5) none of the above

Spring 2002 Page 6 of 8 19) What loop condition should replace??? in the code below in order to produce the output: 8 17 35 71? int N = 8; do { cout << setw(3) << N; N = N*2 + 1; while (???); 1) N <= 71 2) N < 71 3) N <= 35 4) N < 35 5) N > 143 6) none of the above 20) Given the array declaration below, what is the range of valid index values for myarray[]? int MaxStuff = 65; char myarray[maxstuff + 10]; 1) 0 through 75 2) 0 through 74 3) 0 through 76 4) 1 through 75 5) 1 through 74 6) 1 through 76 7) none of the above 21) What is the output of the following program? void main() { int Ray[5] = {100,200,300,400,500; int k; for (k = 4; k >= 1; k--) cout << Ray[k] << ; 1) 100 200 300 400 500 2) 400 300 200 100 0 3) 500 400 300 200 100 4) 4 3 2 1 0 5) 500 400 300 200 6) 400 300 200 100 7) 100 200 300 400 8) none of the above

Spring 2002 Page 7 of 8 22) Given an integer array Fred[] holding 5000 values, which of the code fragments below could be used to print out the values of Fred[0], Fred[2], Fred[4], etc: 1) for (int i = 0; i < 5000; i = i + 2) cout << Fred[i] << endl; 2) for (int i = 0; i < 2500; i++) cout << Fred[i] << endl; 3) for (int i = 0; i < 2500; i++) cout << Fred[2*i] << endl; 4) for (int i = 0; i < 2500; i++) cout << 2*Fred[i] << endl; 5) for (int i = 0; i < 5000; i++) cout << Fred[i] << endl; 6) all of the above 7) 1 and 2 only 8) 1 and 3 only 9) 1, 2, and 3 only 10) none of the above For the next three questions, consider writing a program that contains the following variable declarations and function prototypes. const int MaxSize = 5; void FillArray(int Ray[], int arraydimension); int aray[maxsize] = {1, 2, 3, 4, 5, bray[maxsize] = {27, 13, 4, 4, 2, RayStevens[MaxSize-1] = {0, 0, 0, 0; Indicate whether the proposed statement given in each question is: 1) syntactically illegal; i.e., there would be a compile-time error 2) syntactically legal, but logically incorrect 3) syntactically legal and logically correct, as far as we can tell 23) aray[maxsize] = bray[maxsize]; 24) FillArray(4, aray); 25) aray[3] = RayStevens[bRay[4]];

Spring 2002 Page 8 of 8 For the next five questions, consider the incomplete function definition given below: // MaxValue() takes an array of integers and returns the index of the // largest value in the array. // // Parameters: // List[] array of integers // HowMany number of values stored in List[] // Returns: // the index of the largest value in List[] // int MaxValue( List[], HowMany) { // line A int maxsofar = ; // line B int Look; // line C for (Look = 1; ; Look++) // line D if (List[maxSoFar] < List[Look]) // line E ; // line F return maxsofar; // line G 26) How should the blank preceding the first parameter in line A be filled? 1) int 2) const int 3) int& 4) const int& 5) none of the above 27) How should the blank preceding the second parameter in line A be filled? 1) int 2) int& 3) int& const 4) none of the above 28) How should the blank in line B be filled? Be careful. 1) 0 2) -1 3) List[0] 4) HowMany 5) none of the above 29) How should the blank in line D be filled? 1) Look <= HowMany 2) Look < HowMany 3) Look < maxsofar 4) Look == HowMany 5) none of the above 30) How should the blank in line F be filled? 1) Look = maxsofar 2) Look == maxsofar 3) maxsofar = Look 4) maxsofar = List[Look] 5) none of the above