Smoking is prohibited 1 CS 101 First Exam Review.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
The If/Else Statement, Boolean Flags, and Menus Page 180
Introduction to C Programming
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CH Programming An introduction to programming concepts.
Selection Structures (if & switch statements) (CS1123)
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
First steps Jordi Cortadella Department of Computer Science.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Programming I Final Exam Review. Question..True or False (Please click on the answer...) Variables hold data that may change while the program.
Chapter#3 Part1 Structured Program Development in C++
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Midterm preview. double int = 2.0; True / FalseThe following is a syntactically correct variable declaration and assignment statement:
1 CS161 Introduction to Computer Science Topic #6.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
CS 240 Computer Programming 1
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Branching statements.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 2 - Introduction to C Programming
Computing Fundamentals
Chapter 2 Assignment and Interactive Input
CSC113: Computer Programming (Theory = 03, Lab = 01)
Chapter 2 - Introduction to C Programming
Operators and Expressions
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Summary Two basic concepts: variables and assignments Basic types:
CS150 Introduction to Computer Science 1
Arithmetic Operations
Chapter 2 - Introduction to C Programming
CS 101 First Exam Review.
Branching statements Kingdom of Saudi Arabia
HNDIT11034 More Operators.
Introduction to C Programming
Presentation transcript:

Smoking is prohibited 1 CS 101 First Exam Review

Smoking is prohibited 2MC-1  The statement that correctly assigns the sum of the two variables “loop_count” and “petrol_cost” to the variable “sum”, is  a.loop_count = sum + petrol_cost;  b.petrol_cost = sum - loop_count;  c.sum = petrol_cost / loop_count;  d.sum = loop_count + petrol_cost;

Smoking is prohibited 3MC-1  The statement that correctly assigns the sum of the two variables “loop_count” and “petrol_cost” to the variable “sum”, is  a.loop_count = sum + petrol_cost;  b.petrol_cost = sum - loop_count;  c.sum = petrol_cost / loop_count;  d.sum = loop_count + petrol_cost;

Smoking is prohibited 4MC-2  Which of these following variable names are valid? 1.3set2.PAY DAY3.bin_2 4.cin5.num-5  a.1, 2 & 4  b.2, 3 & 5  c.2 & 5  d.3 & 4

Smoking is prohibited 5MC-2  Which of these following variable names are valid? 1.3set2.PAY DAY3.bin_2 4.cin5.num-5  a.1, 2 & 4  b.2, 3 & 5  c.2 & 5  d.3 & 4

Smoking is prohibited 6MC-3  The correct statement which divides the variable “t” by the value 10 and stores the result in the variable “d”, is  a.d = t/10;  b.d = 10/t;  c.t = d/10;  d.t = 10/d;

Smoking is prohibited 7MC-3  The correct statement which divides the variable “t” by the value 10 and stores the result in the variable “d”, is  a.d = t/10;  b.d = 10/t;  c.t = d/10;  d.t = 10/d;

Smoking is prohibited 8MC-4  The statement that correctly defines an integer called “sum” is  a.sum : integer;  b.integer sum;  c.int sum;  d.sum int;

Smoking is prohibited 9MC-4  The statement that correctly defines an integer called “sum” is  a.sum : integer;  b.integer sum;  c.int sum;  d.sum int;

Smoking is prohibited 10MC-5  Select the incorrect statement.  a.9 % 4 produce the same output as 4 % 3  b.Z = X - -Y; The same as Z = X - (-Y); The same as Z = X + Y;  c.X*Y < Z+3 is the same as (X*Y) < (Z+3)  d.Assume that x = 7, y = 25, and z = 24.4, then (x != y-18) produces the same output as (x+y != z).

Smoking is prohibited 11MC-5  Select the incorrect statement.  a.9 % 4 produce the same output as 4 % 3  b.Z = X - -Y; The same as Z = X - (-Y); The same as Z = X + Y;  c.X*Y < Z+3 is the same as (X*Y) < (Z+3)  d.Assume that x = 7, y = 25, and z = 24.4, then (x != y-18) produces the same output as (x+y != z).

Smoking is prohibited 12MC-6  Convert  f = e  into a valid C++ assignment.  a.f = a+b / c-d * e;  b.f = (a+b) / (c-d) * e;  c.f = (a+b)/c-d * e;  d.f = a+b / (c-d) * e;

Smoking is prohibited 13MC-6  Convert  f = e  into a valid C++ assignment.  a.f = a+b / c-d * e;  b.f = (a+b) / (c-d) * e;  c.f = (a+b)/c-d * e;  d.f = a+b / (c-d) * e;

Smoking is prohibited 14MC-7  What is the output of the following?  int x = 1, y = 2, z = 3;  cout << 3 / x / (y – x);  a.1  b.2  c.3  d.4

Smoking is prohibited 15MC-7  What is the output of the following?  int x = 1, y = 2, z = 3;  cout << 3 / x / (y – x);  a.1  b.2  c.3  d.4

Smoking is prohibited 16MC-8  What is the output of the following statement?  cout << ((3*4*(5/2-(21%4-1)*2)+1)-1);  a.12  b.-25  c.47  d.24

Smoking is prohibited 17MC-8  What is the output of the following statement?  cout << ((3*4*(5/2-(21%4-1)*2)+1)-1);  a.12  b.-25  c.47  d.24

Smoking is prohibited 18MC-9  How is the following expression is written in C++?  y = 3 x 2 – 2x  a.y = 3 * x + x – 2 + x  b.y = (3 + (x * x)) – (2 + x)  c.y = 3 * x^2 – 2 * x  d.y = 3 * x * x – 2 * x

Smoking is prohibited 19MC-9  How is the following expression is written in C++?  y = 3 x 2 – 2x  a.y = 3 * x + x – 2 + x  b.y = (3 + (x * x)) – (2 + x)  c.y = 3 * x^2 – 2 * x  d.y = 3 * x * x – 2 * x

Smoking is prohibited 20MC-10  Given int a = 7 and int b = 3 then the value of Y will be:  Y = ( a * b % ( a + b +2) – ( a / b) )  a.3  b.7  c.5  d.Non of the answers

Smoking is prohibited 21MC-10  Given int a = 7 and int b = 3 then the value of Y will be:  Y = ( a * b % ( a + b +2) – ( a / b) )  a.3  b.7  c.5  d.Non of the answers

Smoking is prohibited 22MC-11  Choose the right statement.  a.A C++ program that prints 3 lines must contain 3 cout statements.  b.A C++ program that prints 3 lines must contain 2 cout statements.  c.A C++ program that prints 3 lines must contain 1 cout statement.  d.A C++ program that prints 3 lines may contain 1 or more cout statements.

Smoking is prohibited 23MC-11  Choose the right statement.  a.A C++ program that prints 3 lines must contain 3 cout statements.  b.A C++ program that prints 3 lines must contain 2 cout statements.  c.A C++ program that prints 3 lines must contain 1 cout statement.  d.A C++ program that prints 3 lines may contain 1 or more cout statements.

Smoking is prohibited 24MC-12  Which of the following statements is incorrect?  a.The modulus operator (%) can be used only with an integer operand.  b.The arithmetic operators *, /, % all have the same level of precedence.  c.C++ considers the two variables (number and NUMBER) to be identical.  d.None of the above

Smoking is prohibited 25MC-12  Which of the following statements is incorrect?  a.The modulus operator (%) can be used only with an integer operand.  b.The arithmetic operators *, /, % all have the same level of precedence.  c.C++ considers the two variables (number and NUMBER) to be identical.  d.None of the above

Smoking is prohibited 26MC-13  In C++, the expression  1 / % 3 * =  a.1  b.1.5  c.5  d.-1

Smoking is prohibited 27MC-13  In C++, the expression  1 / % 3 * =  a.1  b.1.5  c.5  d.-1

Smoking is prohibited 28MC-14  Statements that the compiler ignore are  a.Selection Statements  b.Loop Statements  c.Include statements  d.Comments

Smoking is prohibited 29MC-14  Statements that the compiler ignore are  a.Selection Statements  b.Loop Statements  c.Include statements  d.Comments

Smoking is prohibited 30MC-15  The statement which correctly assigns the value of the variable “num” to the variable “tot”, is  a.tot := num;  b.num = tot;  c.tot = num;  d.num := tot;

Smoking is prohibited 31MC-15  The statement which correctly assigns the value of the variable “num” to the variable “tot”, is  a.tot := num;  b.num = tot;  c.tot = num;  d.num := tot;

Smoking is prohibited 32MC-16  The correct definition of three variables called x, y, and z, which can hold integer values, is  a.int x, y, z  b.int x, y, z;  c.int x; y; z;  d.int x y z;

Smoking is prohibited 33MC-16  The correct definition of three variables called x, y, and z, which can hold integer values, is  a.int x, y, z  b.int x, y, z;  c.int x; y; z;  d.int x y z;

Smoking is prohibited 34MC-17  Find the errors in the following program?  1.include  1.include  2.int main(  {  3. int x;  4. cout << ”Enter a value for x” << endl;  5. cin > x;  6. x = 5 – 3  7. return 0;  }

Smoking is prohibited 35MC-17  Find the errors in the following program?  1.include  1.include  2.int main(  {  3. int x;  4. cout << ”Enter a value for x” << endl;  5. cin > x;  6. x = 5 – 3  7. return 0;  }

Smoking is prohibited 36MC-18  What are the values of x, y, z, r, s, and t after the code is executed  int x,y,z;float r,s,t;  z=2;y=z-1;x=z+4;  r=x/y;s=r/z;t=z%y;  a.x=4, y=1, z=2, r=2, s=3, t=2.  b.x=6, y=4, z=2, r=6, s=3, t=1.  c.x=6, y=1, z=2, r=6, s=3, t=0.  d.x=4, y=4, z=4, r=2, s=2, t=1.

Smoking is prohibited 37MC-18  What are the values of x, y, z, r, s, and t after the code is executed  int x,y,z;float r,s,t;  z=2;y=z-1;x=z+4;  r=x/y;s=r/z;t=z%y;  a.x=4, y=1, z=2, r=2, s=3, t=2.  b.x=6, y=4, z=2, r=6, s=3, t=1.  c.x=6, y=1, z=2, r=6, s=3, t=0.  d.x=4, y=4, z=4, r=2, s=2, t=1.

Smoking is prohibited 38MC-19  Which of the following is NOT a valid identifier (i.e. CANNOT be used as a name for a variable).  a.phone_number  b.EXTRACREDIT  c.DOUBLE  d.my course

Smoking is prohibited 39MC-19  Which of the following is NOT a valid identifier (i.e. CANNOT be used as a name for a variable).  a.phone_number  b.EXTRACREDIT  c.DOUBLE  d.my course

Smoking is prohibited 40MC-20  What is the output of the following statement? int num = 26; int num = 26; cout << "Here it is." << num << "\nThere it is.";  a.Here it is.There it is.  b.Here it is.26\nThere it is.  c.Here it is.26 There it is.  d.Here it is. 26 There it is.

Smoking is prohibited 41MC-20  What is the output of the following statement? int num = 26; int num = 26; cout << "Here it is." << num << "\nThere it is.";  a.Here it is.There it is.  b.Here it is.26\nThere it is.  c.Here it is.26 There it is.  d.Here it is. 26 There it is.

Smoking is prohibited 42MC-21   Assuming that the user types followed by a return, what is the output of the following code: int num; cout << "Enter a number: "; cin >> num; cout << num;   a.0   b.14   c   d.15

Smoking is prohibited 43MC-21   Assuming that the user types followed by a return, what is the output of the following code: int num; cout << "Enter a number: "; cin >> num; cout << num;   a.0   b.14   c   d.15

Smoking is prohibited 44MC-22   What is the result of the following code: int a = 53; int b = 6; cout << a / b;   a   b9   c.8   d.5

Smoking is prohibited 45MC-22   What is the result of the following code: int a = 53; int b = 6; cout << a / b;   a   b9   c.8   d.5

Smoking is prohibited 46MC-23   The statement that compares the value of an integer called sum against the value 65, and if it is greater, prints the text string "Sorry, try again", is   a.if (sum > "65") cout << "Sorry, try again";   b.if (sum > 65) cout << "Sorry, try again";   c.if (65 == sum) cout << "Sorry, try again";   d.if (sum >= 65) cout << "Sorry, try again";

Smoking is prohibited 47MC-23   The statement that compares the value of an integer called sum against the value 65, and if it is greater, prints the text string "Sorry, try again", is   a.if (sum > "65") cout << "Sorry, try again";   b.if (sum > 65) cout << "Sorry, try again";   c.if (65 == sum) cout << "Sorry, try again";   d.if (sum >= 65) cout << "Sorry, try again";

Smoking is prohibited 48MC-24   The statement that compares total for equality to guess, and if equal prints the value of total, and if not equal prints the value of guess, is   a.if (total = guess) cout << total);   else cout << guess;   b.if (total < guess) cout << total;   else cout << guess;   c.if (total == guess) cout << total;   else cout << guess;   d.if (total == guess) cout << guess;   else cout << total;

Smoking is prohibited 49MC-24   The statement that compares total for equality to guess, and if equal prints the value of total, and if not equal prints the value of guess, is   a.if (total = guess) cout << total);   else cout << guess;   b.if (total < guess) cout << total;   else cout << guess;   c.if (total == guess) cout << total;   else cout << guess;   d.if (total == guess) cout << guess;   else cout << total;

Smoking is prohibited 50MC-25   3.If grade has the value of 50 what will the following code print?  if (grade >= 50) cout << “Passed”;   a.nothing   b.50   c.“Passed”   d.Passed

Smoking is prohibited 51MC-25   3.If grade has the value of 50 what will the following code print?  if (grade >= 50) cout << “Passed”;   a.nothing   b.50   c.“Passed”   d.Passed

Smoking is prohibited 52MC-26   In C++, the condition x > y > z   a.evaluates correctly and could be replaced by (x > y && y > z)   b.generates syntax error and should be replaced by (x > y || y > z)   c.evaluates correctly and could be replaced by (x > y || y > z)   d.generates syntax error and should be replaced by (x > y && y > z)

Smoking is prohibited 53MC-26   In C++, the condition x > y > z   a.evaluates correctly and could be replaced by (x > y && y > z)   b.generates syntax error and should be replaced by (x > y || y > z)   c.evaluates correctly and could be replaced by (x > y || y > z)   d.generates syntax error and should be replaced by (x > y && y > z)

Smoking is prohibited 54MC-27   The AND (&&) operator   a.has less precedence than the OR (II) operator   b.associates from right to left   c.stops evaluation upon finding one condition to be true   d.is a binary operator

Smoking is prohibited 55MC-27   The AND (&&) operator   a.has less precedence than the OR (II) operator   b.associates from right to left   c.stops evaluation upon finding one condition to be true   d.is a binary operator

Smoking is prohibited 56MC-28   The expression if (num != 65) can be replaced by:   a.if (num > 65 && num < 65)   b.if ((num == 65))   c.if (num – 65)   d.if ( !(num – 65))

Smoking is prohibited 57MC-28   The expression if (num != 65) can be replaced by:   a.if (num > 65 && num < 65)   b.if ((num == 65))   c.if (num – 65)   d.if ( !(num – 65))

Smoking is prohibited 58MC-29   What is the output of the following code, assuming that x = 12; if(x = 6) x = x + 1; cout << x;   a.12   b.6   c.7   d.x

Smoking is prohibited 59MC-29   What is the output of the following code, assuming that x = 12; if(x = 6) x = x + 1; cout << x;   a.12   b.6   c.7   d.x

Smoking is prohibited 60MC-30   The statement that tests to see if sum is equal to 10 or total is less than 20, and if so, prints the text string "incorrect.", is   a.if ((sum = 10) && (total < 20)) cout << ”incorrect";   b.if ((sum == 10) && (total < 20)) cout << "incorrect";   c.if ((sum == 10) || (total < 20)) cout << "incorrect";

Smoking is prohibited 61MC-30   The statement that tests to see if sum is equal to 10 or total is less than 20, and if so, prints the text string "incorrect.", is   a.if ((sum = 10) && (total < 20)) cout << ”incorrect";   b.if ((sum == 10) && (total < 20)) cout << "incorrect";   c.if ((sum == 10) || (total < 20)) cout << "incorrect";

Smoking is prohibited 62MC-31   If f is equal 1 and c is not equal an 'X', then assign the value 0 to f, else set f to 1.   a.if ((f == 1) && (c != 'X'))f = 0;   else f = 1;   b.if ((f == 1) && (c <> 'X'))f = 0;   elsef = 1;   c.if ((f = 1) && (c != 'X'))f = 0;   elsef = 1;

Smoking is prohibited 63MC-31   If f is equal 1 and c is not equal an 'X', then assign the value 0 to f, else set f to 1.   a.if ((f == 1) && (c != 'X'))f = 0;   else f = 1;   b.if ((f == 1) && (c <> 'X'))f = 0;   elsef = 1;   c.if ((f = 1) && (c != 'X'))f = 0;   elsef = 1;

Smoking is prohibited 64MC-32   What does the following code fragment print? int h = 13; if (h <= 12) cout << "Low bridge: "; cout << "proceed with caution.";   a.Nothing is written.   b.Low bridge:   c.proceed with caution.   d.Low bridge: proceed with caution.

Smoking is prohibited 65MC-32   What does the following code fragment print? int h = 13; if (h <= 12) cout << "Low bridge: "; cout << "proceed with caution.";   a.Nothing is written.   b.Low bridge:   c.proceed with caution.   d.Low bridge: proceed with caution.

Smoking is prohibited 66MC-33   What is the output of the following code? int x = 0, y = 1, z; if(x)z = 1; else z = 2; if(y) z = 3; else z = 4; cout << z;   a.4   b.3   c.2   d.1

Smoking is prohibited 67MC-33   What is the output of the following code? int x = 0, y = 1, z; if(x)z = 1; else z = 2; if(y) z = 3; else z = 4; cout << z;   a.4   b.3   c.2   d.1

Smoking is prohibited 68MC-34   One of these is a Correct C++ statement   a.if x == 1 cout << x;   b.if (x == 1 ) then cout << x;   c.if (x == 1) cout << x;   d.if (x == 1) cout >> x;

Smoking is prohibited 69MC-34   One of these is a Correct C++ statement   a.if x == 1 cout << x;   b.if (x == 1 ) then cout << x;   c.if (x == 1) cout << x;   d.if (x == 1) cout >> x;

Smoking is prohibited 70MC-35   What is the output of the following code? int a = 7; if(a = 1) { if (a == 22) cout << a; } else cout << a; cout << 88;   a.88   b.788   c.880   d.088

Smoking is prohibited 71MC-35   What is the output of the following code? int a = 7; if(a = 1) { if (a == 22) cout << a; } else cout << a; cout << 88;   a.88   b.788   c.880   d.088