Study Guide for Test 2

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

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.

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

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

Lab Instructor : Jean Lai

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

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

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

Functions. Arash Rafiey. September 26, 2017

C++ For Science and Engineering Lecture 12

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

A First Program - Greeting.cpp

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

Loops / Repetition Statements

Scientific Computing

EECS402 Lecture 02. Functions. Function Prototype

Perfect square. #include<iostream> using namespace std; int main(){ int a=1; int square; while(true){ } cout<<square<<endl; }

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

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

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

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

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

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

CSCE Practice Midterm. Data Types

Getting started with C++ (Part 2)

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

Introduction to Computer Science Midterm 3 Fall, Points

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

Increment and the While. Class 15

The University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters.

University of Dublin

Week 3: Pointers (Part 2)

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

Problem Solving: Storyboards for User Interaction

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

Local and Global Variables

Assignment #1 (50 points; due 11:59 P.M.)

C++ Final Exam 2017/2018

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

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

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

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

Chapter 3 Problem Solving and the Computer

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

Exercise: Inventing Language

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

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

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

Due Date: See Blackboard

Exceptions, Case Study-Exception handling in C++.

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

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

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

do { statements } while (condition);

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Computer Programming

CSCE 206: Structured Programming in C++

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

Exercise 1.1 Hello world

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

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

The following expression causes a divide by zero error:

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

pointers + memory double x; string a; int x; main overhead int y; main overhead

Lab # 02. Basic Elements of C++ _ Part1

CSc Introduction to Computing

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

Control Structures/Lespérance 1

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

C++ For Science and Engineering Lecture 2

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

LECTURE 02 INTRODUCTION TO C++

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

Input And Output of C++

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

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

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)

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

A Freshman C++ Programming Course

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, November 24, 2015

CSCE Practice Midterm. Data Types

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

A function that invokes itself is said to

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

BENG (HONS) ELECTRONIC ENGINEERING BENG (HONS) TELECOMMUNICATIONS. Cohort: BEE/10A/FT, BEE/10B/FT &BTEL/10B/FT

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

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

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

Subprograms. Introduction to Programming (in C++) Subprograms: procedures and functions. Subprograms. Subprograms. Functions are defined as follows:

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm

Ch 6. Functions. Example: function calls function

Chapter 1 INTRODUCTION

REPETITION CONTROL STRUCTURE LOGO

Transcription:

Study Guide for Test 2 Topics: decisions, loops, arrays, c-strings, linux Material Selected from: Chapters 4, 5, 6, 7, 10.1, 10.2, 10.3, 10.4 Examples 14 33 Assignments 4 8 Any syntax errors are unintentional 1. Know what is meant by and how to use the following linux commands: pwd, cd, rm, cp, mkdir, mv 2 10. Problems 31 40, pp 218-219, Gaddis 11-12. Problems 63 64, p. 221, Gaddis 13. Using a while loop, display the first five non-negative integers 14. Using a for loop, display the first five alphabetic characters 15. Using a while loop, display the first five non-negative integers in reverse 16. Using a for loop, display the first five non-negative integers in reverse

What is the output? int main() int x, y; x = y = 0; while(x < 5) y += x; ++x; cout << x << << y << endl ; 16. Write the following function: pre: limit is an integer >= 2 post: returns the sum of the integers in the closed interval [1..limit] using a for loop int add(int limit) 17. Do problem 16 using a while loop

18. 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; else if (y > x && y > z) return y; else if (z > x && z > y) return z; else return 0; 19. Rewrite problem 18 without using a nested if 20. 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) 21. 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)

22. 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) 23. Write the following function: pre: num is an integer > 1 pre: returns true if num is prime, false otherwise bool isprime(int num) 23. Write the following function pre: num is a positive integer post: returns true if num is odd, false otherwise bool isodd(int num) 24. 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) 25 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)

26. Write the following function using the function you wrote for problem 23 pre: stuff is an array containing size integers post: returns the number of even integers in the array int evens(int stuff[], in size) 27. Write the following function Pre: stuff is an C-string Post: if target is in the array, its position is returned, else returns -1 is returned int linsrch(char stuff[], ch target) 29. What is the big O complexity of linsrch in problem 27? 30. Rewrite the following to its equivalent using DeMorgan s Law: if (!(x == 1 && y == 2)) cout << Negation with logical AND << endl; 31. Write the following function: pre: data is a c-string post: returns the number of upper case characters in the string using either a function that you write or one of the character functions found on p. 558 int howmany(char data[]) 32. Create an character array of 6 positions. Store the first five lower case characters of the alphabet in the array using a loop. Transform the character array to a c-string. 33. Display the characters stored in the array from problem 32 in reverse using a loop and strlen. 34. How many bytes are allocated in this declaration: int data[10];

35. How many bytes are allocated in this declaration: char data[10]; 36. Write a piece of code that a. asks the user to input a line of < 80 characters b. accepts the characters into a previously declared 81 position character array c. displays the result with a single statement d. why does c work? 37. Write a piece of code that a. declares a ten position integer array b. Stores the first ten non-negative integers in the array c. Displays the contents of the array after the array has been filled with values. 38. Write a piece of code that: a. declares a 6 position character array b. uses cin.get() to fill the array with the first five upper case alphabetic characters c. transforms the array to a c-string. d. displays the array with a single statement after it has been filled.

39. Write the following function: Pre: data is a c-string which holds alphabetic characters Post: returns the number of alphabetic characters in data int mystrlen(char data[]) 40. What is the output? #include<iostream> using namespace std; void swap(int,int); int main() int x = 7; int y = 8; swap(x,y); cout << x << << y << endl; return 0; void swap(int x, int y) int buf = x; x = y; y = buf;

41. What is the output? #include<iostream> using namespace std; void swap(int&,int&); int main() int x = 7; int y = 8; swap(x,y); //here 1 cout << x << << y << endl; return 0; void swap(int& x, int& y) //here 2 int buf = x; x = y; y = buf; 42. The parameters in the line labeled //here1 in problems 41 are called: parameters 43. The parameters in the line labeled //here 2 in problems 41 are called: parameters

44. What is the output? #include<iostream> using namespace std; void swap(int,int); int main() int x = 7; int y = 8; swap(x,y); cout << x << << y << endl; return 0; void swap(int a, int b) int buf = a; a = b; b = buf;

45. What is the output? #include<iostream> using namespace std; void swap(int&,int&); int main() int x = 7; int y = 8; swap(x,y); cout << x << << y << endl; return 0; void swap(int& a, int& b) int buf = a; a = b; b = buf;