PASS$MOCK$EXAM$ $FOR$PRACTICE$ONLY$

Similar documents
ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

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

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.

SYSC Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Using Free Functions

Engineering Problem Solving with C++, Etter/Ingber

SYSC Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Expressions and operators

Increment and the While. Class 15

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Monday, October 30, 6pm - 8pm ME 3380 Thursday, November 2, 6pm - 8pm ME 4499

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

SYSC Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

do { statements } while (condition);

The cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

SYSC 2006 CD. Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

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

Chapter 2. Outline. Simple C++ Programs

Expressions, Input, Output and Data Type Conversions

Pre- Defined Func-ons in C++ Review for Midterm #1

Chapter 3. Numeric Types, Expressions, and Output

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

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

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Chapter Four: Loops II

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

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

Lecture 2:- Functions. Introduction

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

3.1. Chapter 3: The cin Object. Expressions and Interactivity

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

ECET 264 C Programming Language with Applications

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.

Chapter 3 - Functions

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

Class 14. Input File Streams. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

CSCI 111 Midterm 1 Exam Spring Solutions 09.00am 09.50am, Monday, March 21, 2016

A SHORT COURSE ON C++

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

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

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

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

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

PIC 10A. Lecture 3: More About Variables, Arithmetic, Casting, Assignment

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

C++ Programming Lecture 11 Functions Part I

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

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

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

Function. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers

CS2141 Software Development using C/C++ Stream I/O

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10

Lab Instructor : Jean Lai

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

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

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1

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

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

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

Chapter Overview. I/O Streams as an Introduction to Objects and Classes. I/O Streams. Streams and Basic File I/O. Objects

1st and 3rd September 2015

The C++ Language. Arizona State University 1

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

Programming Language. Functions. Eng. Anis Nazer First Semester

Design and Debug: Essen.al Concepts Numerical Conversions CS 16: Solving Problems with Computers Lecture #7

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

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

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

Why Is Repetition Needed?

C Programs: Simple Statements and Expressions

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

Primitive Data Types: Intro

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

Functions and Recursion

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

Computer Programming : C++

DUBLIN CITY UNIVERSITY

DUBLIN CITY UNIVERSITY

C++ Programming Lecture 10 File Processing

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

Scientific Computing

BITG 1233: Introduction to C++

Fundamentals of Programming CS-110. Lecture 2

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. Instructor: Final Exam Fall 2011

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

CS 007A Midterm 1 Practice Chapters 1 5

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Objectives. In this chapter, you will:

pointers + memory double x; string a; int x; main overhead int y; main overhead

9 C Language Function Block

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

Transcription:

PASS$MOCK$EXAM$ $FOR$PRACTICE$ONLY$ Course: ECOR 1606 Facilitator: Dane Levere Dates and locations of take-up: Wednesday April 23 rd, 2014 12:00pm-3:00pm LA C164 IMPORTANT: It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: Complete the midterm in 3 hour(s). Work on your own. Keep your notes and textbook closed. Attempt every question. After the time limit, go back over your work with a different colour or on a separate piece of paper and try to do the questions you are unsure of. Record your ideas in the margins to remind yourself of what you were thinking when you take it up at PASS. The purpose of this mock exam is to give you practice answering questions in a timed setting and to help you to gauge which aspects of the course content you know well and which are in need of further development and review. Use this mock exam as a learning tool in preparing for the actual exam. Please note: Come to the PASS session with your mock exam complete. There, you can work with other students to review your work. Often, there is not enough time to review the entire exam in the PASS session. Decide which questions you most want to review the Facilitator may ask students to vote on which questions they want to discuss. Facilitators do not bring copies of the mock exam to the session. Please print out and complete the exam before you attend. Facilitators do not produce or distribute an answer key for mock exams. Facilitators help students to work together to compare and assess the answers they have. If you are not able to attend the PASS session, you can work alone or with others in the class. Good Luck writing the Mock Midterm!! DISCLAIMER: PASS handouts are designed as a study aid only for use in PASS workshops. Handouts may contain errors, intentional or otherwise. It is up to the student to verify the information contained within. PLEASE NOTE: THIS HANDOUT IS NOT TO BE DISTRIBUTED.$

Question 1 Given the following function: int execute(int x[], int &y, int z){ for (int i = z; i >= 0; i--){ x[i] = y++; z += 1; return z - 2; a) What will be the output if the following code is executed? int b = 0, c = 4, d; int a[5] = {0; d = execute(a, b, c); for (int i = 0; i <= c; i++){ cout << a[i] << " "; cout << endl; b) What will be the output if the following code is executed? int b = 2, c = 3, d; int a[5] = {0; d = execute(a, b, c); c *= 0.8; cout<<b%4 <<""<<c<<""<<d*1.25<<endl; c) What will be the output if the following code is executed? int b = 9, c = 2, d; int a[5] = {0; if ((b % c == 1) ((a[1] + 3 * 2 % 2 == 0) && (a[c] / c == b + 2 * a[b]))){ b = 2; c = 1; else { b = 1; c = 2; d = q1(a, b, c); cout << b << " " << c << " " << d << endl;

d) What will be the output if the following code is executed? double a = 1./3; for (int i = 0; i <= 6; i+=2){ cout << setfill('x') << setprecision(i) << setw(i+2) << ++a << endl; Question 2 Write a function that accepts an array of integer values and the number of values in this array. It should return true if any of the values in the array is the square of one of the other values, and false otherwise Note the "other values". Having a "1" somewhere in the array does NOT guarantee a true result. Your function must be consistent with the sample call below: int values[20];... if (checksquares (values, 20)) {... // one of the values is the square of one of the other values

Question 3 This question involves converting a flowchart into the corresponding C++ code. You are NOT required to produce the program framework or to declare any variables. Simply translate the logic represented by the flowcharts into C++ code.

Question 4 State what is wrong with the following snippets of code (assume all variables and file streams are setup and initialized properly where applicable). Fix the errors, re- writing the code if necessary. a) calculates the sum of numbers stored in a file sum = 0; while (!fin.eof()!fin.fail()){ fin >> input; sum = sum + input; cout << sum << endl; b) Opens file located at: files\data01\data040613.txt and checks for errors ifstream fin; fin.open("files\data01\data040613.txt"); if (fin.fail()){ cout << "FILE ERROR: Unexpected Input\n"; fin.ignore(max_int,'\n'); fin.clear(); c) Asks user for filename and checks for errors cout << Enter a filename: ; cin >> filename; while (cin.fail()){ cout << "Error opening file\n"; cin.clear(); cout << Enter a filename: ; cin >> filename; fin.open(filename);

Question 5 File "data.txt" is supposed to contain between 10 and 100 integer values (inclusive of these limits) and all of the values are supposed to be different (i.e. there should not be any duplicate values). Write a program that reads this file and verifies that it is valid. Your program should terminate after having output exactly one of the following messages:. "File cannot be opened". "File contains bad data". "File contains too many values". "File contains too few values". "File contains at least one duplicate value". "File is OK"

ECOR 1606 Final Lab Test Crib Sheet and Hints (Note: 2 pages long) CONTROL STRUCTURES simple if: if (boolean exp) { statements // body if-then-else: if (boolean exp) { statements // true part else { statements // false part multi-way if: if (boolean exp) { statements // part 1 else if (boolean exp) { statements // part 2 else if (boolean exp) { statements // part 3 // and so on else { // an else part is optional statements // else part while loop (pre-test): while (boolean exp) { statements // body do-while loop (post-test): do { statements // body while (boolean exp); for loop: for (exp1; exp2; exp3) { statements // body is equivalent to: exp1; while (exp2) { same statements exp3; break statement: break; causes an exit from the enclosing loop. continue statement: continue; sends control back to the top of the enclosing loop. CALL BY int sample (int a, int &b); a is call-by-value (just like a regular variable but given a value when the function is called). b is call-by-reference. all operations on b actually operate on the variable supplied. #include <iostream> #include <cmath> #include <iomanip> using namespace std; int add(int x, int y) { int result; result = x + y; return result; int main() { int a, b, c; MODEL PROGRAM cout << Enter two values: ; cin >> a >> b; c = add(a, b); cout << The answer is << c << endl; system( PAUSE ); return 0; EXPRESSIONS < is less than > is greater than <= is less than or equal to >= is greater than or equal to == is equal to!= is not equal to OR (either side is true) && AND (both sides are true)! NOT (changes true to false, false to true) % modulus (gives remainder from division) X++ means use value of X, then increment X X-- means use value of X, then decrement X ++X means increment X, then use new value --X means decrement X, then use new value X += Y is equivalent to X = X + (Y) (same idea for -=, *=. and /=) ECOR 1606 Crib sheet page 1

OUTPUT (use iostream, iomanip) cout << setiosflags(ios::fixed ios::showpoint); // forces use of non-scientific notation and the display of zeroes // to the right of the decimal point. this remains in effect until changed. cout << setprecision(value); // selects the number of digits to be displayed to the right of the decimal point // when outputting double values. the choice remains in effect until changed. cout << setw (value) << // indicates that the next value output is to occupy the specified number of // columns. a one shot deal affects only the next value output cout << setfill(ch); // selects the fill character to be used when padding output values to a specified width. // the choice remains in effect until changed. LIBRARY FUNCTIONS double fabs(double x); returns the absolute value of x, for real numbers int abs(int x); returns the absolute value of x, for integers double log (double x) natural log (log base e) double log10(double x) log base 10 double exp(double x) returns e to power of x double sqrt(double x) returns the square root of x double pow (double x, double y); returns x to the power of y double sin(double x); returns the sine of x (note: x is in radians) double cos(double x); returns the cosine of x (note: x is in radians) double asin(double x); returns the inverse sin of x (in radians) double acos(double x); returns the inverse cosine of x (in radians) double sinh(double x); hyperbolic sin double cosh(double x); hyperbolic cosine Seven Deadly Lab Final Test Sins Stuck? Check that you aren't making any of the following mistakes: 1/. Integer division. (1 / 5) is zero! 2/. Assignments in conditions: if (a = b) { // a disaster 3/. Legal (but nonsensical) logical expressions: if (7 < a < 67) { if ((a b c) == 0) { 4/. Variables with the same name as a function. sin = sin(x); error: sin cannot be used as a function 5/. Missing multiplication operators in expressions. a = b(4 + 7); error: b cannot be used as a function 6/. Variables that are not properly initialized. 7/. Improperly chosen functions. do you have abs where you want fabs? do you have log and where you need log10 (or vice versa)? ECOR 1606 Crib sheet page 2