Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Similar documents
CSCE 206: Structured Programming in C++

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

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

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

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

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

The C++ Language. Arizona State University 1

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

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

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

Final Exam Solutions PIC 10B, Spring 2016

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

GO MOCK TEST GO MOCK TEST I

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

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

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

2 nd Week Lecture Notes

W3101: Programming Languages C++ Ramana Isukapalli

Introduction to Programming using C++

Tokens, Expressions and Control Structures

CS31 Discussion 1E Spring 17 : week 08

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

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

Perfect square. #include<iostream> using namespace std; int main(){ int a=1; int square; while(true){ } cout<<square<<endl; }

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CMSC 202 Midterm Exam 1 Fall 2015

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

Increment and the While. Class 15

6.096 Introduction to C++ January (IAP) 2009

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

Outline. 1 About the course

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Introduction to Programming EC-105. Lecture 2

A First Program - Greeting.cpp

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

CS242 COMPUTER PROGRAMMING

Fundamentals of Programming CS-110. Lecture 2

LECTURE 02 INTRODUCTION TO C++

Programming. C++ Basics

Chapter Two MULTIPLE CHOICE

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

BOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT. Problem Solving with Computers-I

Bristol Institute of Technology

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter-8 DATA TYPES. Introduction. Variable:

Chapter 2. C++ Basics

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 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.

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

CHAPTER 3 BASIC INSTRUCTION OF C++

Review Questions for Final Exam

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

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

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)

CSCI 1061U Programming Workshop 2. C++ Basics

Your first C++ program

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Outline. Introduction. Pointer variables. Pointer operators. Calling functions by reference. Using const with pointers. Examples.

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Integer Data Types. Data Type. Data Types. int, short int, long int

Chapter 2: Introduction to C++

Relational Operators and if. Class 10

Input And Output of C++

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

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

Spring Semester 16, Dr. Punch. Exam #1 (2/18), form 1 A

Introduction to Computer Science Midterm 3 Fall, Points

CSCE 110 PROGRAMMING FUNDAMENTALS

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

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Chapter 8 - Notes User-Defined Simple Data Types, Namespaces, and the string Type

CS 115 Exam 3, Spring 2010

CS31 Discussion. Jie(Jay) Wang Week8 Nov.18

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

BLM2031 Structured Programming. Zeyneb KURT

CSCI-1200 Computer Science II Fall 2008 Lecture 15 Associative Containers (Maps), Part 2

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

Variables. Data Types.

C++ Quick Reference. switch Statements

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

C++ for Java Programmers

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

Lexical Considerations

Chapter 2: Basic Elements of C++

CS302 - Data Structures using C++

Informatik I (D-ITET) Übungsstunde 9, Hossein Shafagh

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

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

Transcription:

Name: Section: INSTRUCTIONS: (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. (2) The total for the exam is 100 points (3) There are 8 pages with 32 problem; 15 multiple-choice, 15 short answer, and 2 free response. (4) You may skip one multiple-choice and one short answer problem for a total of 5 points. (5) Use the backside of the paper as your scratch paper. The backside is not graded. (6) If you make a mistake, cross it out or erase it. Otherwise, it will be graded, for better or for worse. (7) No electronic devices (e.g. phones, calculators, mp3 players, etc.) are allowed. (8) You are allowed one sheet of notes on Letter paper or smaller. (9) Write your name on the upper-right corner of each page of the exam. (10) To receive full credit, you must write legibly and your answers must be clear. You may need to sketch out answers to less straightforward problems on the scratch side before you write on the front side. (11) Do not leave classroom until you have handed in the exam. (12) The exam lasts 110 minutes

(1) (2 pts) Given the declaration int i = 5; what does i++; return? (a) 0 (b) 5 (c) 6 (d) Undefined (2) (2 pts) For the following code snippet: long lng1 = 10; long & lng2 = lng1 ; What does the & signify? (a) Take the Boolean-and of lng1 and lng2 (b) Treat lng2 like a reference type (c) Extract the memory address of lng2 (d) This expression is illegal (it will not compile) (3) (2 pts) For the following code snippet: long lng1 = 123; long * val = & lng1 ; What does the & signify? (a) Take the Boolean-and of lng1 (b) Treat lng1 like a reference type (c) Extract the memory address of lng1 (d) This expression is illegal (it will not compile) (4) (2 pts) Given the following code snippet: unsigned int my_var = 0; my_var = my_var - 1; Which of the following statements are true? (a) my var has the value -1 (b) my var has the value 0 (c) my var has the value -2,147,483,648 (that is 2 31 ) (d) my var has the value 4,294,967,295 (that is 2 32 1)

(5) (2 pts) Which of the following Unix command line commands will copy a file? (a) copy (b) cp (c) mv (d) c (6) (2 pts) On the command line, the unix command cd.. does what? (a) Print the current directory (b) Select as the current working directory the first child directory (c) Copies all the elements in the current directory to the special cd directory (d) Select as the current directory the parent directory (7) (2 pts) Given the decimal value 17, which of the following statements are true? (a) Hexadecimal equivalent is 0x11 (b) Binary equivalent is 0b10001 (C++14 notation) (c) Octal equivalent is 021 (d) All of the above (8) (2 pts) What is the return type of the expression cout << 14;? (a) No return, a void type (b) long (c) int (d) char (9) (2 pts) Which of the following are true about the terms lvalue and rvalue? (a) An rvalue represents a value (b) An lvalue represents a memory location (c) rvalue is on the right and lvalue is on the left of an assignment statement (d) All of the above

# include < iostream > using std :: cout ; using std :: endl ; using std :: boolalpha ; int main () { cout << boolalpha ; long lng = 2; double dbl = 3.4; long & amp_lng = lng ; long * star_lng = & lng ; cout << amp_lng << endl ; // line 1 cout << (& amp_lng == & lng ) << endl ; // line 2 lng = 4; cout << star_lng << endl ; // line 3 auto result = * star_lng * dbl ; // line 4 cout << result << endl ; // line 5 cout << amp_lng ++ << endl ; // line 6 (10) (2 pts) What is the output produced by Line 1? (a) 0 (b) 1 (c) 2 (d) 4 (11) (2 pts) What is the output produced by Line 2? (a) true (b) false (c) 0 (d) 1

(12) (2 pts) What is the output produced by Line 3? (a) some address (b) 1 (c) 2 (d) 4 (13) (2 pts) What is the type of result on Line 4? (a) long (b) long reference (c) long pointer (d) bool (14) (2 pts) What is the output produced by Line 5? (a) 3.4 (b) 13.6 (c) 6.8 (d) 2.0 (15) (2 pts) What output is produced by Line 6? (a) some address (b) 1 (c) 2 (d) 4

string fn1 ( string arg_s, int cnt ) { for ( int i = 0; i < cnt ; ++ i) { arg_s = arg_s. substr (1) + arg_s [0]; return arg_s ; (16) (3 pts) If s = "abcdef", what is the result of calling fn1(s, 2)? (17) (3 pts) What is the value of s? string fn2 ( string arg_s, char c1, char c2) { string result ; for ( auto ele : arg_s ) { if ( ele < c1) ( ele > c2) result += ele ; return result ; (18) (3 pts) What is the type of ele in fn2? (19) (3 pts) What is the result of calling fn2("abcdefg", c, e )? (20) (3 pts) What is the result of calling fn2("abcdefg", e, c )? long fn3 ( double dbl1, double dbl2 ) { long lng = static_cast < long >( dbl1 ); double r = dbl1 - lng ; if ( r >= dbl2 ) return lng + 1; else : return lng ; (21) (3 pts) What is the result of calling fn3(123.75, 0.5)? (22) (3 pts) What is the result of calling fn3(17.5, 0.5)?

long fn4 ( long lng ) { long result = 0; for ( int i = 1; i <= lng ; ++ i) { if ( lng % i == 0) result += i; return result ; (23) (3 pts) What is the result of calling fn4(12)? (24) (3 pts) What is the result of calling fn4(31)? long fn5 ( long lng ) { long result = 0, r = 0; while ( lng > 0) { r = lng % 10; result += r; lng /= 10; return result ; (25) (3 pts) What is the result of calling fn5(12)? (26) (3 pts) What is the result of calling fn5(31)? long fn6 ( long lng ) { return ( lng % 2)? lng * 2 : lng / 2; (27) (3 pts) What is the result of calling fn6(12)? (28) (3 pts) What is the result of calling fn6(31)?

int fn7 ( int n) { int result = 0; for ( int i = 1; i < n; i += 3) { if (i % 2): result *= 2; else : result += i; return result ; (29) (3 pts) What is the result of calling fn7(9)? (30) (3 pts) In problem 29, how many iterations of the for loop occur?

(31) (15 pts) Write a function IsPalindrome that returns true if and only if its const string& parameter reads the same forward and backward. For example, racecar is a palindrome but neither race nor car are palindromes. You may assume that the input is only alphabetic (you don t need to treat symbols specially). (32) (15 pts) Write a function FizzBuzz that prints out each integer from 1 to parameter n (inclusive) except that if the number is divisible by 3 it prints fizz and if it is divisible by 5 it prints buzz (if it is divisible by both it should print fizzbuzz ). Each number should be printed on a new line.