Topics: Material through example 19 (types, operators, expressions, functions, selection, loops, arrays)

Similar documents
Study Guide for Test 2

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.

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

Lecture 3 Tao Wang 1

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

Loops / Repetition Statements

Subject: Fundamental of Computer Programming 2068

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

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

CSCE Practice Midterm. Data Types

8. The C++ language, 1. Programming and Algorithms II Degree in Bioinformatics Fall 2017

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

C++ Final Exam 2017/2018

Week 3: Pointers (Part 2)

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

CS2141 Software Development using C/C++ C++ Basics

Homework #3 CS2255 Fall 2012

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Functions! Objectives! 1E3! Topic 9! programming! n This topic should allow students to! n Read chapter 6 of the textbook now.!

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

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

Exercise: Inventing Language

Functions. Arash Rafiey. September 26, 2017

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

CHAPTER 3 Expressions, Functions, Output

Exam 3 Chapters 7 & 9

Pointers. Variable Declaration. Chapter 10

Do not start the test until instructed to do so!

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

This is CS50. Harvard University Fall Quiz 0 Answer Key

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

Arrays. Arizona State University 1

CHAPTER 4 FUNCTIONS. 4.1 Introduction

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

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

MIT Semantic Analysis. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

A First Program - Greeting.cpp

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Chapter 9. Pointers and Dynamic Arrays

Chapter 3 Problem Solving and the Computer

CS242 COMPUTER PROGRAMMING

Computer Programming

Getting started with C++ (Part 2)

Test Bank for Problem Solving with C++: The Object of Programming, 8/e Chapter 2 C++ Basics

CS201- Introduction to Programming Current Quizzes

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

Introduction to Computer Science Midterm 3 Fall, Points

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Lesson 2 Variables and I/O

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

LAB 4.1 Relational Operators and the if Statement


M1-R4: Programing and Problem Solving using C (JAN 2019)

Subject: Computer Science

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

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

Chapter 1 INTRODUCTION

ComS 228 Exam 1. September 27, 2004

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

CSCE Practice Midterm. Data Types

Lab Instructor : Jean Lai

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

n Group of statements that are executed repeatedly while some condition remains true

Practice test for midterm 2

CS 115 Exam 2, Fall 2009

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

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

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

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

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

Recursion. Example R1

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

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

Data Structures And Algorithms

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Exercise: Using Numbers

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

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

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

Chapter 6 Single-dimensional Arrays

Chapter Overview. Pointers and Dynamic Arrays. Pointers. Pointers. Declaring Pointers. Pointers Tell Where To Find A Variable. 9.

The C++ Language. Arizona State University 1

A structure is an aggregate data type which contains a fixed number of heterogeneous components.

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

Pointers and Strings Chapters 10, Pointers and Arrays (10.3) 3.2 Pointers and Arrays (10.3) An array of ints can be declared as

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

KENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW MARKS QUESTIONS : DATA STRUCTURE

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

REPETITION CONTROL STRUCTURE LOGO

CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad

Chapter 3, Selection. Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved.

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1

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

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

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

Transcription:

CPSC 122 Study Guide: Examination 1 Topics: Material through example 19 (types, operators, expressions, functions, selection, loops, arrays) 1. What is the output? int x, y; x = y = 0; while(x < 5) y += x; ++x; cout << x << << y << endl ; 2. Write the following function: pre: limit is an integer >= 2 post: returns the sum of the integers in the closed interveral [1..limit] using a for loop int add(int limit) 3. Do problem 2 using a while loop 4. What is the output?... cout << whatisit(9, 3, 17) << endl;... int whatisit(int x, int y, int z) if (x > y && x > z) return x; if (y > x && y > z) return y; if (z > x && z > y) return z; return 0;

5. Rewrite problem 5 without using a nested if 6. Rewrite problem 5 without using && and without using <= 7. Suppose we have this line in a program: typedef float mytype; Write a short program that: declares and initializes two variables of type mytype. Inputs values for each from the keyboard Sums the two variables and outputs the sum 8. What is the output: int a = 2; int d = 0; float b = 1.0; float c = 0.0; c = b/a; cout << c << endl; cout << static_cast<int>(b/a) << endl; d = b/a; cout << d << endl; cout << showpoint; c = static_cast<int>(b/a); cout << c << endl; 9. Write the following function: //pre: x, y, z are integers //post: returns the smallest of the arguments. If two or three of the arguments are tied for the smallest, returns one of them. int findsmallest(int x, int y, int z) 10. Write the following function: pre: base and exp are integers with base >= 1 and exp >= 0 post: returns base to the exp power without using a built-in function int myexp(int base, int exp) 11. If you used a for loop in problem 10, rewrite it with a while loop and vice-versa.

12. Write the following function using a loop construction of your choice pre: value is an integer >= 0 post: returns the factorial of num. Example: fact(0) = 1, fact(3) = 3 * 2 * 1 int fact(int num) 13. If you used a for loop in problem 12, rewrite it with a while loop and vice-versa 14. Write the following function: pre: num is a positive integer >=2 //post: returns true if num is prime, false otherwise int isprime(int num) 15. What is the output?. int sum = 0; int value = 1; for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) sum += value++; cout << sum << << value; 16. What is the output? int x = 7; int y = 0; y = 3 * ++x cout << x << << y << endl; x = 7; y = 0; y = 3 * x++; cout << x << << y << endl;

17. Write the following function pre: num is a positive integer post: returns true if num is odd, false otherwise bool isodd(int num) 18. What is the output? int a = 0; int b = 1; int c = 2; int result = 0; if (result == a result == b result == c) ++result; cout << result << endl; 19. What is the output? int a = 0; int b = 1; int c = 2; int result = 0; if (result == a && result == b && result == c) ++result; cout << result << endl;

20. What is the output? This is supposed to print 1 if result is either a or b or c. What does it print? What s wrong? Fix it. int a = 1; int b = 1; int c = 2; int result = 0; if ((result = a) (result = b) (result = c)) cout << true << endl; cout << false << endl; 21. Write the following function pre: num is an integer > 0 post: displays all integers in the closed interval [0..num] but in reverse void disprev(int num) 22. Suppose you are using a 32 bit machine. int x; //how many bytes are allocated for x char y; //how many bytes are allocated for y 23. Write the following function //pre: stuff is an integer array of size howmany. It is filled with integers //post: returns the sum of the integers in the array int add(int stuff[], int howmany) 24. What is the complexity to your solution to problem 23 expressed in big O notation? 25. What is the complexity to problem 19 expressed in big O notation 26. Write the following function: /* pre: nums is an array containing integers, howmany is the size of the array post: returns the product of the integers in the array */ int prod(int nums[], int howmany) 26. If you solved 1 with a for loop, solve it with a while loop and vice-versa. 27. Write a program that stores the first twenty even integers in an array and then displays them in reverse.

29. Write the following function /* Pre: stuff is an array of strings of size num. target is a string. Post: if target is in the array, its position is returned, returns -1 is returned */ int linsrch(string stuff[], int num, string target) 30. What is the big O complexity of linsrch in problem 29? 31. Write the following function. /* Pre: stuff is an array of char of size num. idx is an index in the range 0 <= idx <= num 1 Post: returns the character stored in stuff at position idx */ char getstuff(char stuff[], int idx) 32. What is the big O complexity of getstuff from problem 31 33. Example 18 on the class web site is selection sort. What is the big O complexity? 34. What is the output? void dostuff(int,int); int x = 1; int y = 2; dostuff(x,y): cout << x << << y << endl; void dostuff(int x, int y) int z; z = x x = y y = z

35. What is the output? void dostuff(int[], int, int); int x = 1; int y = 2; int stuff[5]; for (int i = 0; i < 5; i++) stuff[i] = i; dostuff(stuff, x, y): cout << stuff[x] << << stuff[y] << endl; void dostuff(int stuff[], int x, int y) int z = stuff[x]; stuff[x] = stuff[y]; stuff[[y] = z;