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

Size: px
Start display at page:

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

Transcription

1 CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given. All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers suggests otherwise. 1. [NOT GRADED] Read through this code fragment and determine what (if anything) is wrong with this code. int i; //line 1 int * ip; //line 2 ip = &i; //line 3 delete ip; //line 4 A. line 3 is illegal, because ip is not a reference parameter. B. line 4 is a syntax error; it should read delete *ip because ip is a pointer. C. line 4 has no syntax error, but represents a logic error because i has not been initialized. D. line 4 has no syntax error, but represents a serious programmer error in dynamic memory usage. E. no apparent errors ANSWER: D 2. In object-oriented programming, the term "method" A. simply means a member function of a class B. means any algorithm or way of doing things in a program C. means a particular technique for defining variables D. refers to the arguments passed to a constructor E. is used in connection with the software lifecycle to describe a particular way of developing quality software 3. int i; double d; char c; char str[100]; cin >> i >> d >> c >> str; cout << str; Suppose at the point where the statement with cin above is executed, the user types in King Dome (The leading spaces are part of what is typed in.) What will be the result displayed by the line with cout? A. Can't tell, because an error would have occurred reading in the variable i B. King Dome C. King D. ing Dome E. ing ANSWER: E

2 Page 2 4. Trace through the operation of this code, and then pick the true statement it: #include <iostream> void f (int& p1, int& p2) { p1 = p2 + 7 * 2; int main (void) { int x, y; x = 2; f (x, x); y = x; f (y, y); cout << x << endl; return 0; A. It prints the value 18 B. y's value after the call f (y, y) is 16 C. It prints the value 30 D. It prints the value 16 E. It prints the value 2 ANSWER: D 5. cout is what? A. An object (a variable whose type is a class) B. A library function C. A system file D. A C++ operator E. A class 6. The process of going from a set of source files to a running program has several steps. Place the following in the correct order from the first step executed to the last: A.) Linking B.) Compiling C.) Execution D.) Processing #include directives A. B, D, A, C B. B, C, A, D C. D, B, A, C D. D, A, B, C E. A, D, B, C ANSWER: C

3 Page 3 7. Which represents a proper use of the new C++ type for Boolean values? A. char errorflag = "true"; B. bool errorflag = true; C. bool errorflag = FALSE; D. enum errorflag = {true, false; E. Boolean errorflag; ANSWER: B 8. The filestream declared as ifstream ifile; has been opened successfully. This line of the program ifile >> count; executes, where count is an integer variable. However, the file at this point contains the letter 'x' rather than a valid integer. Which code properly detects such an error? A. if (ifile) { //OK else { //error B. if (ifile[0]!= int) { C. char chcount = char (count); if (isalpha(chcount)) { D. if (isalpha(count)) { E. if (ifstream.error()) { 9. The typical reason for using assert() in a program is A. to detect user input errors B. to display confidence (assertiveness) in one's ability to program C. to check invariants D. to guard against undeclared identifiers E. to inform the caller (of the function in which the assert is located) whether or not there was an error ANSWER: C

4 Page A "module" is best described as A. any.cpp file B. any.h file C. another name for a program D. a self-contained unit of code E. any method or function apart from main() ANSWER: D 11. "Data + Operations" is a characterization of A. functional decomposition B. operator overloading C. overloaded constructors D. modularity E. (abstract) data type ANSWER: E 12. Study the following fragment of class declaration and method implementation. Note that in the method, the "legs" variable of three different objects is referred to. Are all of these references legal? A. Line A is legal B. Line B is legal C. Line C is legal class chair { private: int legs; int back; double weight; public: chair copy (chair other); ; chair chair::copy(chair other) { chair tempchair; int templegs = other.legs; //Line A tempchair.legs = templegs; //Line B legs = templegs; //Line C A. A only B. B only C. C only D. B and C only E. all of A, B, and C ANSWER: E

5 Page Suppose you see this in a valid C++ program. a, b, c, d, and e are all valid identifiers (none of them are reserved words): void myfunction (a b, c d) { a e (b, d);.. Given this, what might you expect to find as a prototype in a class specification somewhere? A. a e (b x, d y); B. a (a, c); C. a e (a, c); D. e::e (a, b); E. a e (b. d); ANSWER: B 14. Food is the name of a class. A function contains an array declared as Food menu[20]; What is true? A. If there is a default constructor for Food, it will be called 20 times to initialize the elements of menu. B. If there is a constructor for Food which takes an array argument, that constructor will be called for the initialization of menu. C. The menu is uninitialized. [Of course, it might be initialized by some later statements.] A. A only B. B only C. C only D. A and B only E. None of A, B, or C

6 Page [NOT GRADED] bool F(int low, int high) { if (low > high) return false; if (low == high) return true; else return F(low + 2, high + 1); Consider the state of A and B after the following two calls: bool A = F(5, 7); bool B = F(0, 4); A. A is false, B is false B. A is false, B is true C. A is true, B is false D. A is true, B is true E. The program does not terminate (infinite recursion) ANSWER: C 16. (Worth 4 multiple choice questions) On a separate handout you have the header file for class which represents a List of ints. The header file is practically the same as the one used in last week's quiz (adapted from the Carrano, Helman, and Veroff textbook, p.136.) Your job is to implement a new method. Here is what will be added to the public: section of the.h file: void ListInsertBefore(int elementbefore, int newvalue, bool & Success); /* Inserts newvalue into a list, before an element with a value equal to elementbefore. Postcondition: If there is an element in the list with a value equal to elementbefore, NewItem is inserted at a position directly before that element, other list items are moved accordingly, and Success is true; otherwise Success is false, and the list is unchanged. (If there is more than one list element equal to elementbefore, it does not matter which one the newvalue is placed before. */ Example: suppose the list currently contains and a client makes a call with the first two arguments as Then the method give true as the result, and the list has the elements Your task: give a complete implementation of ListInsertBefore. Make no changes to the.h file. [You should follow the handout quite strictly in developing your answer. The quiz was graded pass/fail, but this problem won't be!]

7 Page 7 /************************* sample solution ******************/ //Two possible implementations void listclass::listinsertbefore (int ElementBefore, int NewValue, bool &Success) { Success = false; assert(size <= MAX_LIST); if (Size >= MAX_LIST) return; int i; for (i = 0; i < Size; i++) { if (Items[i] == ElementBefore) { // found it // shift the other elements and insert the new value for (int j = Size; j > i; j--) { Items[j] = Items[j-1]; Items[i] = NewValue; Success = true; Size++; return; // version 2 void listclass::listinsertbefore(int elementbefore,int newvalue,bool &success) { assert(size <= MAX_LIST); success = false; for(int i=0;i < Size; i++) if(items[i] == elementbefore) { ListInsert(i+1,newValue,success); //the call to ListInsert will do its job, if it can, //and set success apprpriately //It will also have updated Size (unless the array was full) return;

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

double d0, d1, d2, d3; double * dp = new double[4]; double da[4]; All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) Review Final exam Final exam will be 12 problems, drop any 2 Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) 2 hours exam time, so 12 min per problem (midterm 2 had

More information

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!!!!) CS 161 Exam II: FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. The declaration below declares three pointer variables of type pointer to double that is

More information

CMSC 202 Midterm Exam 1 Fall 2015

CMSC 202 Midterm Exam 1 Fall 2015 1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.

More information

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.

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. 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. B. Outputs to the console a floating point number f1 in scientific format

More information

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

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 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),

More information

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

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (! FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.

More information

CSci 1113 Midterm 1. Name: Student ID:

CSci 1113 Midterm 1. Name: Student ID: CSci 1113 Midterm 1 Name: Student ID: Instructions: Please pick and answer any 7 of the 9 problems for a total of 70 points. If you answer more than 7 problems, only the first 7 will be graded. The time

More information

Suppose that the following is from a correct C++ program:

Suppose that the following is from a correct C++ program: All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

Multiple Choice (Questions 1 13) 26 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) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Assertions, pre/postconditions

Assertions, pre/postconditions Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What

More information

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance) Parallel processing Highlights - Making threads - Waiting for threads - Review (classes, pointers, inheritance) Review: CPUs Review: CPUs In the 2000s, computing too a major turn: multi-core processors

More information

Multiple Choice (Questions 1 13) 26 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) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

CSci 1113 Final. Name: Student ID:

CSci 1113 Final. Name: Student ID: CSci 1113 Final Name: Student ID: Instructions: Please pick and answer any 10 of the 12 problems for a total of 100 points. If you answer more than 10 problems, only the first 10 will be graded. The time

More information

Unit 7. 'while' Loops

Unit 7. 'while' Loops 1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment

More information

CIS 130 Exam #2 Review Suggestions

CIS 130 Exam #2 Review Suggestions CIS 130 - Exam #2 Review Suggestions p. 1 * last modified: 11-11-05, 12:32 am CIS 130 Exam #2 Review Suggestions * remember: YOU ARE RESPONSIBLE for course reading, lectures/labs, and especially anything

More information

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

1) You want to determine whether time has run out. The following code correctly implements this: Exam Name TRUE/FALSE. Write ʹTʹ if the statement is true and ʹFʹ if the statement is false. 1) You want to determine whether time has run out. The following code correctly implements this: 1)!time > limit

More information

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

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. Failure to adhere to these directions will not constitute an excuse or defense. Print your name in the space

More information

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!

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! 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; be sure to

More information

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:

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: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

CS201- Introduction to Programming Current Quizzes

CS201- Introduction to Programming Current Quizzes CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements

More information

C:\Temp\Templates. Download This PDF From The Web Site

C:\Temp\Templates. Download This PDF From The Web Site 11 2 2 2 3 3 3 C:\Temp\Templates Download This PDF From The Web Site 4 5 Use This Main Program Copy-Paste Code From The Next Slide? Compile Program 6 Copy/Paste Main # include "Utilities.hpp" # include

More information

Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) Review for Test 1 (Chapter 1-5) 1. Software development 1. Pre-conditions and Post-conditions 2. Running time analysis Big O Timing loops and nested loops 1) Write the simplest big-o expression to describe

More information

Part I: Short Answer (6 questions, 18 points total)

Part I: Short Answer (6 questions, 18 points total) CSE 143 Sp01 Midterm 2 Sample Solution page 1 of 7 Part I: Short Answer (6 questions, 18 points total) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Answer each question in the space

More information

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

More information

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

The following expression causes a divide by zero error:

The following expression causes a divide by zero error: Chapter 2 - Test Questions These test questions are true-false, fill in the blank, multiple choice, and free form questions that may require code. The multiple choice questions may have more than one correct

More information

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:

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: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

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

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout

More information

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

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

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Memory and Pointers written by Cathy Saxton

Memory and Pointers written by Cathy Saxton Memory and Pointers written by Cathy Saxton Basic Memory Layout When a program is running, there are three main chunks of memory that it is using: A program code area where the program itself is loaded.

More information

CS Final Exam Review Suggestions - Spring 2014

CS Final Exam Review Suggestions - Spring 2014 CS 111 - Final Exam Review Suggestions p. 1 CS 111 - Final Exam Review Suggestions - Spring 2014 last modified: 2014-05-09 before lab You are responsible for material covered in class sessions, lab exercises,

More information

Review Questions for Final Exam

Review Questions for Final Exam CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.

More information

Exam 3 Chapters 7 & 9

Exam 3 Chapters 7 & 9 Exam 3 Chapters 7 & 9 CSC 2100-002/003 29 Mar 2017 Read through the entire test first BEFORE starting Put your name at the TOP of every page The test has 4 sections worth a total of 100 points o True/False

More information

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

FORM 2 (Please put your name, form #, and section # on the scantron!!!!) EECS 161 Exam 2: FORM 2 (Please put your name, form #, and section # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive functions always execute faster than an iterative function. 2. The

More information

Review Questions II KEY

Review Questions II KEY CS 102 / ECE 206 Spring 2011 Review Questions II KEY The following review questions are similar to the kinds of questions you will be expected to answer on Exam II (April 7), which will focus on LCR, chs.

More information

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID# Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

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 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. Print your name in the space provided below. Print your name and ID number on the Opscan form and code your

More information

Consider the following statements. string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is " ". Given the function prototype: float test(int,

More information

CS 61B, Midterm #3 and solutions, Spring 1996

CS 61B, Midterm #3 and solutions, Spring 1996 CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3 Read and fill in this page now. Do NOT turn the page until you are told to do so. Your name: Your login name:

More information

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

IS0020 Program Design and Software Tools Midterm, Fall, 2004

IS0020 Program Design and Software Tools Midterm, Fall, 2004 IS0020 Program Design and Software Tools Midterm, Fall, 2004 Name: Instruction There are two parts in this test. The first part contains 22 questions worth 40 points you need to get 20 right to get the

More information

C++ Final Exam 2017/2018

C++ Final Exam 2017/2018 1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value

More information

CS2255 HOMEWORK #1 Fall 2012

CS2255 HOMEWORK #1 Fall 2012 CS55 HOMEWORK #1 Fall 01 1.What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; a. 10 b. 7 c. The

More information

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm Directions: This is a take-home exam. Type your answers in an electronic file (all in ONE file), in a pdf/doc/txt format,

More information

PIC 10A. Final Review: Part I

PIC 10A. Final Review: Part I PIC 10A Final Review: Part I Final exam The final exam is worth 30% of your grade, same weight as 2 midterms. Could be 50% if grading option 2 turns out better for you. Length is also roughly 2 midterms

More information

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015 CMSC 202 Section 06 Fall 2015 Computer Science II Midterm Exam I Name: Username: Score Max Section: (check one) 07 - Sushant Athley, Tuesday 11:30am 08 - Aishwarya Bhide, Thursday 11:30am 09 - Phanindra

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

CSE 333 Midterm Exam Nov. 3, 2017 Sample Solution

CSE 333 Midterm Exam Nov. 3, 2017 Sample Solution Question 1. (8 points) Making things. Consider this (buggy) Makefile (the options -Wall, -g, and -std=c11 were omitted to save space and do not affect the answers): all: prog foo.c: foo.c foo.h bar.h gcc

More information

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

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1 BEng (Hons) Electronic Engineering Cohort: BEE/10B/FT Resit Examinations for 2016-2017 / Semester 1 MODULE: Programming for Engineers MODULE CODE: PROG1114 Duration: 3 Hours Instructions to Candidates:

More information

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;

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; Debugging Some have said that any monkey can write a program the hard part is debugging it. While this is somewhat oversimplifying the difficult process of writing a program, it is sometimes more time

More information

ComS 228 Exam 1. September 27, 2004

ComS 228 Exam 1. September 27, 2004 ComS 228 Exam 1 September 27, 2004 Name: University ID: Section: (10 percent penalty if incorrect) This is a one-hour, closed-book, closed-notes, closed-calculator exam. The exam consists of 9 pages (including

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3 CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3 Read and fill in this page now. Do NOT turn the page until you are told to do so. Your name: Your login name:

More information

Constants, References

Constants, References CS 246: Software Abstraction and Specification Constants, References Readings: Eckel, Vol. 1 Ch. 8 Constants Ch. 11 References and the Copy Constructor U Waterloo CS246se (Spring 2011) p.1/14 Uses of const

More information

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

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received CSC 126 FINAL EXAMINATION FINAL Spring 2012 B Name (last, First) Instructor Question # Total Possible Total Received 1. 8 2. 8 3. 8 4. 14 5. 18 6. 10 7. 16 8. 18 TOTAL 100 Final Exam/ Page 2 1) (8 points)

More information

Practice test for midterm 2

Practice test for midterm 2 Practice test for midterm 2 April 9, 2 18 1 Functions Write a function which takes in two int parameters and returns their average. (Remember that if a function takes in parameters, it does not need to

More information

C for C++ Programmers

C for C++ Programmers C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available

More information

Use the scantron sheet to enter the answer to questions (pages 1-6)

Use the scantron sheet to enter the answer to questions (pages 1-6) Use the scantron sheet to enter the answer to questions 1-100 (pages 1-6) Part I. Mark A for True, B for false. (1 point each) 1. Abstraction allow us to specify an object regardless of how the object

More information

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

Lab # 02. Basic Elements of C++ _ Part1 Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special

More information

CS Exam 2 Study Suggestions

CS Exam 2 Study Suggestions CS 131 - Fall 2009 p. 1 last modified: 11-10-09 CS 131 - * Remember: anything covered in lecture, in lab, or on a homework, is FAIR GAME. * You are responsible for all of the material covered through Week

More information

CSE143 Exam with answers Problem numbering may differ from the test as given. Midterm #2 February 16, 2001

CSE143 Exam with answers Problem numbering may differ from the test as given. Midterm #2 February 16, 2001 CSE143 Exam with answers Problem numbering may differ from the test as given. All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to

More information

CSci 1113 Final. Name: Student ID:

CSci 1113 Final. Name: Student ID: CSci 1113 Final Name: Student ID: Instructions: Please pick and answer any 10 of the 12 problems for a total of 100 points. If you answer more than 10 problems, only the first 10 will be graded. The time

More information

Chapter 2 C++ Fundamentals

Chapter 2 C++ Fundamentals Chapter 2 C++ Fundamentals 3rd Edition Computing Fundamentals with C++ Rick Mercer Franklin, Beedle & Associates Goals Reuse existing code in your programs with #include Obtain input data from the user

More information

Computer Science II Lecture 1 Introduction and Background

Computer Science II Lecture 1 Introduction and Background Computer Science II Lecture 1 Introduction and Background Discussion of Syllabus Instructor, TAs, office hours Course web site, http://www.cs.rpi.edu/courses/fall04/cs2, will be up soon Course emphasis,

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

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

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one

More information

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

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); } 1. (9 pts) Show what will be output by the cout s in this program. As in normal program execution, any update to a variable should affect the next statement. (Note: boolalpha simply causes Booleans to

More information

a data type is Types

a data type is Types Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental

More information

CS 162, Lecture 25: Exam II Review. 30 May 2018

CS 162, Lecture 25: Exam II Review. 30 May 2018 CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you

More information

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 1 COS 126 General Computer Science Spring 2017 Written Exam 1 This exam has 9 questions (including question 0) worth a total of 70 points. You have 50 minutes. Write all answers inside the designated spaces.

More information

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections University of Maryland Baltimore County CMSC 202 Computer Science II Fall 2004 Mid-Term Exam Sections 0201 0206 Lecture Hours: Monday Wednesday 5:30 PM 6:45 PM Exam Date: Wednesday 10/20/2004 Exam Duration:

More information

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03 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.

More information

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):

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): 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): 1. If a function has default arguments, they can be located anywhere

More information

Computer Science II Lecture 2 Strings, Vectors and Recursion

Computer Science II Lecture 2 Strings, Vectors and Recursion 1 Overview of Lecture 2 Computer Science II Lecture 2 Strings, Vectors and Recursion The following topics will be covered quickly strings vectors as smart arrays Basic recursion Mostly, these are assumed

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Review. Relational Operators. The if Statement. CS 151 Review #4

Review. Relational Operators. The if Statement. CS 151 Review #4 Review Relational Operators You have already seen that the statement total=5 is an assignment statement; that is, the integer 5 is placed in the variable called total. Nothing relevant to our everyday

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Programming Language. Functions. Eng. Anis Nazer First Semester

Programming Language. Functions. Eng. Anis Nazer First Semester Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

More loops Ch

More loops Ch More loops Ch 3.3-3.4 Announcements Quiz next week! -Covers up to (and including) HW1 (week 1-3) -Topics: cout/cin, types, scope, if/else, etc. Review: Loops We put a loop around code that we want to run

More information

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;

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; Midterm Practice Problems TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 ENJOY! Problem 1 True False Variable names can begin with an alphabet or a digit. True False

More information

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM CS 103: Introduction to Programming Fall 2017 - Written Final Exam 12/11/16, 4:30PM 6:30PM Name: USC Email Address: Lecture (Circle One): Redekopp 2:00 TTh Goodney: 2 MW 9:30 TTh 11:00 TTh Complete the

More information

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

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017 QUEENS COLLEGE Department of Computer Science CSCI 111 First Midterm Exam Fall 2017 10.18.17 Solutions 09.00am 09.50am, Wednesday, October 18, 2017 Problem 1 (10 points) The following C++ program has errors

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

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

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

EECE.3220: Data Structures Spring 2017

EECE.3220: Data Structures Spring 2017 EECE.3220: Data Structures Spring 2017 Lecture 14: Key Questions February 24, 2017 1. Describe the characteristics of an ADT to store a list. 2. What data members would be necessary for a static array-based

More information

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where

More information

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver) Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program

More information

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

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

CSE 113 A. Announcements - Lab

CSE 113 A. Announcements - Lab CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

C++_ MARKS 40 MIN

C++_ MARKS 40 MIN C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float

More information