PROBLEM 1 : (Vocabulary: 12 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the contex

Size: px
Start display at page:

Download "PROBLEM 1 : (Vocabulary: 12 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the contex"

Transcription

1 Test 1: CPS 53.2 Owen Astrachan October 6, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 12 pts. grade Problem 2 14 pts. Problem 3 5 pts. Problem 4 6 pts. Problem 5 9 pts. Problem 6 10 pts. Problem 7 10 pts. Problem 8 15 pts. Problem 9 15 pts. Problem 10 extra TOTAL: 10 pts. 96 pts. 1

2 PROBLEM 1 : (Vocabulary: 12 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context of computer science, programming, and C/C I/O streams (a) a thought process in which ideas are immediately transformed to programs (b) standard classes that are used for input and output of both built-in and user-dened types (c) a contiguous collection of homogeneous elements supporting random access 2. formal parameters (a) the parameters that occur in a function call as opposed to in a function header (b) the parameters that occur in a function header as opposed to in a function call (c) parameters with well-dened names that are indicative of their purpose 3. loop guard (a) the boolean expression whose truth determines if a loop body is executed (b) a programming device that protects against innite loops (loops that execute forever) (c) a term used to describe the evaluation of the expression (a && b) in which bisnot evaluated if a is false. 4. return statement (a) the line in a Makele that returns control to the user (b) a statement that returns (a value) from a function (c) the hidden statement that the compiler inserts in a for loop to ensure that the loop begins execution again after the increment part of the for loop is executed PROBLEM 2 : (Header les: 14 points) For each function, type, or class on the left, list the header le needed for its use. All header les are not used and a header le can be listed more than once. If no header le is needed (e.g., the type is built-in) put 0. sqrt 0. no header le needed cin 1. iostream.h String 2. math.h pow 3. String.h cout 4. heart.h double 5. nput.h Heart 6. ctype.h char 7. stdio.h 2

3 PROBLEM 3 : (Heart Monitor: 5 points) In the program you wrote that sensed a simulated heart and administered a shock if the heart was beating too rapidly or too slowly, a message similar to the following was printed: heart shocked after 20 senses However, if a \bad" voltage reading occurred (outside the range,10::10), and the program heartmon.cc ignores such bad readings in determining the period during which zero-crossings are counted, a message might appear such as heart shocked after 23 senses where the 23 indicates that the heart was sensed 23 times, but your program only acknolwedged 20 as legitimate senses. Explain (briey) why your program could not avoid such counts as 23 being printed even though your program was ignoring these senses in determining zero-crossings. PROBLEM 4 : (Grades: 6 points) The following lines appear in a program designed to compute student grade point averages: gpa = pointtotal/numcourses; cout << "number of courses = " << numcourses << endl; cout << "student GPA = " << gpa << endl; if (gpa >= SUMMA_CUTOFF){ cout << "summa cum laude graduate" << endl; Part A Assume a gpa of 3.75 is needed to graduate summa cum laude, write an appropriate denition for the identier SUMMA_CUTOFF. Part B The registrar notices that only students with 4.0 averages are graduating summa cum laude and that the only gpa's actually printed are 1.0, 2.0, 3.0, and 4.0; i.e., no one has a gpa with a fractional part such as 3.63 the registrar thinks that there is an error in the program. The programmer claims the program is correct because the variable gpa is of type double. The registrar is correct, the program has a small error. Briey describe why the only gpa's printed are 1.0, 2.0, 3.0, and 4.0, and a simple x that will cause \correct" gpa's to be printed. 3

4 PROBLEM 5 : (Debugging: 9 points) The quadratic formula is used to nd roots of quadratic equations of the form ax 2 + bx + c formula is:,b p b 2, 4ac the 2a For example, the roots of the equation x 2 +2x,15 are -5 and 3 (substituting these values for x yields 0) and the formula simplies as:,2 p 2 2, 4(1)(,15) 2(1) =,2 p 64 2 =,2 8 2 =,5 or3 The following C++ function is designed to print the roots of a quadratic equation whose coecients are specied by the parameters a, b, and c; it does not work as intended. void QuadRoots(double a, double b, double c) //precondition: a,b,c, are coefficients of a quadratic equation // which has roots //postcondition: roots of equation ax^2 + bx + c are computed and printed { double discriminant = sqrt(b*b - 4*a*c); double root1 = -b - discriminant/(2*a); double root2 = -b + discriminant/(2*a); cout << "roots are " << root1 << " and " << root2 << endl; Part A: The call: QuadRoots(1,2,-15) should result in the message roots are -5.0 and 3.0 being printed as described above. When run, however, the procedure generates as output roots are -6.0 and 2.0 Briey describe the error in QuadRoot or indicate in the code how to x it so that the correct values will be printed. Part B: On a computer system the call QuadRoots(2,3,4) generates the error message: floating point exception: bus error A programmer adds an output statement just before the denition of root1 as shown below, but no output appears before the error message is printed. cout << "disc = " << discriminant << endl; double root1 = -b - discriminant/(2*a); 4

5 Describe why the error message appears and one possible method for xing the code so that no error message is generated. Part C: It is possible to change the function QuadRoots so that rather than printing the roots, the values of the roots are returned via parameters so that the sequence of statements: QuadRoots(1,2,-15,r1,r2); cout << "roots = " << r1 << " and " << r2 << endl; would result in printing the roots of the equation x 2 +2x,15. Describe the changes in the function QuadRoots that are needed for it to work in this manner. PROBLEM 6 : (Sum: 10 points) You are to complete a code segment that will permit the user to enter integers until the integer 0 is entered. After the numbers are entered the sum of the negative integers entered should be printed. For example: enter a number> 3 enter a number> 4 enter a number> -5 enter a number> 7 enter a number> -2 enter a number> -1 enter a number> 8 enter a number> 0 sum of negative numbers = -8 The code segment is partially given below: int num; cin >> num; while (num!= 0) { cout << "sum of negative numbers = " << negsum << endl; 5

6 PROBLEM 7 : (Change: 10 points) You are to write a function ChangeChar that changes all occurrences of a specic character in a string to another character. For example, if str represents the string \daddy", the call ChangeChar(str,'d','p') would change str so that it represents the string \pappy". Assume that variables of type String support a Length method. Complete the procedure below, be sure all parameters are properly specied. void ChangeChar(,char oldchar, char newchar) 6

7 PROBLEM 8 : (Diving: 15 points) You have been contracted to write a C++ function DiveScore, whose header is given below, to assist in scoring Olympic diving competition. The number of scores that are stored in the array parameter scores is given by the parameter numscores and the diculty factor of the dive is specied by the parameter difactor. The overall score, which is to be returned by the function DiveScore, is computed by throwing out a high and low score, computing the average of the remaining scores, and multiplying this average by the diculty factor. For example, if the scores 5.0, 5.5, 4.5, 5.0, and 5.5 are stored in the array diving as indicated: :::::: for a dive with diculty factor 2.3, then the expression DiveScore(diving,5,2.3) should evaluate to *2.3 = (because the average of 5.0, 5.5, and 5.0 is ). Complete DiveScore below the following header double DiveScore(double scores[], int numscores, double difffactor) // precondition: numscores = number of dive-scores in array scores // postcondition: returns score of dive according to rules of // removing a high and low score, averaging, and // multiplying average by difffactor 7

8 PROBLEM 9 : (15 points) Consider a class StockBroker whose partial implementation is given below: class StockBroker{ private: int numstocks; public: StockBroker(); // constructor // returns current price of stock passed as parameter double CurrentPrice(String); // returns opening price for current trading period of // stock passed as parameter ; double OpeningPrice(String);... For example, the loop below prints the current price of the stock whose name is \IBM". The loop executes until the price of IBM is greater than $80.00 (which might be forever). StockBroker broker; double price = broker.currentprice("ibm"); while (price <= 80.0){ cout << "$ " << price << endl; price = broker.currentprice("ibm"); What to do You are to write a code segment that will be used to monitor a specied stock and to \sell" the stock if its current price is more than twice its opening price. In this problem selling a stock consists of printing a message as shown below and stopping the stock monitoring process. sell stock: Nike current price $ opening price $ However, a current price can be requested no more than 10,000 times during the monitoring process. If more than 10,000 requests are made the monitoring process should stop and a message similar to that below printed. price requests for Nike exceeded 10000, monitoring halted The code you write should consist of appropriate initialization, a loop that gets prices, and a statement that prints a message indicating why monitoring stops as described above. Complete the code segment on the next page. 8

9 StockBroker broker; String name; cout << "enter name of stock "; cin >> name; double openprice = broker.openingprice(name); extra credit on back of page 9

10 PROBLEM 10 : (Extra Credit Heads or Tails 10 points) A Coin class is dened by the declarations below which would appear in the le coin.h class Coin{ ; private: <some fields/methods declared here>; public: Coin(); int Flip(); // the constructor // returns 1 50% of the time, returns 0 50% of the time The code segment below uses the coin object to toss a simulated coin 6 times with sample output as indicated: Coin penny; int k; for(k=0; k < 6; k++){ if (penny.flip() == 1){ else{ cout << "heads" << endl; cout << "tails" << endl; heads tails tails heads tails heads " output Write the function MaxTails whose header is given below. MaxTails is to simulate the tossing of a coin the number of times specied by parameter numtosses and return the longest sequence of consecutive \tails" that are tossed. For example, in the sequence of six tosses shown above, the longest consecutive tails sequence is two. int MaxTails(int numtosses) // precondition: numtosses > 0 // postcondition: returns length of longest sequence // of consecutive tails in numtosses simulated // coin tosses 10

Test 1: CPS 08 Owen Astrachan February 17, 1995 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Extra T

Test 1: CPS 08 Owen Astrachan February 17, 1995 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Extra T Test 1: CPS 08 Owen Astrachan February 17, 1995 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Extra TOTAL: value 8 pts. 12 pts. 10 pts. 10 pts. 12 pts.

More information

Test 2: CPS Owen Astrachan. November 17, Name: Honor code acknowledgement (signature)

Test 2: CPS Owen Astrachan. November 17, Name: Honor code acknowledgement (signature) Test 2: CPS 53.2 Owen Astrachan November 17, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 12 pts. grade Problem 2 16 pts. Problem 3 10 pts. Problem 4 13 pts. Problem 5 14 pts. TOTAL:

More information

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake Assigning Values // Example 2.3(Mathematical operations in C++) float a; cout > a; cout

More information

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context Test 1: CPS 100 Owen Astrachan February 12, 1996 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Extra TOTAL: value 8 pts. 18 pts. 13 pts. 16 pts. 6 pts. 57 pts. grade

More information

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context Test 1: CPS 100 Owen Astrachan October 5, 1994 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 TOTAL: value 8 pts. 6 pts. 14 pts. 10 pts. 14 pts. 52 pts.

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

Test 1: CPS 06 Owen Astrachan Susan Rodger October 2, 1995 Name: Honor code acknowledgement èsignatureè Problem 1 Problem 2 Problem 3 Problem 4 Proble

Test 1: CPS 06 Owen Astrachan Susan Rodger October 2, 1995 Name: Honor code acknowledgement èsignatureè Problem 1 Problem 2 Problem 3 Problem 4 Proble Test 1: CPS 06 Owen Astrachan Susan Rodger October 2, 1995 Name: Honor code acknowledgement èsignatureè Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 Problem 7 Extra TOTAL: value 12 pts.

More information

"apple" "grape" "grape" "grape" "apple"

apple grape grape grape apple Test 1: CPS 100 Owen Astrachan and Dee Ramm February 21, 1997 Name: Honor code acknowledgment (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 TOTAL: value 10 pts. 9 pts. 21 pts.

More information

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

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one

More information

LAB 4.1 Relational Operators and the if Statement

LAB 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 information

Assertions, pre/postconditions

Assertions, pre/postconditions Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What

More information

Test 2: CPS 103 Owen Astrachan November 19, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 9 pts. grade Problem 2 12 pts. Problem 3

Test 2: CPS 103 Owen Astrachan November 19, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 9 pts. grade Problem 2 12 pts. Problem 3 Test 2: CPS 103 Owen Astrachan November 19, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 9 pts. grade Problem 2 12 pts. Problem 3 6 pts. Problem 4 12 pts. Problem 5 12 pts. Problem

More information

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

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

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

Name Section: M/W T/TH Number Definition Matching (8 Points) Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

Separate Compilation of Multi-File Programs

Separate Compilation of Multi-File Programs 1 About Compiling What most people mean by the phrase "compiling a program" is actually two separate steps in the creation of that program. The rst step is proper compilation. Compilation is the translation

More information

Before calling Prepend(list,13) After calling Prepend(list,13) After calling RemoveLast(list)

Before calling Prepend(list,13) After calling Prepend(list,13) After calling RemoveLast(list) Test 1: CPS 100 Owen Astrachan Susan Rodger October 5, 1995 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Extra TOTAL: value 6 pts. 10 pts. 20 pts. 20 pts. 6 pts.

More information

Programming. C++ Basics

Programming. 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 information

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

Class 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 information

WARM UP LESSONS BARE BASICS

WARM 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 information

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont) CP Lect 5 slide 1 Monday 2 October 2017 Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont) Cristina Alexandru Monday 2 October 2017 Last Lecture Arithmetic Quadratic equation

More information

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

Multiple 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 information

Chapter 1 INTRODUCTION

Chapter 1 INTRODUCTION Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer

More information

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

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

Name Section: M/W T/TH Number Definition Matching (6 Points) Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control

More information

CS201 Spring2009 Solved Sunday, 09 May 2010 14:57 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Question No: 1 ( Marks: 1 ) - Please choose one The function of cin is To display message

More information

Do not write in this area A.1 A.2 A.3 A.4 A.5 A.6 B.1 B.2 B.3 TOTAL. Maximum possible points:

Do not write in this area A.1 A.2 A.3 A.4 A.5 A.6 B.1 B.2 B.3 TOTAL. Maximum possible points: Name: Student ID: Instructor: Borja Sotomayor Do not write in this area A.1 A.2 A.3 A.4 A.5 A.6 B.1 B.2 B.3 TOTAL Maximum possible points: 75 + 10 This homework has two parts: Part A (Polynomial ADT) and

More information

CSCE 2004 Midterm Exam Spring 2017

CSCE 2004 Midterm Exam Spring 2017 CSCE 2004 Midterm Exam Spring 2017 Student Name: Student UAID: Instructions: This is a 50 minute exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers are

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

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

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. Concepts Review 1. An algorithm is a sequence of steps to solve a problem. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. 3. A flowchart is the graphical

More information

Computer Programming : C++

Computer 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 information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

More information

Engineering 12 - Spring, 1999

Engineering 12 - Spring, 1999 Engineering 12 - Spring, 1999 1. (18 points) A portion of a C program is given below. Fill in the missing code to calculate and display a table of n vs n 3, as shown below: 1 1 2 8 3 27 4 64 5 125 6 216

More information

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

1. 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 information

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

More information

I 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 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 information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 7&8: Methods Lecture Contents What is a method? Static methods Declaring and using methods Parameters Scope of declaration Overloading

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

1st Midterm Exam: Solution COEN 243: Programming Methodology I

1st Midterm Exam: Solution COEN 243: Programming Methodology I 1st Midterm Exam: Solution COEN 243: Programming Methodology I Aishy Amer, Concordia University, Electrical and Computer Engineering February 10, 2005 Instructions: 1. Time Allowed is 1 Hour. Total Marks

More information

University of Dublin

University of Dublin University of Dublin TRINITY COLLEGE Faculty of Enginering & Systems Sciences School of Engineering Junior Freshman Engineering Trinity Term 2014 Computer Engineering I (1E3) Date Location Time Dr L. Hederman

More information

CMPE Experiment 3 Selective Structures

CMPE 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 information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

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

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

b. Suppose you enter input from the console, when you run the program. What is the output?

b. Suppose you enter input from the console, when you run the program. What is the output? Part I. Show the printout of the following code: (write the printout next to each println statement if the println statement is executed in the program). a. Show the output of the following code: public

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

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,

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

The 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 &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 information

FORM 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): 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 information

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

5. 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 information

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. The declaration below declares three pointer variables of type pointer to double that is

More information

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

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

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

Multiple 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 information

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

CHAPTER 3 Expressions, Functions, Output

CHAPTER 3 Expressions, Functions, Output CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number

More information

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

Week 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 information

1.3b Type Conversion

1.3b Type Conversion 1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type

More information

Programming Project: ArrayFun

Programming Project: ArrayFun Programming Project: ArrayFun Collaboration: Solo with help from classroom/online resources, Lane, and/or Rick. Anyone can also share thoughts about any specification and possible algorithm, but no sharing

More information

EP578 Computing for Physicists

EP578 Computing for Physicists EP578 Computing for Physicists Topic 3 Selection & Loops Department of Engineering Physics University of Gaziantep Course web page wwwgantepedutr/~bingul/ep578 Oct 2011 Sayfa 1 1 Introduction This lecture

More information

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking Review for Test 2 (Chapter 6-10) Chapter 6: Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B.

More information

mypoly

mypoly CPS 100 Exam 1 Fall 1996 Dr. Rodger PROBLEM 1 : (Hidden in the Stack: (12 pts)) The Stack class discussed in lecture (StackAr.h) is given on the Exam 1 handout. PART A (6 pts): Write the function Max which

More information

Data types. CISC 1600/1610 Computer Science I. Array syntax. Memory allocation. Zero-indexing 4/4/2016. Arrays

Data types. CISC 1600/1610 Computer Science I. Array syntax. Memory allocation. Zero-indexing 4/4/2016. Arrays 4/4/6 CISC 6/6 Computer Science I rrays Professor Daniel Leeds dleeds@fordham.edu JMH 38 Data types Single pieces of information one integer int one symbol char one truth value bool Multiple pieces of

More information

Unit 3, Lesson 3.1 Creating and Graphing Equations Using Standard Form

Unit 3, Lesson 3.1 Creating and Graphing Equations Using Standard Form Unit 3, Lesson 3.1 Creating and Graphing Equations Using Standard Form Imagine the path of a basketball as it leaves a player s hand and swooshes through the net. Or, imagine the path of an Olympic diver

More information

Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

More information

Programming Language. Functions. Eng. Anis Nazer First Semester

Programming 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 information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Test 1: CPS 100. Owen Astrachan. February 23, 2000

Test 1: CPS 100. Owen Astrachan. February 23, 2000 Test 1: CPS 100 Owen Astrachan February 23, 2000 Name: Login: Honor code acknowledgment (signature) Problem 1 value 19 pts. grade Problem 2 24 pts. Problem 3 8 pts. Problem 4 9 pts. Problem 5 6 pts. TOTAL:

More information

C++ Functions. Last Week. Areas for Discussion. Program Structure. Last Week Introduction to Functions Program Structure and Functions

C++ Functions. Last Week. Areas for Discussion. Program Structure. Last Week Introduction to Functions Program Structure and Functions Areas for Discussion C++ Functions Joseph Spring School of Computer Science Operating Systems and Computer Networks Lecture Functions 1 Last Week Introduction to Functions Program Structure and Functions

More information

UNIT 3 EXPRESSIONS AND EQUATIONS Lesson 3: Creating Quadratic Equations in Two or More Variables

UNIT 3 EXPRESSIONS AND EQUATIONS Lesson 3: Creating Quadratic Equations in Two or More Variables Guided Practice Example 1 Find the y-intercept and vertex of the function f(x) = 2x 2 + x + 3. Determine whether the vertex is a minimum or maximum point on the graph. 1. Determine the y-intercept. The

More information

PROBLEM 1 : (Trouble?: (14 pts)) Part A: (6 points) Consider the function Trouble below. int Trouble (const Vector<int> & numbers, int size) if (size

PROBLEM 1 : (Trouble?: (14 pts)) Part A: (6 points) Consider the function Trouble below. int Trouble (const Vector<int> & numbers, int size) if (size Test 2: CPS 6 50 Minute Exam March 31, 1999 Name (print): Lab # Honor Acknowledgment (signature): DO NOT SPEND MORE THAN 10 MINUTES ON ANY OF THE QUESTIONS! If you do not see the solution to a problem

More information

CSCI 102 Fall 2010 Exam #1

CSCI 102 Fall 2010 Exam #1 Name: USC Username: CSCI 102 Fall 2010 Exam #1 Problems Problem #1 (14 points) Problem #2 (15 points) Problem #3 (20 points) Problem #4 (16 points) Problem #5 (35 points) Total (100 points) Problem 1 Short

More information

Chapter 5 Selection Statements. Mr. Dave Clausen La Cañada High School

Chapter 5 Selection Statements. Mr. Dave Clausen La Cañada High School Chapter 5 Selection Statements Mr. Dave Clausen La Cañada High School Objectives Construct and evaluate Boolean expressions Understand how to use selection statements to make decisions Design and test

More information

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

Multiple 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 information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number:

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number: UNIVERSITY OF WINDSOR 60-106-01 Winter 2007 QUIZ # 1 Solution Examiner:Ritu Chaturvedi Dated : Feb 7 th, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.

More information

Companion C++ Examples

Companion C++ Examples 68 Appendix D Companion C++ Examples D.1 Introduction It is necessary to be multilingual in computer languages today. Since C++ is often used in the OOP literature it should be useful to have C++ versions

More information

Superior 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 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 information

Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007.

Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007. UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 1 Solution Examiner:Ritu Chaturvedi Dated :October 2nd, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.

More information

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

Name SECTION: 12:45 2:20. True or False (12 Points) Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables

More information

class for simulating a die (object "rolled" to generate a random number) Dice(int sides) -- constructor, sides specifies number of "sides" for the die

class for simulating a die (object rolled to generate a random number) Dice(int sides) -- constructor, sides specifies number of sides for the die CPS 100, Ramm/Duvall Hour Exam #2 (4/1/98) Spring, 1998 NAME (print): Honor Acknowledgment (signature): DO NOT SPEND MORE THAN 10 MINUTES ON ANY OF THE OTHER QUESTIONS! If you don't see the solution to

More information

Chapter 1 Section 1 Solving Linear Equations in One Variable

Chapter 1 Section 1 Solving Linear Equations in One Variable Chapter Section Solving Linear Equations in One Variable A linear equation in one variable is an equation which can be written in the form: ax + b = c for a, b, and c real numbers with a 0. Linear equations

More information

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

3/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 information

PROBLEM 1 : (Short Answer: 13 points) Three points each, except for last two which are two points 1. Both bubble-sort and selection sort are O(n 2 ) s

PROBLEM 1 : (Short Answer: 13 points) Three points each, except for last two which are two points 1. Both bubble-sort and selection sort are O(n 2 ) s Test 2: CPS 100 Owen Astrachan April 3, 1996 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 EXTRA TOTAL: value 13 pts. 14 pts. 13 pts. 12 pts. 15 pts. 8

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure Learning Objectives At the end of this chapter, student should be able to: Understand the requirement of a loop Understand the Loop Control Variable () Use increment (++) and decrement ( ) operators Program

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

cameron grace derek cameron

cameron grace derek cameron Test 1: CPS 100E Owen Astrachan and Dee Ramm November 19, 1996 Name: Honor code acknowledgement (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Extra TOTAL: value 15 pts. 15 pts. 8 pts. 12

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Pointers and scanf() Steven R. Bagley

Pointers and scanf() Steven R. Bagley Pointers and scanf() Steven R. Bagley Recap Programs are a series of statements Defined in functions Can call functions to alter program flow if statement can determine whether code gets run Loops can

More information

Add Subtract Multiply Divide

Add 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 information

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 Name: USC loginid (e.g., ttrojan): CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 There are 6 problems on the exam, with 70 points total available. There are 7 pages to the exam, including this one;

More information

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

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma. REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

More information

UNIT 8: SOLVING AND GRAPHING QUADRATICS. 8-1 Factoring to Solve Quadratic Equations. Solve each equation:

UNIT 8: SOLVING AND GRAPHING QUADRATICS. 8-1 Factoring to Solve Quadratic Equations. Solve each equation: UNIT 8: SOLVING AND GRAPHING QUADRATICS 8-1 Factoring to Solve Quadratic Equations Zero Product Property For all numbers a & b Solve each equation: If: ab 0, 1. (x + 3)(x 5) = 0 Then one of these is true:

More information

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

Computer 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 information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

CPS 6 Test 1 Fall 2000 Dr. Rodger String class

CPS 6 Test 1 Fall 2000 Dr. Rodger String class CPS 6 Test 1 Fall 2000 Dr. Rodger String class int length(); // post: returns number of characters in string string substr(int pos, int len); // pre: 0

More information

CS 2505 Computer Organization I

CS 2505 Computer Organization I Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester Programming Language Control Structures: Repetition (while) Eng. Anis Nazer Second Semester 2017-2018 Repetition statements Control statements change the order which statements are executed Selection :

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010 The American University in Cairo Computer Science & Engineering Department CSCE 106-08 Dr. KHALIL Exam II Spring 2010 Last Name :... ID:... First Name:... Form - I EXAMINATION INSTRUCTIONS * Do not turn

More information