Computer Engineering Department CMPE110 Midterm Sample Questions, 2017/ Fall
|
|
- Amber Fletcher
- 5 years ago
- Views:
Transcription
1 Computer Engineering Department CMPE110 Midterm Sample Questions, 2017/ Fall Q1) Give the correct answer for following: 1. What is the value of x after the following statement? double x; x = 3.0 / / 4 a b c d What is the correct way to write the condition y < x < z in C++ form? a. (y < x < z) b. ( (y < x) && z) c. ((y > x) (y < z)) d. ((y < x) && (x < z)) 3. What is the output of the following code fragment? int x=0; while( x < 5) cout << x << endl; x ++; cout << x << endl; a. 0 b. 5 c. 4 d. unable to determine 4. Given the following code fragment, which of the following expressions is always true? int x; cin >> x; a. if( x < 3) b. if( x==1) c. if( (x / 3) >1 ) d. if( x = 1) 5. What is wrong with the following switch statement? int ans; cout <<"Type y for yes on n for no\n"; cin >> ans; switch (ans) { case 'y': case 'Y': cout << "You said yes\n"; break; case 'n': case 'N': cout << "You said no\n"; break; default: cout <<"invalid answer\n"; a. ans is an int b. break; is illegal syntax c. nothing d. there are no break statements on 2 cases.
2 6. int a = 5, b = 8, t; t = a;a = b;b = t; cout << a<< ", " << b; A. 5,8 B. 5,5 C. 8,8 D. 8,5 7. int x=5; if( x > 5) cout << "x is bigger than 5. "; cout <<"That is all. "; cout << "Goodbye\n"; a. x is bigger than 5. That is all b. x is bigger than 5 c. That is all. Goodbye d. Goodbye 8. int FD, Year=2019; FD=Year%4 == 0?29 :28; cout<<fd; A. 29 B. 28 C. 1 D int a = 5, b = 8; a = b;b = a; cout << a<< ", " << b; A. 5,8 B. 5,5 C. 8,8 D. 8,5 Q2) Consider the code given below. Show its output and explain what does the code do? Output: #include <iostream>. int main(){ int x; The main function of this code is for(x=325;x > 0; x /= 10). {cout<< (x % 10);
3 Q3) Write a program that reads the radius (r) and the height (h) of a cylinder and then computes its volume and surface area. volume r 2 h surface area 2 r h 2 r The volume and the surface area are computed as Note: Let all variables be of type float. A sample run of the code should be as Enter the radius: 6.5 Enter the height: 9.5 The volume = The surface area = #include<iostream> int main(){ //declare the variables // write necessary statements to read the radius from keyboard // write necessary statements to read the height from keyboard // perform the required operations // show the outputs on the monitor
4 Q4) What is the output of the following code segments: I/ int Year; cout<< Enter a year: ; cin>> year; FebDays=year%4 == 0?29 :28; cout<< FebDays= << FebDays; II/ int grade; cout<< Enter your Grade: ; cin>> grade; if(grade >= 60) {cout<< You passed << endl; cout<< Congratulations\n ; else; cout<< You failed << endl; cout<< SORRY\n ; Enter a year: Enter your grade: III/ Section II may contain logical error(s). If any, introduce your correction(s) on the code segment. Q5) What is the output of the following code segments: 1. int i, j=2; for(i=3; i<=8; i+=2) {j+=i; if (j>6) break; cout<< J= <<j; 2. int i, Sum=2; for(i=3; i<=10; i+=2) {if (i%3==0) continue; Sum+=i; cout<< Sum= <<Sum;
5 Q6) The following code segment is designed to read the age of a person, and display his/her class as shown in the given table. Fill in the blanks to complete the required task. A sample run of the code is: int Age; cout<< How old are you? ; cin>>age; switch(.){ case 0 :.. case 1 : case 2 :.. case 3 :.. case 4 : case 5 : case 6 : case 7 : case 8 : case 9 : case 10: case 11: How old are you? 18 You are a teenager case 12:.. default:.. Age Class 0 4 Baby 5 14 Child Teenager Adult above Old 64 Q7) Write the equivalent C++ condition to implement the following statements. Statement Equivalent C++ condition x greater than 0 and not more than 10 x is even and y is odd x is outside the interval [-5,20] X and y are less than or equal to 30
6 Q8) The following flowchart is designed to read from the keyboard the Grades of N students in CMPE110 course, and then it computes and prints on the monitor the minimum grade and the average grade. Implement this flowchart in C++ language. Note: let variable average be of type double, and other variables are of type integer. BEGIN READ N i = 1 Min=100 Sum=0 Design your code to have the following sample run: Enter number of students (N): 3 Enter grade of student 1: 18 Enter grade of student 2: 19 Enter grade of student 3: 17 The minimum grade is 17 The average grade is 18.0 i <= N True READ Grade Sum+=Grade Grade < Min True Min=Grade i = i + 1 False Average=sum/N Print Min Print Average False END #include<iostream> int main(){
7 Q9) Complete the following code that reads two integer numbers (N1 and N2) and then finds the sum of all integers, between N1 and N2, that can be divided by 5 without a reminder. Do not include in the sum those integers that are divided by 3 without a reminder. Note: first, you should find the minimum and the maximum of N1 and N2. For example, if N1=23 and N2=4, then the program should find Min=4, Max=23 and then prints on the monitor: Sum = 35 ( , 15 is not included because it can be divided by 3 without a reminder). #include <iostream> int main(){int N1, N2, Min, Max,i, Sum=0; cin>>n1>>n2; // Find the minimum (Min) and the maximum (Max) of N1 and N // Find the required sum..... // Print the result on the monitor cout<< Sum = << Sum;
8 Q10) Consider the following code: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 #include<iostream> int main(){ int Digit; cin>>digit; switch(digit) {case 0 : case 1 : cout<<"this digit is a binary."; default: cout<<"this digit is not a binary."; A/ Trace this code for the following input: Input Output 2 1 B/ This code may contain logical error(s), indicate which line(s), and if any, give below the correct one(s) Line(if any) should be Q11) Write a program that reads the lengths of two sides of a triangle (SideA, SideB) and the angle between them (A) and calculates the length of the third side (SideC) using the following formula: SideC SideA SideB SideA SideB A 2 2 = 2 cos( ) Note: The angle A is entered from keyboard in degree and should be translated into A radian as A= 180 #include <iostream> #include <cmath> // define the constant with the name of PI and value of int main(){// Variable declarations. // read SideA and SideB and angle A from keyboard. // tranlate the angle A into radian. // compute SideC. // print SideC on monitor.
9 Q12) It is required to write a code to read from the keyboard the lab (Lab), the midterm (Mid), and the final (Final) points of a student and then computes his letter grade (Lgrade). Let the letter grades be computed as Total point (Tpoint) Letter grade 85 Tpoint 100 A 75 Tpoint < 85 B 65 Tpoint < 75 C 55 Tpoint < 65 D Otherwise F where Tpoint is computed from the Lab, the Mid, and the Final points according to the following weights: Lab 10 % Midterm 40 % Final 50 % Complete the following code to do the above task. #include <iostream> int main(){ // Declaration.. // Get the input from the keyboard cin>>lab>>mid>>final; // Compute Total point (Tpoint). // Compute Letter Grade (Lgrade) // Display Letter grade on monitor cout<< Your letter grades is << Lgrade;
10 Q13) Write a C++ code that reads two integer numbers and one operator (+, -, *, /, %) and then perform the required operation. Note: If the user enters a wrong operator, then your code should display wrong operator as an output. Write the code using switch selective structure (do not use if/else). A sample run of the code must be as follows: *** Calculator Problem *** Enter two numbers: 4 3 Enter one operator: = 7 *** Calculator Problem *** Enter two numbers: 4 3 Enter one operator: > Wrong operaor #include <iostream> int main(){ // Declaration.. // Get the input from the keyboard.... // Perform the required task
11 Q14) Re-write the following if/else using switch statement: if(digit==0) cout<< ZERO ; else if(digit==1) cout<< ONE ; else cout<< Not a Binary Digit ; Q15) Re-write the following if/else using conditional expression operator (?:) if(number % 2 = = 0) cout<< EVEN Number ; else cout<< ODD Number ; a) Re-write the following if/else using switch statement: if(digit==0 Digit==1) cout<< Binary ; else cout Not Binary ; b) Re-write the following code using for-loop: year=1900; sum=0; while(year<=4002) { sum+=year; cout<<"year="<<year; year+=sum; Q16) Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distances. The formula for computing the distance (d) is d ( x x ) ( y y ) Note you can use pow(a,0.5) to compute a. Let all variables be of type double. Here is a sample run: Enter x1 and y1: Enter x2 and y2: 4 5 The distance of the two points is
12 Q17)The following FLOWCHART computes the area of a triangle. Write the corresponding C++ code. BEGIN READ A, B,C True False A+B>C and B+C>A and C+A>B P = A + B + C S =P/2 Area = PRINT Not Triangle PRINT Area End #include <iostream> #include <cmath> int main(){ double A,B,C,P,S, Area;
13 Q18) a) Given int i = 4, j = 3, k = 6, m = 4; what is the output of i * = j + k; cout<< i= <<i; b) Given int i = 4, j = 3, k = 6, m = 4; what is the output of k =++m+ 5; cout<< k= <<k; c) Find the result of the following expressions: Expression Result 6 >= 4 >= 2 (double) (10/4) / (int) 2.5 int a=4, b=7; a++ * --b 7!=4!=1 int year=2016; year%4 == 0? 29 :28; d) Show the output of the following code segments: A/ int x1=1, x2=1, i, y, z; float f; y = 5 + x1--; z = x2; i=35/10; f = 10./4 * i; cout << "Y= " << y << endl; cout << "Z = " << z << endl; cout << "F= " << f; B/ char ch = 'b'; switch (ch) {case 'a': case 'A': cout << ch << endl; break; case 'b': case 'B': cout << ch << endl; case 'c':
14 case 'C': cout << ch << endl; break; case 'd': case 'D': cout << ch << endl; C/ bool even = false; cout << (even? "true" : "false") << endl; Q19) Consider the definition of the following f(x) function. Write a code read x, and then calculate and display the value of f(x). The value of input x must be entered from keyboard. x 3 if x < 50 f(x) = { x 2 if 50 x < 100 x/2 if x = otherwise
15 Q20) Trace the following programs and write the output in the space provided below. int k=0, x=0; int k=0, m=0, x=0; for (k=1; k<7; ++k) { if (k%3 == 1) x=x+k; else x- -; cout<< x<<endl; { for (k=1; k<4; ++k) for (m=0; m<k; ++m) { if (k%2 == 0) x++; else x- -; cout<< x<<endl; Output: Output: int k=0, x=0; int k=5, x=0; { while (k<5) switch ( (k+x) % 4 ) { case 0: case 1: x = x + 2; break; case 2: x = x - 1; break; default: x = x * 2; cout<< x<<endl; k++; do { if (x==1) x=0; else if (x==2) x=2; else x=3; cout<< x<<endl; x- -; k- -; while (k>=0); Output: Output:
CMPE110, Sample questions
CMPE110, Sample questions Number : Name :... Q1)Give the correct answer for following: 1. What is the value of x after the following statement? double x; x = 3.0 / 4.0 + 3 + 2 / 4 a. 5.75 b. 4.25 c. 1.75
More informationBoolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;
Programming in C++ If Statements If the sun is shining Choice Statements if (the sun is shining) go to the beach; True Beach False Class go to class; End If 2 1 Boolean Data Type (false, ) i.e. bool bflag;
More informationSelection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Selection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING MULTIPLE SELECTION To solve a problem that has several selection, use either of the following method: Multiple selection nested
More information3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)
Structures Programming in C++ Sequential Branching Repeating Loops (Repetition) 2 1 Loops Repetition is referred to the ability of repeating a statement or a set of statements as many times this is necessary.
More informationLAB 4.1 Relational Operators and the if Statement
LAB 4.1 Relational Operators and the if Statement // This program tests whether or not an initialized value of num2 // is equal to a value of num1 input by the user. int main( ) int num1, // num1 is not
More informationTest Bank for Problem Solving with C++: The Object of Programming, 8/e Chapter 2 C++ Basics
TRUE/FALSE 1. In the following code fragment, x has the value of 3. int x = 3; ANSWER: TRUE 2. The body of a do-while loop always executes at least once. ANSWER: TRUE 3. The body of a while loop may never
More information1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?
Instructions: This homework assignment focuses primarily on some of the basic syntax and semantics of C++. The answers to the following questions can be determined from Chapters 6 and 7 of the lecture
More informationSuperior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II
Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.7 User Defined Functions II Prepared for By: Name: ID: Section: Semester: Total Marks: Obtained Marks:
More informationINTRODUCTION TO COMPUTER SCIENCE - LAB
LAB # O2: OPERATORS AND CONDITIONAL STATEMENT Assignment operator (=) The assignment operator assigns a value to a variable. X=5; Expression y = 2 + x; Increment and decrement (++, --) suffix X++ X-- prefix
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
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. B. Outputs to the console a floating point number f1 in scientific format
More informationBEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1
BEng (Hons) Electronic Engineering Cohort: BEE/10B/FT Resit Examinations for 2016-2017 / Semester 1 MODULE: Programming for Engineers MODULE CODE: PROG1114 Duration: 3 Hours Instructions to Candidates:
More informationLab # 02. Basic Elements of C++ _ Part1
Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special
More informationECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.
It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: Complete the midterm in 1.5 hour(s). Work on your own. Keep your notes and textbook closed. Attempt every question.
More informationCS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1
CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1 Those questions do not imply any favorite subject or question type for the questions in the actual exam Please also
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More informationCSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018
QUEENS COLLEGE Department of Computer Science CSCI 111 First Midterm Exam Spring 2018 03.14.18 Solutions 09.05am 09.55am, Wednesday, March 14, 2018 Problem 1 Write a complete C++ program that asks the
More informationNumber: Name-Surname :... Group:...
COMPUTER ENGINEERING DEPARTMENT CMPE110 Midterm Exam, 2017-2018 Fall Instructors: O. Ramadan (01) and C. Ergun (02) Date: 24/11/2017 Duration: 100 min. Number: Name-Surname :... Group:... Q1 Q2 Q3 Q4 Q5
More informationThe American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011
The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS
More informationClass 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)
Class 2: Variables and Memory Variables A variable is a value that is stored in memory It can be numeric or a character C++ needs to be told what type it is before it can store it in memory It also needs
More information5. Selection: If and Switch Controls
Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation
More informationComputer Programming : C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program
More informationStructured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1
ELEC 330 1 Structured Programming Control Structures ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne Algorithm Development Conditional Expressions Selection Statements Loops 206_C3
More informationWARM UP LESSONS BARE BASICS
WARM UP LESSONS BARE BASICS CONTENTS Common primitive data types for variables... 2 About standard input / output... 2 More on standard output in C standard... 3 Practice Exercise... 6 About Math Expressions
More informationA First Program - Greeting.cpp
C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout
More informationProgramming Language. Functions. Eng. Anis Nazer First Semester
Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities
More informationThe sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.
CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationCSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015
QUEENS COLLEGE Department of Computer Science CSCI 111 Midterm 1, version A Exam Fall 2015 10.13.15 Solutions 09.00am 09.50am, Tuesday, October 13, 2015 Problem 1 Write a complete C++ program that does
More informationIntroduction to Algorithms and Programming (COMP151)
Introduction to Algorithms and Programming (COMP151) A Student's Manual for Practice Exercises Dr. Mohamed Aissa m.issa@unizwa.edu.om 11i13 Summer 2014 Practice Exercises #1 Introduction Page 2 Practice
More informationCS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015
CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:
More informationLaboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++
Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It
More information2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization?
1 2. ARRAYS 1. What is an Array? Arrays are used to store a set of values of the same type under a single variable name. It is a collection of same type elements placed in contiguous memory locations.
More informationCSci 1113 Midterm 1. Name: Student ID:
CSci 1113 Midterm 1 Name: Student ID: Instructions: Please pick and answer any 7 of the 9 problems for a total of 70 points. If you answer more than 7 problems, only the first 7 will be graded. The time
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More information1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?
Exercises with solutions. 1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl? #include b) What using statement do you always put at the top of
More informationIntroduction to Programming EC-105. Lecture 2
Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically
More informationCSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017
QUEENS COLLEGE Department of Computer Science CSCI 111 First Midterm Exam Fall 2017 10.18.17 Solutions 09.00am 09.50am, Wednesday, October 18, 2017 Problem 1 (10 points) The following C++ program has errors
More informationCSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York
CSc 10200 Introduc/on to Compu/ng Lecture 8 Edgardo Molina Fall 2011 City College of New York 18 The Null Statement Null statement Semicolon with nothing preceding it ; Do-nothing statement required for
More informationProgramming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester
Programming Language Control Structures: Selection (switch) Eng. Anis Nazer First Semester 2018-2019 Multiple selection choose one of two things if/else choose one from many things multiple selection using
More informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationBy 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
1 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 variables. Apply C++ syntax rules to declare variables, initialize
More informationCS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay
CS 101 Computer Programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building Bombay Lecture 4, Conditional execution of instructions Friday, August
More informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationChapter 3 Problem Solving and the Computer
Chapter 3 Problem Solving and the Computer An algorithm is a step-by-step operations that the CPU must execute in order to solve a problem, or to perform that task. A program is the specification of an
More informationLOGO BASIC ELEMENTS OF A COMPUTER PROGRAM
LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM Contents 1. Statements 2. C++ Program Structure 3. Programming process 4. Control Structure STATEMENTS ASSIGNMENT STATEMENTS Assignment statement Assigns a value
More informationProgramming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1
300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard
More informationLoops and Files. of do-while loop
L E S S O N S E T 5 Loops and Files PURPOSE PROCEDURE 1. To introduce counter and event controlled loops 2. To work with the while loop 3. To introduce the do-while loop 4. To work with the for loop 5.
More informationCMPE Experiment 3 Selective Structures
Page1 CMPE 108 - Experiment 3 Selective Structures OBJECTIVES: Understand how to edit, compile and execute C computer codes. Understand C programming: sequential and selective structures NOTES: You should
More informationI SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.
I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK 70. a) What is the difference between Hardware and Software? Give one example for each. b) Give two differences between primary and secondary memory.
More informationOther operators. Some times a simple comparison is not enough to determine if our criteria has been met.
Lecture 6 Other operators Some times a simple comparison is not enough to determine if our criteria has been met. For example: (and operation) If a person wants to login to bank account, the user name
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationint n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;
Debugging Some have said that any monkey can write a program the hard part is debugging it. While this is somewhat oversimplifying the difficult process of writing a program, it is sometimes more time
More informationCS 115 Exam 3, Spring 2010
Your name: Rules You must briefly explain your answers to receive partial credit. When a snippet of code is given to you, you can assume o that the code is enclosed within some function, even if no function
More informationWeek 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.
Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than
More informationC++ Final Exam 2017/2018
1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationProblem Solving: Storyboards for User Interaction
Topic 6 1. The while loop 2. Problem solving: hand-tracing 3. The for loop 4. The do loop 5. Processing input 6. Problem solving: storyboards 7. Common loop algorithms 8. Nested loops 9. Problem solving:
More informationChapter 2: Overview of C++
Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in
More informationControl Structures. Lecture 4 COP 3014 Fall September 18, 2017
Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More information4.1. Chapter 4: Simple Program Scheme. Simple Program Scheme. Relational Operators. So far our programs follow a simple scheme
Chapter 4: 4.1 Making Decisions Relational Operators Simple Program Scheme Simple Program Scheme So far our programs follow a simple scheme Gather input from the user Perform one or more calculations Display
More informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationBENG (HONS) ELECTRONIC ENGINEERING BENG (HONS) TELECOMMUNICATIONS. Cohort: BEE/10A/FT, BEE/10B/FT &BTEL/10B/FT
BENG (HONS) ELECTRONIC ENGINEERING BENG (HONS) TELECOMMUNICATIONS Cohort: BEE/10A/FT, BEE/10B/FT &BTEL/10B/FT Special Resit Examinations for September 2014 MODULE: PROGRAMMING FOR ENGINEERS MODULE CODE:
More informationThe Hyderabad Public School, Begumpet, Hyderabad, A.P
The Hyderabad Public School, Begumpet, Hyderabad, A.P. 500 016 2012-13 Department of Computer Science Class 8 Worksheet 3 1) How many times will the following statement execute? ( ) int a=5; while(a>6)
More informationComputer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:
Computer Department Program: Computer Midterm Exam Date : 19/11/2016 Major: Information & communication technology 1 st Semester Time : 1 hr (10:00 11:00) Course: Introduction to Programming 2016/2017
More informationProgramming in C++ The manager of a company. Lecture Notes 6. Functions (Procedures) 4/24/2018. he he he. Does Does Does
The manager of a company Programming in C++ Lecture Notes 6 Functions (Procedures) Does Does Does he he he pay the bills? answer the phone? clean the office? 2 1 Division of Labor Our programs until now
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection) Control Structures A computer can proceed: In sequence Selectively (branch) - making
More informationIn this chapter you will learn:
1 In this chapter you will learn: Essentials of counter-controlled repetition. Use for, while and do while to execute statements in program repeatedly. Use nested control statements in your program. 2
More informationWrite a program that displays all the even integers between 1 and 100, inclusive
Write a program that displays all the even integers between 1 and 100, inclusive for(int i=1;i
More informationCHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad
CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING Dr. Shady Yehia Elmashad Outline 1. Introduction to C++ Programming 2. Comment 3. Variables and Constants 4. Basic C++ Data Types 5. Simple Program: Printing
More informationUnit 7. 'while' Loops
1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment
More informationdo { statements } while (condition);
Topic 4 1. The while loop 2. Problem solving: hand-tracing 3. The for loop 4. The do loop 5. Processing input 6. Problem solving: storyboards 7. Common loop algorithms 8. Nested loops 9. Problem solving:
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where
More informationOutline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types
Data Types Declarations and Initializations Larry Caretto Computer Science 16 Computing in Engineering and Science February 7, 25 Outline Review last week Meaning of data types Integer data types have
More informationLoops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017
Loops! Loops! Loops! Lecture 5 COP 3014 Fall 2017 September 25, 2017 Repetition Statements Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The
More informationConsider 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,
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationconditional statements
L E S S O N S E T 4 Conditional Statements PU RPOSE PROCE DU RE 1. To work with relational operators 2. To work with conditional statements 3. To learn and use nested if statements 4. To learn and use
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationStarting Out With C++: Early Objects, Seventh Edition Solutions to End-of-Chapter Review Questions
Starting Out With C++: Early Objects, Seventh Edition Solutions to End-of-Chapter Review Questions Chapter 1 1. programmed 12. key 2. CPU 13. programmer-defined symbols 3. arithmetic logic unit (ALU) and
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationThe American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011
The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science Instructor: Final Exam Fall 2011 Last Name :... ID:... First Name:... Section No.: EXAMINATION
More informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: 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): 1. The basic commands that a computer performs are input (get data), output (display result),
More information5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationCHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad
CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad Outline 1. The if Selection Structure 2. The if/else Selection Structure 3. The switch Multiple-Selection Structure 1. The if Selection
More informationBITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)
BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17) 1 Learning Outcomes At the end of this lecture, you should be able to: 1. Explain the concept of selection control structure
More informationCHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++
CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,
More informationProgramming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3
Programming - 1 Computer Science Department 011COMP-3 لغة البرمجة 1 011 عال- 3 لطالب كلية الحاسب اآللي ونظم المعلومات 1 1.1 Machine Language A computer programming language which has binary instructions
More informationCMSC 202 Midterm Exam 1 Fall 2015
1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.
More informationEngineering Problem Solving with C++, Etter/Ingber
Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input
More informationAdd Subtract Multiply Divide
ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient
More informationMore Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4
More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4 Ziad Matni Dept. of Computer Science, UCSB Administrative CHANGED T.A. OFFICE/OPEN LAB HOURS! Thursday, 10 AM 12 PM
More informationCMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING
CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING Aims 1. Learning primary functions of Microsoft Visual Studio 2008 * 2. Introduction to C++ Programming 3. Running C++ programs using
More informationCSE030 Fall 2012 Final Exam Friday, December 14, PM
CSE030 Fall 2012 Final Exam Friday, December 14, 2012 3-6PM Write your name here and at the top of each page! Name: Select your lab session: Tuesdays Thursdays Paper. If you have any questions or need
More information