Chapter Two MULTIPLE CHOICE

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Chapter 2: Introduction to C++

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

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

CHAPTER 3 BASIC INSTRUCTION OF C++

The C++ Language. Arizona State University 1

BITG 1233: Introduction to C++

LECTURE 02 INTRODUCTION TO C++

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Chapter 2: Basic Elements of C++

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

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

2 nd Week Lecture Notes

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

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

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Objectives. In this chapter, you will:

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

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

Lecture 2 Tao Wang 1

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

UNIT- 3 Introduction to C++

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

6.096 Introduction to C++ January (IAP) 2009

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

4. Inputting data or messages to a function is called passing data to the function.

Chapter 2 Basic Elements of C++

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Your First C++ Program. September 1, 2010

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

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

CSc Introduction to Computing

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

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

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

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

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

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

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

Chapter 2. C++ Basics

Chapter 1 Introduction to Computers and C++ Programming

Introduction to Programming

Computer Programming : C++

Chapter 2, Part I Introduction to C Programming

Understanding main() function Input/Output Streams

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Programming in C++ 4. The lexical basis of C++

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

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

Your first C++ program

1. C++ Overview. C++ Program Structure. Data Types. Assignment Statements. Input/Output Operations. Arithmetic Expressions.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

UNIT-2 Introduction to C++

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

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

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

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

Chapter 2. Lexical Elements & Operators

Typescript on LLVM Language Reference Manual

A First Program - Greeting.cpp

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

UEE1302 (1102) F10: Introduction to Computers and Programming

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio

EEE145 Computer Programming

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Chapter 2: Overview of C++

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

Introduction to C# Applications

Full file at C How to Program, 6/e Multiple Choice Test Bank

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

Visual C# Instructor s Manual Table of Contents

The Warhol Language Reference Manual

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Fundamentals of Programming Session 4

Engineering Problem Solving with C++, Etter/Ingber

Java Basic Datatypees

download instant at Introduction to C++

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

C++ Programming Basics

Chapter 2: Using Data

LEXICAL 2 CONVENTIONS

Creating a C++ Program

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

Input And Output of C++

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

7 Arrays. 7.1 Arrays Hold Multiple Values TOPICS. CONCEPT: An array allows you to store and work with multiple values of the same data type.

Getting started with C++ (Part 2)

Manual. Subject Code: CS593. Computer Science and Engineering

Lecture 3 Tao Wang 1

CHAPTER-6 GETTING STARTED WITH C++

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

Variables. Data Types.

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

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

Transcription:

Chapter Two MULTIPLE CHOICE 1. In a C++ program, two slash marks ( // ) indicate: a. The end of a statement b. The beginning of a comment c. The end of the program d. The beginning of a block of code 2. A statement that starts with a # is called a: a. Comment b. Function c. Preprocessor directive d. Key word. 3. For every opening brace in a C++ program, there must be a: a. String literal b. Function c. Variable d. Closing brace 4. The is/are used to display information on the computer's screen. a. Opening and closing braces b. Opening and closing quotation marks c. cout object d. Backslash 5. The causes the contents of another file to be inserted into a program. a. Backslash b. Pound sign c. Semicolon d. #include directive 6. represent storage locations in the computer's memory. a. Literals b. Variables c. Comments d. Integers

7. These are data items whose values do not change while the program is running. a. Literals b. Variables c. Comments d. Integers ANS: A 8. You must have a for every variable you intend to use in a program. a. purpose b. definition c. comment d. constant 9. Of the following, which is a valid C++ identifier? a. June1997 b. _employee_number c. department d. myextralongvariablename e. All of the above are valid identifiers. ANS: E 10. The numeric data types in C++ can be broken into two general categories: a. numbers and characters b. singles and doubles c. integer and floating point d. real and unreal 11. Besides decimal, two other number systems you might encounter in C++ programs are: a. Octal and Fractal b. Hexadecimal and Octal c. Unary and Quaternary d. Base 7 and Base 9 12. A character literal is enclosed in quotation marks, whereas a string literal is enclosed in quotation marks. a. double, single b. triple, double c. open, closed d. single, double

13. In memory, C++ automatically places a at the end of string literals. a. Semicolon b. Quotation marks c. Null terminator d. Newline escape sequence 14. Which escape sequence causes the cursor to move to the beginning of the current line? a. \n b. \t c. \a d. \b e. \r ANS: E 15. What is the modulus operator? a. + b. * c. & d. % e. 16. Which data type typically requires only one byte of storage? a. short b. int c. float d. char e. double 17. What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl; a. 15 b. 12 c. 63 d. 72 e. None of these 18. In programming terms, a group of characters inside a set of quotation marks is called a: a. String literal b. Variable c. Operation d. Statement

ANS: A 19. This is used to mark the end of a complete C++ programming statement. a. Pound Sign b. Semicolon c. Data type d. Void 20. Which character signifies the beginning of an escape sequence? a. // b. / c. \ d. # e. { 21. must be included in any program that uses the cout object. a. Opening and closing braces b. The header file iostream c. Comments d. Escape sequences 22. If you use a C++ key word as an identifier, your program will: a. Execute with unpredictable results b. not compile c. understand the difference and run without problems d. Compile, link, but not execute 23. In the C++ instruction, cookies = number % children; given the following declaration statement: int number = 38, children = 4, cookies; what is the value of cookies after the execution of the statement? a. 2 b. 0 c. 9 d..5 e. None of these ANS: A

24. This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires. a. len b. bytes c. f(x) d. int e. sizeof ANS: E 25. Character constants in C++ are always enclosed in. a. [brackets] b. "double quotation marks" c. 'single quotation marks' d. {braces} e. (parentheses) 26. These are used to declare variables that can hold real numbers. a. Integer data types b. Real data types c. Floating point data types d. Long data types 27. The float data type is considered precision, and the double data type is considered precision. a. single, double b. float, double c. integer, double d. short, long ANS: A 28. A variable whose value can be either true or false is of this data type. a. binary b. bool c. T/F d. float. 29. How would you consolidate the following declaration statements into one statement? int x = 7; int y = 16; int z = 28; a. int x = 7; y = 16; z = 28;

b. int x = 7 y = 16 z = 28; c. int x, y, z = 7, 16, 28 d. int x = 7, y = 16, z = 28; e. None of these will work 30. A variable's is the part of the program that has access to the variable. a. data Type b. value c. scope d. reach 31. Every complete C++ program must have a. a. comment b. function named main c. preprocessor directive d. symbolic constant e. cout statement 32. This control sequence is used to skip over to the next horizontal tab stop. a. \n b. \h c. \t d. \a e. \' 33. Which one of the following would be an illegal variable name? a. dayofweek b. 3dGraph c. _employee_num d. June1997 e. itemsorderedforthemonth 34. Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payrate, grosspay; 10 11 hours = 40;

12 payrate = 20.0; 13 grosspay = hours * payrate; 14 cout << "My gross pay is $" << grosspay << endl; 15 return 0; 16 } Which line(s) in this program cause output to be displayed on the screen? a. 13 and 14 d. 13 b. 8 and 9 e. 15 c. 14 35. Which of the following defines a double-precision floating point variable named paycheck? a. float paycheck; c. paycheck double; b. double paycheck; d. Double paycheck; 36. What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday"; a. Monday Tuesday Wednesday c. MondayTuesdayWednesday b. Monday Tuesday Wednesday d. "Monday" "Tuesday" "Wednesday" 37. What will the following code display? int number = 7; cout << "The number is " << "number" << endl; a. The number is 7 c. The number is7 b. The number is number d. The number is 0 38. What will the following code display? int x = 0, y = 1, z = 2;

cout << x << y << z << endl; a. 0 1 2 c. xyz b. 0 d. 012 1 2 39. What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl; a. Four score and seven years ago b. Four score and seven years ago c. Four score and seven years ago d. Four score and seven years ago ANS: A 40. What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl; a. Four score and seven yearsago b. Four score and seven years ago c. Four score and seven/nyearsago d. Four score and seven yearsago

41. What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl; a. Four score and seven years ago b. Four score and seven years ago c. Fourscoreandsevenyearsago d. Fourscore andseven yearsago 42. Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable? a. letter = Z; c. letter = Z ; b. letter = Z ; d. letter = (Z); 43. What will the value of x be after the following statements execute? int x; x = 18 / 4; a. 4.5 c. 0 b. 4 d. unknown 44. What will the value of x be after the following statements execute? int x; x = 18.0 / 4; a. 4.5 c. 0

b. 4 d. unknown ANS: A 45. What will the value of x be after the following statements execute? int x; x = 18 % 4; a. 0.45 c. 2 b. 4 d. unknown 46. Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William" a. 7 c. 8 b. 14 d. 1 47. The first step in using the string class is to #include the header file. a. iostream b. cctype c. cmath d. string 48. Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object? a. name = Jane; c. name = Jane ; b. name = Jane ; d. name = (Jane); TRUE/FALSE 1. When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive. ANS: T

2. A preprocessor directive does not require a semicolon at the end. ANS: T 3. The C++ language requires that you give variables names that indicate what the variables are used for. ANS: F 4. A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places. ANS: F 5. Escape sequences are always stored internally as a single character. ANS: T 6. Floating point constants are normally stored in memory as doubles. ANS: T 7. C++ does not have a built in data type for storing strings of characters. ANS: T 8. If you do not follow a consistent programming style, your programs will generate compiler errors. ANS: F