CSCE 2004 Midterm Exam Spring 2017

Similar documents
CSCE 2014 Final Exam Spring Version A

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types

CSCE 2004 Final Exam Spring Version A

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

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.

LAB 4.1 Relational Operators and the if Statement


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

Introduction to Computer Science Midterm 3 Fall, Points

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

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

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

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

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

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

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

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

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

CSCE 206: Structured Programming in C++

Multiple Choice (Questions 1 13) 26 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)

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

CSci 1113 Midterm 1. Name: Student ID:

CS Spring 05 - MidTerm

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

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

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

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

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

Arrays in C++ Instructor: Andy Abreu

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

1st Midterm Exam: Solution COEN 243: Programming Methodology I

Question 2. [5 points] Given the following symbolic constant definition

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

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

C++ Final Exam 2017/2018

CMSC 202 Midterm Exam 1 Fall 2015

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

Reviewing all Topics this term

Exam 3 Chapters 7 & 9

CS242 COMPUTER PROGRAMMING

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

Definition Matching (10 Points)

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

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

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

EECS402 Lecture 02. Functions. Function Prototype

Name. Classes and Objects 1. We re going to develop a class to help out Café Below is the definition for a class called

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Write a program that displays all the even integers between 1 and 100, inclusive

Spring 2002 Page 1 of 8 READ THIS NOW!

University of Toronto

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

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

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013

Boolean Algebra Boolean Algebra

Largest Online Community of VU Students

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

Final Exam. Name: Student ID: Section: Signature:

System Design and Programming II

The University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters.

CSE 5A Final Fall 2006

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

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

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Variable Definitions and Scope

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

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

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

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

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

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

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

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Add Subtract Multiply Divide

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

Programming in C++ The manager of a company. Lecture Notes 6. Functions (Procedures) 4/24/2018. he he he. Does Does Does

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

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

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Introduction to Programming I COS1511 School of Computing Revision Notes

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

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)

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

Introduction to Programming

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

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

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Chapter 3 Problem Solving and the Computer

Transcription:

CSCE 2004 Midterm Exam Spring 2017 Student Name: Student UAID: Instructions: This is a 50 minute exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers are not allowed. Reminder: This class is governed by the code of ethics of the College of Engineering and Department of Computer Science and Computer Engineering. Any instances of cheating will result in a grade of zero on the exam and referral to the ethics board. Page 1

Consider the following C++ variables: float Num1 = 10; int Num2 = 5; float Num3 = 2; Expressions [1 point] What is the value of: (1+2+3) / Num1 [1 point] What is the data type of this expression? [1 point] What is the value of: (Num2 + 2 * 5-4) [1 point] What is the data type of this expression? [1 point] What is the value of: (Num3 * 2) + 5 / 2 [1 point] What is the data type of this expression? [1 point] What is the value of: Num1 * Num2 + Num3 [1 point] What is the data type of this expression? Consider the following C++ code: float Num1 = (1 + 2 + 3); int Num2 = 5 / 2.0; [1 point] What is value stored in variable Num1? [1 point] What is value stored in variable Num2? Page 2

If Statements Consider the problem of choosing a place to rent based on your monthly budget and the number of roommates you are planning to live with. If you have over $2,000, rent a house to share with 3 roommates. If you have over $1,500, rent a 2 bedroom apartment with 1 roommate. If you have over $1,000, rent a 1 bedroom apartment by yourself. If you have under $1,000, rent your parent s basement. The following C++ code implements this decision process: float Money = 0.0; int Roommates = 0; cin >> Money >> Roommates; if ( condition 1 ) cout << "Rent a house and throw big parties\n"; else if ((Money > 1000) && (Roommates == 0)) cout << "Rent a one bedroom apartment\n"; else if ( condition 2 ) cout << "Rent a two bedroom apartment\n"; else if (Money < 1000) cout << "Rent your parent's basement\n"; else cout << "Sorry, no advice\n"; [5 points] What should condition 1 be? a) (Money > 2000) b) (Money > 2000) && (Roommates!= 0) c) (Roommates >= 0) && (Roommates <= 3) && (Money > 2000) d) (Money > 2000) && (0 <= Roommates <= 3) e) None of the above. [5 points] What should condition 2 be? a) (Money > 1500) (Roommates < 2) b) (0 <= Roommates <= 1) c) (Money * Roommates == 1500) d) (Roommates == 1) && (Money > 1500) e) None of the above. Page 3

Consider the following C++ code, which is intended to calculate the cost of an item after tax has been added. Notice that different tax rates are applied based on prices. float Tax1 = 0.05; float Tax2 = 0.10; float Price = 0.0; float Cost = 0.0; cin >> Price; if (Price > 5000.0) Cost = Price + Price * Tax2; else if (Price > 3000.0) Cost = Price + Price * Tax1; else Cost = Price; cout << "Cost:" << fixed << setprecision(2) << Cost << endl; [5 points] Assume that the user enters 10000 for the Price. What does this program print for the value of Cost? a) 10500.00 b) 10000.00 c) 0.00 d) 11000.00 e) None of the above. [5 points] Assume that the user enters 2000 for the Price. What does this program print for the value of Cost? a) 2200.00 b) 2000.00 c) 0.00 d) 2100.00 e) None of the above. Page 4

Loops [5 points] How many times will the following loop display Hi Mom!? for (int i = 10; i >= 0; i--) cout<<" Hi Mom!"<<endl; i--; a) 5 b) 6 c) 10 d) 11 e) None of the above. [5 points] What is the output of the following code segment? int n = 1; while (n <= 5 n > 0) cout << n << ' '; n++; a) 1 2 3 4 5 b) 1 1 1... and so on forever c) 1 2 3 and so on forever d) 1 2 3 4 e) 2 3 4 5 6 Page 5

[5 points] What will the following code display? int x = 0; for (int count = 4; count > 0; count--) x = x + count; cout << x << ; a) 4 3 2 1 b) 4 7 9 10 c) 4 d) 10 e) none of the above [5 points] Consider the following code. What is the final value of x? int x, y; x = 1; while (x < 40) for (y = 0; y <= 20; y = y+10) x = x + y; a) 1 b) 21 c) 40 d) 41 e) none of the above Page 6

Function Prototypes [10 points] For this question, your task is to write function prototypes (the first line of the function that gives the return type and the list of parameters) that match the comments below. You do NOT have to fill in the function bodies. // This function takes in a letter grade between A and F and // calculates the corresponding grade point value between 0.0 and 4.0. // The answer is returned by the function. GetGradePoint ( ); // This function takes in two integer numbers and calculates their difference. // The answer is returned by the function. CalculateDifference ( ); // This function prints a message and asks the user their shoe size. // The answer is stored in a floating point reference parameter. GetShoeSize ( ); // This function exchanges the values of two character reference parameters. // The function does not return any value. Exchange ( ); // This function takes in one floating point number and calculates the cube root. // The answer is stored in a floating point reference parameter. CubeRoot ( ); Page 7

Calling Functions [10 points] Assume we have the following variables and function prototypes. Which of the function calls below are correct (they compile without errors or warnings, and the return values and parameters are used properly) and which function calls are incorrect? Circle your answer. // Variable declarations int A, B; float X, Y, Z; char C, D; // Function prototypes void ReadChar(char & ch); int GetMin (int Num1, float Num2); float FindSum (float A, float B); cout << ReadChar (); ReadChar (C); cin >> ReadChar (); cout << GetMin (2, 3); A = GetMin (Num1, Num2); GetMin (A, B, C); B = GetMin(A+2, B-1); FindSum (X, Y, Z); Z = FindSum (X, Y); FindSum (X-Y, Y-Z); Page 8

Tracing Functions Consider the following three C++ functions. void silly (int &U, int &V) cout << U << " " << V << endl; if (U < V) int temp = U; U = V; V = temp; cout << U << " " << V << endl; int goofy (int X, int Y, int Z) cout << X << " " << Y << " " << Z << endl; silly (X, Y); silly (Y, Z); cout << X << " " << Y << " " << Z << endl; return Z; int main() // Part A int U = 6; int V = 8; silly (U, V); // Part B int Result = goofy (7, 1, 2); cout << "Result: " << Result << endl; return(0); Page 9

[5 points] Using the box method, trace the execution of Part A in the program above to show the sequence of function calls, the values of parameters, and return values. What will the Part A section of the code print? [5 points] Using the box method, trace the execution of Part B in the program above to show the sequence of function calls, the values of parameters, and return values. What will the Part B section of the code print? Page 10