CSCE 206: Structured Programming in C++

Similar documents
CSCE 206: Structured Programming in C++

Chapter Two MULTIPLE CHOICE

CSCE 206: Structured Programming in C++

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

BITG 1233: Introduction to C++

LECTURE 02 INTRODUCTION TO C++

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

VARIABLES & ASSIGNMENTS

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

The C++ Language. Arizona State University 1

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

Chapter 2: Introduction to C++

2 nd Week Lecture Notes

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

CHAPTER 3 BASIC INSTRUCTION OF C++

A First Program - Greeting.cpp

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.

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

Getting started with C++ (Part 2)

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

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

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

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

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

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

Introduction to C++ (Extensions to C)

Introduction to Programming EC-105. Lecture 2

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!

Chapter 1 INTRODUCTION

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

Fundamentals of Programming CS-110. Lecture 2

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

Programming. C++ Basics

Programming with C++ as a Second Language

Lecture 3 Tao Wang 1

CS101 PLEDGED SPRING 2001

Understanding main() function Input/Output Streams

Chapter 2: Overview of C++

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

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

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Expressions, Input, Output and Data Type Conversions

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

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

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.

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

Objectives. In this chapter, you will:

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

Chapter 1 Introduction to Computers and Programming

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

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

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

Definition Matching (10 Points)

Computer Programming : C++

UNIT- 3 Introduction to C++

CSCI 1061U Programming Workshop 2. C++ Basics

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

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

Introduction to Programming

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

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

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

Chapter 1 Introduction to Computers and C++ Programming

CSCE Practice Midterm. Data Types

This watermark does not appear in the registered version - Slide 1

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

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

Lecture 2 Tao Wang 1

Chapter 2 - I know what I want to do NOW WHAT? Student Learning Outcomes (SLOs)

CSCE 110 PROGRAMMING FUNDAMENTALS

Exercise 1.1 Hello world

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.

CS2255 HOMEWORK #1 Fall 2012

CS242 COMPUTER PROGRAMMING

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Programming. Computer. Program. Programming Language. Execute sequence of simple (primitive) instructions What instructions should be provided?

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

Spring 2002 Page 1 of 8 READ THIS NOW!

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

CSCI 123 Introduction to Programming Concepts in C++

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

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

Software Design & Programming I

Chapter 4 - Notes Control Structures I (Selection)

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

Chapter 2. Outline. Simple C++ Programs

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

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

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

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

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

Fundamentals of Structured Programming

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

Transcription:

CSCE 206: Structured Programming in C++ 2017 Spring Exam 1 Monday, February 13, 2017 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam, count the pages to make sure you have all 11. Read the questions and instructions carefully to see what kind of answer is expected. Put the Exam Code on your scantron in the lower right corner There are 50 questions worth 2 points each. On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Signature: Name (Print): UIN: Section: 1

TR UE/FALSE: Select A if the statement is true and B if the statement is false. 1) In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision. 2) The preprocessor reads a C++ program before it is compiled and only executes those lines beginning with a # symbol 3) Arithmetic operators that share the same precedence have right to left associativity. 4) 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. 5) When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive. 6) On a computer it is required that long integers are at least as big as integers 7) In C++, when an operator is working with operands of different types, it strives to convert the operands to the same type through demotion. 8) cin automatically converts the data read from the keyboard to the data type of the variable used to store it (assume data is reasonable). 9) Machine language is an example of a high-level language. 10) The output of the following program is A #include <iostream> #include <string> using namespace std; main() { char letter; letter = "A"; cout<<letter; } 11) When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear before the decimal point. 12) Escape sequences are always stored internally as two consecutive characters 2

13) Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs. 14) A variable called "average" that stores the average of N numbers should be declared as an integer data type because it will probably hold data that contains decimal places. 15) The following statement will output $7.00 to the screen: cout << setprecision(7) << dollars << endl; MULTIPLE CHOICE: Choose the the single option that best completes the statement or answers the question. 16) When a relational expression is false, it has the value. A. one B. zero C. zero, one, or minus one D. less than zero 17) In the process of translating a source file into an executable file, which of the following is the correct sequence? A. Source code, preprocessor, modified source code, compiler, object code, linker, executable code. B. Source code, preprocessor, modified source code, linker, object code, compiler, executable code. C. Preprocessor, source code, compiler, executable code, linker, modified source code, object code. D. Source code, compiler, modified source code, preprocessor, object code, linker, executable code. E. Source code, linker, object code, compiler, modified source code, preprocessor, executable code. 18) 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 3

19) A variable declaration announces the name of a variable that will be used in a program, as well as: A. The type of data it will be used to hold B. The operators that will be used on it C. The number of times it will be used in the program D. The area of the code in which it will be used 20) What will the value of x be after the following statements execute? int x; x = 22.0 / 4; A. 5.5 B. 5 C. 2 D. 0. 21) Programmer-defined names of memory locations that may hold data while the program is run are: A. Operators B. Variables C. Syntax D. Operands 22) You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written? A. cin << length, width, height; B. cin.get(length, width, height); C. cin >> length >> width >> height; D. cin >> length, width, height; E. cin << length; width; height; 23) Which statement will read an entire line of input into the following string object? string name; A. cin << name; B. cin name; C. getline(cin, name); D. cin.get(name); 4

24) What is the value of number after the following statements execute? int number = 7; number += 5; number -= 2; number *= 4; A. 4 B. 30 C. 40 D. 2 25) 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 26) This function tells the cin object to skip one or more characters in the keyboard buffer. A. cin.remove() B. cin.jump() C. cin.hop() D. cin.skip() 27) What is the output of the following program: int main() { int x = 5, y = 20, z = 10; z *= x + y * x; cout << z; return 0; } A. 150 B. 100 C. 1050 D. 300 E. Compiler Error 5

28) What will the value of x be after the following statements execute? int x = 1; int y = 4; int z = 3; x = y + z * 2 % (z + y); A. 10 B. 14 C. 0 D. 2 E. Compiler error 29) Which character signifies the beginning of an escape sequence? A. // B. / C. \ D. # E. { 30) A set of well-defined steps for performing a task or solving a problem is known as a(n): A. Hierarchy B. Machine Code C. Central Processing Unit D. Encoded instruction E. Pseudocode 31) These are data items whose values do not change while the program is running. A. Literals B. Variables C. Comments D. Integers 6

32) What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << "\n" << "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 33 ) Every complete C++ program must have a. A) Comment B) Function named main C) Preprocessor directive D) Symbolic constant E) cout statement 34) What is the value of cookies after the execution of the following statements? int number = 38, children = 47, cookies; cookies = number % children; A. 38 B. 47 C. 0.81 D. 1.24 7

35) Which one of the following would be an illegal variable name? A. dayofweek B. 21YearsOld C. _employee_num D. June1997 E. itemsorderedforthemonth 36) When this operator is used with string operands it concatenates them, or joins them together. A. & B. * C. % D. + 37) In C++ the == operator indicates: A. equality B. assignment C. subtraction D. negation 38) Which statement is equivalent to the following? number += 2; A. number = number + 2; B. number + 2; C. number = 2; D. number + 2; E. number = number + number; 39) Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line? A) if code is equal to C cout << "This is a check\n"; B) if (code = "C") cout << "This is a check" << endl; C) if (code == 'C') cout << "This is a check\n"; D) if (code == C) cout << "This is a check" << endl; E) None of these 8

40) Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } A. 6 B. 7 C. 8 D. 9 41) Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 3; A. 0 B. -1 C. -2 D. -3 42) At the heart of a computer is its central processing unit. The CPU's job is: A. To fetch instructions B. To carry out the operations commanded by the instructions C. To produce some outcome or resultant information D. All of the above 43) If a program produces incorrect answer when run, it is due to A. Syntax errors B. Logic errors C. Compiler errors D. Linker errors 9

44) Characters or symbols that perform operations on one or more operands are: A. Syntax B. Op codes C. Operators D. Program ops 45) Which of the following best describes an operator? A. An operator is a rule that must be followed when constructing a program. B. An operator allows you to perform operations on one or more pieces of data. C. An operator marks the beginning or ending of a statement, or is used to separate items in a list. D. An operator is a word that has a special meaning. E. An operator is a symbolic name that refers to a variable. 46) What is the value stored at x, given the statements: int x; x = 6 / static_cast<int>(4.5 + 5.5); A..6 B. 0 C..275229 D. 3.3 47) are used to translate each source code instruction into the appropriate machine language instruction. A. Modules B. Library routines C. Compilers D. Preprocessor directives 48) What is the output of the following statement: cout << 8 % 4 * (15 / (1 + 3)) << endl; A. 15 B. 6 C. 7.5 D. 8 10

49) Relational operators allow you to numbers. A. add B. multiply C. compare D. average 50) What is the output of the following program: #include <iostream> #include <string> using namespace std; int main() { string firstname; string lastname; firstname = "John "; lastname = "Jacobs"; cout << "My name is " << firstname + lastname <<'\n'; return 0; } A. John B. Jacobs C. John Jacobs D. Compiler error 11