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

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

C++ Final Exam 2017/2018


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.

Name Section: M/W T/TH Number Definition Matching (8 Points)

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

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

CS Spring 05 - MidTerm

Name Section: M/W T/TH Number Definition Matching (6 Points)

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

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

Do not start the test until instructed to do so!

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

EECS 183, Week 5. General. Variables I/O. 0. At which location do you have to take the exam? 1. Source code vs. object code? 2. What s a library?

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

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

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

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

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

Spring 2002 Page 1 of 8 READ THIS NOW!

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

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

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

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

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Definition Matching (10 Points)

Study Guide for Test 2

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

Boolean Algebra Boolean Algebra

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

6. C++ Subprograms David Keil CS I slides 7/03 1

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

Increment and the While. Class 15

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

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

do { statements } while (condition);

If Control Construct

CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad

Chapter 7. Additional Control Structures

1. In C++, reserved words are the same as predefined identifiers. a. True

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

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

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

int x = 5; double y = 3; // Integer division rounds the result down to the nearest whole number. cout << "1a: " << x / 3 << endl; //1

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

CSci 1113 Midterm 1. Name: Student ID:

Test Results Schedule Miscellanea Control Structs. Add l Oper s Break Hands on Q & A Conclusion References Files

Test Bank for Problem Solving with C++: The Object of Programming, 8/e Chapter 2 C++ Basics

SYNERGY INSTITUTE OF ENGINEERING & TECHNOLOGY,DHENKANAL LECTURE NOTES ON DIGITAL ELECTRONICS CIRCUIT(SUBJECT CODE:PCEC4202)

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

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

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

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

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)

Outline. Why do we write functions? Introduction to Functions. How do we write functions? Using Functions. Introduction to Functions March 21, 2006

CSC 222: Computer Programming II. Spring 2004

For questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed

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

Chapter 5 Selection Statements. Mr. Dave Clausen La Cañada High School

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

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

The following expression causes a divide by zero error:

CSCE 2004 Midterm Exam Spring 2017

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

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

CSCE Practice Midterm. Data Types

True or False (14 Points)

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

INTRODUCTION TO COMPUTER SCIENCE - LAB

CSCE 206: Structured Programming in C++

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

Computer Engineering Department CMPE110 Midterm Sample Questions, 2017/ Fall

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!

LAB 4.1 Relational Operators and the if Statement

Name Section: M/W or T/TH. True or False (14 Points)

CS Semester I. Quiz 1 (version A)

REPETITION CONTROL STRUCTURE LOGO

CS242 COMPUTER PROGRAMMING

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

CS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3.

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

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

CSCE Practice Midterm. Data Types

True or False (12 Points)

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

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

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

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

Announcements. Homework 0: using cin with 10/3 is NOT the same as (directly)

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

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

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Review Questions II KEY

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

Topics. Functions. Functions

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

CSCE 121 ENGR 112 List of Topics for Exam 1

Ch 6. Functions. Example: function calls function

Transcription:

CSC1322 Adv Programming in C++ Professor: Zhang Review Summer 2014 Name: Score: Question Points Score 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 10 19 10 20 10 21 15 22 20 Total: 150

1. (5 points) True or False? Every C++ program must have a function named main. 2. (5 points) True or False? If a program compiles successfully, it is guaranteed to execute correctly. 3. (5 points) Which one of the following is not a valid identifier in C++? A. Hi There B. top40 C. UpAnDdOwN D. 4BlindMice E. CAPS 4. (5 points) True or False? The C++ compiler considers the identifier gradepointaverage to be the same as the identifier gradepointaverage. 5. (5 points) Given the following program string st; char ch; int a; cin >> st >> a; cin >> ch; cout << st << ch << a << endl; what is printed with the following as input data to the program? csc 1321 - A. 1321-csc B. csc1321- C. csc-1321 D. -csc1321 E. none of the above Page 2 of 7

6. (5 points) Given the two lines of input data The letters are: ABC what value is read into ch2 by the following code? (variable st is of string and variables ch1 and ch2 are of type char.) getline(cin, st); cin.get(ch1); cin.get(ch2); A. A B. B C. C D. h E. none of the above 7. (5 points) After execution of the following code, what will be the value of angle if the input value is 15? cin >> angle; if (angle > 5) angle = angle + 5; if (angle >= 10) angle = angle + 10; A. 5 B. 10 C. 15 D. 25 E. 30 8. (5 points) This question is about short-circuit evaluation of logical expressions. Consider the following expression in some imaginary programming language (not C++): int n; int k; (n > 5) && (k / n < 20) If n equals 0 when this expression is evaluated, which of the following statements about the expression is true? A. It causes a divide-by-zero error only if the language uses short-circuit evaluation. Page 3 of 7

B. It causes a divide-by-zero error whether or not the language uses short-circuit evaluation. C. It causes a divide-by-zero error only if the language does not use short-circuit evaluation. D. It never causes a divide-by-zero error. 9. (5 points) True or False? The expression n >= 8 is equivalent to the expression!(n < 8). 10. (5 points) What is the termination condition for the following while loop? while (beta > 0 && beta < 10) cout << beta << endl; cin >> beta; A. beta < 0 beta > 10 B. beta > 0 && beta < 10 C. beta <= 0 beta >= 10 D. beta >= 0 && beta <= 10 11. (5 points) Given the following code fragment, cout << A ; for (loopcount = 0; loopcount < 2; loopcount++) cout << B ; cout << C ; The result will be: A. the output AC B. the output ABC C. the output ABBC D. the output ABBBC E. an infinite loop 12. (5 points) After execution of the code fragment Page 4 of 7

char ch = B ; int alpha = 3; switch (ch) case A : alpha = alpha + 10; break; case B : alpha = alpha + 20; case C : alpha = alpha + 30; what is the value of alpha? 13. (5 points) What is the output of the following code fragment if the input value is G? cin >> inputchar; switch (inputchar) case A : cout << 4; break; case G : case Q : cout << 3; case M : cout << 2; break; default : cout << 1; 14. (5 points) Write a for loop that is equivalent to the following while loop. (All variables are of type int.) int count = 0; int sum = 0; while (count < 100) sum = sum + count; count = count + 2; 15. (5 points) What is the output of the following code fragment? (All variables are of type int.) n = 1; for (count = 0; count < 2; count++) while (n < 10) n = 2 * n; cout << n << endl; Page 5 of 7

16. (5 points) What is the output of the following code fragment? loopcount = 1; cout << G ; while (loopcount < 5) if ( loopcount == 4 ) cout << d ; else cout << o ; loopcount++; The result will be: A. the output God B. the output Good C. the output Goood D. the output Gooood E. an infinite loop 17. (5 points) Given the function prototype bool IsGreater( int, int ); which of the following statements use valid calls to the IsGreater function? (The data types of the variables are suggested by their names.) A. someboolean = IsGreater(someInt); B. if (IsGreater(5, someint)) intcounter++; C. while (IsGreater(inputInt, 23)) cin >> inputint; D. b and c above E. a, b, and c above 18. (10 points) If the int variables i, j, and k contain the values 10, 3, and 20, respectively, what is the value of the following logical expression: i < 15 j == 3 && i > k A. false B. true Page 6 of 7

19. (10 points) Given the function definition int Trans(int alpha, int beta ) if (alpha > beta) return alpha + 10; else return 2 * beta; what is printed by the following code? cout << Trans(10, Trans(2, 4)) << endl; 20. (10 points) Are the following two logical expressions equivalent? Hint: Use DeMorgan s law or try some values for beta to verify. a)!(beta < 5 && beta > 10) b)!(beta < 5)!(beta > 10) 21. (15 points) What is the output of the following program? Hint: consider the difference between passing-by-value and passing-by-reference. void foo(int a, int & b) a = 2 * a; b = 3 * b; int main() int a = 5; int b = 10; foo(a, b); cout << a << " " << b << endl; return 0; 22. (20 points) Write a program that finds the sum of the first 100 terms of a series given below. (Hint: C++ power function for x y is pow(x, y) and consider rewriting the series as S = 1 2 1 + 1 2 2 + 1 2 3 +... + 1 2 100 ) S = 1 2 + 1 4 + 1 8 +... Page 7 of 7