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

Similar documents
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.

BITG 1233: Introduction to C++

Chapter 2. Outline. Simple C++ Programs

Engineering Problem Solving with C++, Etter/Ingber

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

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

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

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

Definition Matching (10 Points)

Chapter 3. Numeric Types, Expressions, and Output

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

CSCE 110 PROGRAMMING FUNDAMENTALS

I/O Streams and Standard I/O Devices (cont d.)

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.

LECTURE 02 INTRODUCTION TO C++

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

Getting started with C++ (Part 2)

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

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

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

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

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

2 nd Week Lecture Notes

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Lecture 4 Tao Wang 1

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

CHAPTER 3 Expressions, Functions, Output

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.

Introduction to Programming EC-105. Lecture 2

Chapter 2: Introduction to C++

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

Program Organization and Comments

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

CHAPTER 3 BASIC INSTRUCTION OF C++

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

A First Program - Greeting.cpp

Chapter 2: Overview of C++

The following is a typical execution run of this program:

Expressions, Input, Output and Data Type Conversions

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

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

Introduction to C++ (Extensions to C)

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

Chapter 3 - Notes Input/Output

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

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++

For Teacher's Use Only Q No Total Q No Q No

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

Fundamentals of Programming CS-110. Lecture 2

VARIABLES & ASSIGNMENTS

a. a * c - 10 = b. a % b + (a * d) + 7 =

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity

WARM UP LESSONS BARE BASICS

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

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

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1

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

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

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Example 3. #include <iostream> using namespace std; int main()

Objectives. In this chapter, you will:

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

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

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

The C++ Language. Arizona State University 1

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Chapter 3 - Functions

Programming. C++ Basics

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

Chapter 3: Expressions and Interactivity

Chapter 3 Problem Solving and the Computer

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

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

Functions and Recursion

UNIT- 3 Introduction to C++

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

Computer Programming : C++

PIC 10A. Review for Midterm I

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

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

CS242 COMPUTER PROGRAMMING

Programming Language. Functions. Eng. Anis Nazer First Semester

Computing and Statistical Data Analysis Lecture 3

Introduction to Programming

CS201 Solved MCQs.

Programming with C++ as a Second Language

6.096 Introduction to C++ January (IAP) 2009

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

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

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

Introduction to C++ Systems Programming

C++ Input/Output: Streams

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

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

PROGRAMMING EXAMPLE: Checking Account Balance

Transcription:

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. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag E. boolean C '+' F. none of the above. A -85 E true C '\'' 2. For each of the following determine if it is a valid identifier, and if it is not state why. A. House# not valid, # is not allowed in identifier B. 2nd not valid, identifiers must start with letter or underscore not a number C. WHILE valid D. num4 valid E. double not valid, double is a keyword F. last_name valid 3. Evaluate the following expressions A. (4-7) * 3-9 B. 14 % 4 2 C. 24 / 9 2 D. 6.72 / 4.2 1.6 E. 2 + 8 * 3 + 7 33 4. What is the output of the following program. #include <iostream> #include <iomanip> using namespace std; int main () { int hr, min; hr = 1; min = 50; cout << "The exam is over at " << hr << : << min << endl; cout << "One down\n " << two to go! ; return 0; } The exam is over at 1:50 One down two to go!

5. What is the output of the following program #include <iostream> #include <iomanip> using namespace std; int main() { int WholeNumber; double Real1, Real2; WholeNumber = 76; Real1 = 3.167; Real2 = -24.103; cout << setw(6) << WholeNumber << endl; cout << setiosflags(ios::fixed); cout << setprecision(2) << Real1 << ", " << Real2 << endl; cout << setiosflags(ios::showpoint) << Real2 << 8.376 << endl; return 0; } 76 3.17, -24.10-24.108.38 6. Which of the following are valid on the left side of an assignment operator? A. A numeric constant B. An expression such as 8*6 C. A declared constant D. A variable E. All of the above are valid on the left side of an assignment operator. 7. Which of the following are valid on the right side of an assignment operator? A. A numeric constant B. An expression such as 8*6 C. A declared constant D. A variable E. All of the above are valid on the right side of an assignment operator. 8. The operator >> is used to A. Extract a value from the input stream and assign it to a variable B. Take a value from a variable and place it into the output stream C. Perform integer division and produce the remainder of the division D. Specify that the left hand operand is much larger than the right hand operand. 9. The file which must appear in a #include preprocessor statement if you are using the fabs function is A. iostream B. iomanip C. cmath D. string

10. Which of the following is not a data type used to represent a floating point value A. float B. double C. long double D. short 11. Which of the following is not a syntactically correct declaration? A. int number(12); B. double value1(4.5); value2(3.7); C. double tax_percent =0.06; D. double x{0.0}; E. int x,y,z; 12. Which of the following operators is the increment operator A. += B. + C. % D. ++ 13. Which output flag is set to guarantee that a decimal point will be printed when printing a floating point value? A. fixed B. showpoint C. precision D. setw 14. Function arguments are A. the term used for the name of the function B. the term that refers to the value returned by a function C. the term that refers to the values passed to the function when the function is invoked. D. the term that refers to a function invocation. 15. Which of the following function invocations is an approximation of PI A. atan(-1); B. acos(-1); C. sin(-1); D. cos(-1); 16. Line comments begin with // and run for the rest of the line 17. The purpose of a comment is to help the compiler understand your program and create efficient object code.

18. The math function sin will compute sine when given the angle in degrees 19. The setw manipulator is used to set the field width for all values that are printed until another setw manipulator is encountered. 20. The preprocessor directive #include <iostream> copies the file iostream into the program before compilation, so that the program can use input and output objects and operators. 21. The operand of the increment operator may be either a declared constant or a variable. 22. The math function tan will compute tangent when the angle is given in radians. 23. In a case sensitive language, such as C++, the variables apples and APPLES refer to different storage locations. 24. An expression involving operators can appear after the output operator << in a cout statement. 25. The precision of a floating point number is determined by the number of bits used to represent the exponent. 26. Given the declaration auto i = 0; i is declared as an int. 27. Given the declaration auto i = 1.0; i is declared as type double.

28. C++ is a strongly typed programming language. C. 29. Symbolic constants in C++ are declared with the modifier const; attempting to change the value of a symbolic constant will be flagged as a syntax error by the compiler. 30. Class declarations specify a programmer-defined type/object. 31. Class members may include data (attributes) and methods (functions). 32. Which of the following visibilities by be used to control access to class members: A. public B. protected C. private D. All of these are visibilities used to control access to class members. 33. Class attributes define the operations that may be performed on class objects. 34. Constructors are special methods of a class that are executed when objects of the class type are created. 35. Constructors must have the same name as the class 36. There must be exactly one constructor defined in every class. 37. Once a class is defined, you may use the class as a type specifier.

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. integer 1.427E3 B. double "Oct" C. character -63.29 D. string #Hashtag E. boolean '+' F. none of the above. -85 true '\'' 2. For each of the following determine if it is a valid identifier, and if it is not state why. A. House# B. 2nd C. WHILE D. num4 E. double F. last_name 3. Evaluate the following functions A. (4-7) * 3 B. 14 % 4 C. 24 / 9 D. 6.72 / 4.2 E. 2 + 8 * 3 + 7 4. What is the output of the following program. #include <iostream> #include <iomanip> using namespace std; int main () { int hr, min; hr = 1; min = 50; cout << "The exam is over at " << hr << : << min << endl; cout << "One down\n " << two to go! ; return 0; }

5. What is the output of the following program #include <iostream> #include <iomanip> using namespace std; int main() { int WholeNumber; double Real1, Real2; WholeNumber = 76; Real1 = 3.167; Real2 = -24.103; cout << setw(6) << WholeNumber << endl; cout << setiosflags(ios::fixed); cout << setprecision(2) << Real1 << ", " << Real2 << endl; cout << setiosflags(ios::showpoint) << Real2 << 8.376 << endl; return 0; } 6. Which of the following are valid on the left side of an assignment operator? A. A numeric constant B. An expression such as 8*6 C. A declared constant D. A variable E. All of the above are valid on the left side of an assignment operator. 7. Which of the following is valid on the right side of an assignment operator? A. A numeric constant B. An expression such as 8*6 C. A declared constant D. A variable E. All of the above are valid on the right side of an assignment operator. 8. The operator >> is used to A. Take a value from the input stream an store it into a variable B. Take a value from a variable and place it into the output stream C. Perform integer division and produce the remainder of the division D. Specify that the left hand operand is much larger than the right hand operand. 9. The file which must appear in a #include preprocessor statement if you are using the fabs function is A. iostream B. iomanip C. cmath D. string

10. Which of the following is not a data type used to represent a floating point value A. float B. double C. long double D. short 11. Which of the following is not a syntactically correct declaration? A. int number(12); B. double value1(4.5); value2(3.7); C. double tax_percent =0.06; D. double x{0.0}; E. int x,y,z; 12. Which of the following operators is the increment operator A. += B. + C. % D. ++ 13. Which output flag is set to guarantee that a decimal point will be printed when printing a floating point value? A. fixed B. showpoint C. precision D. setw 14. Function arguments are A. the term used for the name of the function B. the term that refers to the value returned by a function C. the term that refers to the values passed to the function when the function is invoked. D. the term that refers to a function invocation. 15. Which of the following function invocations is an approximation of PI A. atan(-1); B. acos(-1); C. sin(-1); D. cos(-1); 16. Line comments begin with // and run for the rest of the line 17. The purpose of a comment is to help the compiler understand your program and create efficient object code.

18. The math function sin will compute sine when given the angle in degrees 19. The setw manipulator is used to set the field width for all values that are printed until another setw manipulator is encountered. 20. The preprocessor directive #include <iostream> copies the file iostream into the program before compilation, so that the program can use input and output objects and operators. 21. The operand of the increment operator may be either a declared constant or a variable. 22. The math function tan will compute tangent when the angle is given in radians. 23. In a case sensitive language, such as C++, the variables apples and APPLES refer to different storage locations. 24. An expression involving operators can appear after the output operator << in a cout statement. 25. The precision of a floating point number is determined by the number of bits used to represent the exponent. 26. Given the declaration auto i = 0; i is declared as an int. 27. Given the declaration auto i = 1.0; i is declared as a double

28. C++ is a strongly typed programming language.

29. Symbolic constants in C++ are declared with the modifier const; attempting to change the value of a symbolic constant will be flagged as a syntax error by the compiler. 30. Class declarations specify a programmer-defined type/object. 31. Class members may include data (attributes) and methods (functions). 32. Which of the following visibilities by be used to control access to class members: A. public B. protected C. private D. All of these are visibilities used to control access to class members. 33. Class attributes define the operations that may be performed on class objects. 34. Constructors are special methods of a class that are executed when objects of the class type are created. 35. There may be exactly one constructor defined in any class. 36. Constructors must have the same name as the class. 37. Once a class is defined, you may use the class as a type specifier.