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

C++ Final Exam 2017/2018

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

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

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

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

Definition Matching (10 Points)

True or False (14 Points)

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

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

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

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

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

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

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

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

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

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

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

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

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

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

CSCE 2004 Midterm Exam Spring 2017

Why Is Repetition Needed?

Spring 2002 Page 1 of 8 READ THIS NOW!

Do not start the test until instructed to do so!

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

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

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

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

CS Spring 05 - MidTerm

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

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

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!

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

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

REPETITION CONTROL STRUCTURE LOGO

Introduction to C++ (Extensions to C)

CHAPTER 3 Expressions, Functions, Output

True or False (15 Points)

Increment and the While. Class 15

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

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

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

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

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

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

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

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

CMPS 221 Sample Final

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil

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

Programming. C++ Basics

CS242 COMPUTER PROGRAMMING

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

Window s Visual Studio Output

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

WARM UP LESSONS BARE BASICS

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array

Chapter 4 - Notes Control Structures I (Selection)

a data type is Types

CS201- Introduction to Programming Current Quizzes

LAB 4.1 Relational Operators and the if Statement

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

True or False (12 Points)

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

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

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

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

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

Loops and Files. of do-while loop

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

Arrays. Week 4. Assylbek Jumagaliyev

Pointers, Dynamic Data, and Reference Types

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

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

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

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

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

The C++ Language. Arizona State University 1

CHAPTER 4 FUNCTIONS. 4.1 Introduction

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

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Computer Programming

CMSC 202 Midterm Exam 1 Fall 2015

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

COMP322 - Introduction to C++

COMPUTER SCIENCE (083)

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

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Looping. Arizona State University 1

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

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

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

C++ Input/Output: Streams

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Transcription:

Consider the following statements. string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is " ". Given the function prototype: float test(int, int, int); which of the following statements is legal? In C++, the scope resolution operator is. Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num++; executes. A variable listed in a function call is known as a(n) parameter. A variable list in a header is known as a(n) parameter. int alpha = 5; int beta = 10; alpha = alpha + 5; { int alpha = 20; beta = beta + 5 ; } cout << alpha << " " << beta << endl ; What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " "; cout << endl; A loop that continues to execute endlessly is called a(n) loop. What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl; After the execution of the following code, what will be the value of num if the input

value is 5? cin >> num; if (num > 0) num = num + 10; else if (num == 5) num = num + 15; Suppose j, sum, and num are int variables, and the input is 26 34 61 4-1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl; Suppose that str1, str2, and str3 are string variables. After the following statements above execute, the value of str3 is " ". str1 = "abc"; str2 = "xyz"; str3 = str1 + '-' + str2; The function is used to interchange the contents of two string variables. In C++, the following character '/0' represents. The value of the expression 17 % 7 is. What is the value of alpha[4] after the following code executes? int alpha[5]; int j; alpha[0] = 2; for (j = 1; j < 5; j++) alpha[j] = alpha[j 1] + 3; A variable listed in a function call is known as a(n) parameter. A variable list in a header is known as a(n) parameter.

Suppose that x is an int variable. Which of the following expressions always evaluates to true? Given int one; double two; bool four; which of the following assignments are valid? (i) one = 7 * 3 % 4; (ii) 2.3 + 3.5 = two; (iii) four = (2 <= 3); What is the value of alpha[2] after the following code executes? int alpha[5]; int j; for (j = 0; j < 5; j++) alpha[j] = 2 * j + 1; Suppose x and y are int variables. Consider the following statements. if (x > 5) y = 1; else if (x < 5) { if (x < 3) y = 2; else y = 3; } else y = 4; What is the value of y if x = 6? Which of the following function prototypes is not valid? int funexp(intx,intv); int funexp(intx,intv){};?????? funexp(void); int funexp(void); Which of the following is NOT a reserved word in C++? int cons?

num?????? Assume all variables are properly declared. What is the output of the following C++ code? num = 100; while (num <= 150) num = num + 5; cout << num << endl; What is the output of the following C++ code? x = 0; if (x < 0) {cout << "One "; cout << "Two ";} cout << "Three"; What is the output of the following C++ code? int x = 1; do { cout << x << " "; x--; } while (x > 0); cout << endl; Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds The declaration int a, b, c; is equivalent to which of the following????? int a;intb;intc; Given the following function prototype: int test(float, char); which of the following statements is valid? Considering the statement string str = "Gone with the wind";, the output of the statement cout << str.find("the") << endl; is.

Which of the following correctly declares and initializes alpha to be an array of 4 rows and 3 columns and the component type is int? Given the function prototype: float test(int, int, int); which of the following statements is legal? Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl; In C++, the scope resolution operator is. Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num++; executes. When the function executes, any changes made to the formal parameters passed by value do not in any way affect the parameters. Which of the following is a relational operator? Suppose x is 5 and y is 0. Choose the value of the following expression: (x!= 7) && (!y) What is the value of x after the following satements execute? int x; x = (5 <= 3 && 'A' < 'F')? 3 : 4; What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6:

alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } Suppose that you have the following function. void mystery(int& one, int two) { int temp temp = one; one = two; two = temp; } What are the values of x and y after the following statements? (Assume that variables are properly declared.) x = 10; y = 15; mystery(x, y); Consider the following statement. int y =!(12 < 5 3 <= 5 && 3 > x)? 7 : 9; What is the value of y if x = 2? Suppose that x = 87 and y = 423. What is the output of the following statements? cout << "12345678901234567890" << endl; cout << setw(5) << x << left << setw(5) << y << setw(7) << "Sunny" << endl; Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3); If a formal parameter is a non-constant reference parameter, its corresponding actual parameter during a function call must be a(n).

Consider the following declaration. char chararray[51]; char discard; Assume that the input is: Hello There! How are you? What is the value of discard after the following statements execute? cin.get(chararray, 51); cin.get(discard);???????? Suppose that x and y are int variables. Which of the following is a valid input statement? The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is. Suppose that namestr is a character array of size 21. Which of the following statement is valid in C++? (i) if (strcmp(namestr, "Lisa") == 0) cout << namestr << endl; (ii) if (namestr[0] == 'L') cout << namestr[0] << endl; Consider the statement int list[10][8];. Which of the following about list is true? Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; Assume that alpha is a character array of size 20. Which of the following statements is illegal in C++?

Answer all questions Q1. Write a one line C++ statement to do the following: a. An infinite while loop, without any statement inside the while loop block, using the expression (x < 10) as the decision maker, not x is declared as in integer?. b. Declare a character array to a store a name of a student of 30 character maximum for 100 students? c. A call to function fctx which return no value- the call passes the array student with is declared as int students (5) (10)? Assume all needed variables are declared". d. In the previous question, what would be the function declaration/header. e. Declares the integer array test- score (100) and initializes only the first element of the array to 10? Q.2. given the following structure that contains the social security number and the year ob birth: Struct into (unsighed long soc sec/num). Unsigned int year birth). a. Write a structure called Boo di that contains the following members: info structure, name of type, string. b. write a function named initialize info that takes no parameters but return a structure of type info in which the social security number is initialized to 5511, the name is initialized to Ahmed, and the year to 1986. c. Write a main function (including all necessary header files and other parameters) to declare an identifier of type Boo di, initialize, Boo Di by calling the function initialize info. - 1 -

Multiple choice: Identify the letter of the choice that best complete the statement or answers the question. 1. Which of the following is not a valid C ++ identifier? a. stop and go. b. salary for the month. c. hello three. d. My counter. 2. which of the following is a reserved word in C++? a. char. b. char. c. CHAR. d. None of these. 3. The value of the C++ expression 14/4 + 4.3 is: a. 7 b. 7.3 c. 7.8 d. none of these. 4. Suppose that alpha is a double variable. What is the value of alpha after the following statement executes: a. alpha 14.0 + static- cast < double> (15/2): a. alpha = 21.0. b. alpha = 21.5. c. alpha = 22.0. d. none of these. - 2 -

5. Suppose that X and y are int variables, ch is a char variable, and the input is 4 2 A 12. What is the value of x, y, and Ch after the following statement executes <in >> x >> ch>>y, a. x = 4, ch = 2, y= 12. b. x 4, ch= A, y = 12. c. x = 4, ch = ', y = 2. d. this statement results in input failure. 6. Suppose that X = 55.68, y = 476,859 and z = 23, 8216, what is the output of the following statement? Cout << fixed<< showpoint. Cout << setprecision (3). Cout << x << << y << setprecision (2) << z << end1". a. 55.680 476,859 23,82. b. 55.690 476, 860 23.82. c. 55.688, 476, 23.82. d. None of these. 7. Suppose that X = 32, y = 62.93, and Z = 781.92. what is the output of the following statements" Cout << fixed<< showpoint. Cout << setprecision (3). Cout << x << << y << setprecision (2) << z << end1". Cout << setprecision (3). a. 123456789102348901234567890. Hi 32 62.93 781.92. b. 123456789012345678901234567890. - 3 -

Hi 32 62.93 781.92. c. 12345678901234567890j. Hi 32 62.93 781. 92. d. None of these. 8. after the execution of the following code, what will be the value of num ifthe input values are 4 5? Cin >> num. If (num > 0). Num = num > 5). Num = num + 15'. a. 4. b. 5. c. 14. d. 15. 9. What is the output of the following C ++ code? Int x = 35, Int y = 45. Int z, If (x > y). Z = x + y1 Else Z = y x Cout << x << " << y <<" << z<< end1". a. 35 45 80. b. 35 45 10. c. 35 45 10. d. none of these. - 4 -

10. What is the output of the following code fragment if the input value is 4? Int num' Int alpha = 10. Cin >> num, Switch (num). Case 3: alpha ++. Break; Case 4: Case 6: alpha = alpha + 3. Case 8: alpha + 4. Break, Default: alpha = alpha + 5'. Cout << alpha << endl' a. 13. b. 14. c. 15. d. 17. - 5 -