Final Revision I 1020: Introduction to Programming Mohamed Shehata November 30, 2015.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
CS 106 Introduction to Computer Science I 11 / 09 / 2007 Instructor: Michael Eckmann.
1 Array, Pointer and Reference ( III ) Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Introduction to Computers and Programming Class 22 Character Arrays (Strings) Professor Avi Rosenfeld.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
CS 106 Introduction to Computer Science I 03 / 30 / 2007 Instructor: Michael Eckmann.
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
1 Applications of Recursion (Walls & Mirrors - Chapter 5)
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
CS1020E Sitin 1 Discussion -- Counting Palindromes.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12: Recursion Problem Solving, Abstraction, and Design using C++
Chapter 17 Pointers and Arrays. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Pointers and Arrays.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
Introduction to Programming (in C++) Algorithms on sequences. Reasoning about loops: Invariants. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
Announcements This Wednesday, Class and Labs are cancelled! The last lab is due this Wednesday … how many people are planning on doing it? Finally posted.
Looping and Counting Lecture 3 Hartmut Kaiser
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Function Overloading Two different functions may have the same name as long as they differ in the number or types of arguments: int max(int x, int y) and.
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Arrays. Collections We would like to be able to keep lots of information at once Example: Keep all the students in the class Grade each one without writing.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Chapter 3: User-Defined Functions I
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Computer Programming for Engineers
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Arrays.
Reading from a file, Sorting, and a little Searching Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics,
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
1 11/12/04CS150 Introduction to Computer Science 1 More Arrays.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
Chapter 16 Pointers and Arrays Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them in C. Pointer Address.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 7 Pointers and C-Strings.
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Recursion Version 1.0.
Introduction to Arrays
Chapter 7 User-Defined Methods.
Chapter 6: User-Defined Functions I
Containers and Lists CIS 40 – Introduction to Programming in Python
Arrays.
1020: Introduction to Programming Mohamed Shehata November 22, 2017
1020: Introduction to Programming Mohamed Shehata December 1, 2017
Chapter 16 Pointers and Arrays
Chapter 6: User-Defined Functions I
Introduction to Arrays
Introduction to Problem Solving and Programming
Presentation transcript:

Final Revision I 1020: Introduction to Programming Mohamed Shehata November 30, 2015

Example (from Final Review Sheet on the website)  This question deals with digital audio (e.g., music), which is essentially an array of sound samples, where each sample represents the amplitude of the sound wave at a particular instant. A fuzz box creates a distortion effect common in rock guitar music by 'clipping' the maximum amplitude to the given value, as illustrated. Write the prototype and implementation of the header block shown below. 2

/*** Q17. fuzzBox ******************************* * Clip the size samples in snd to a maximum amplitude (magnitude) snd - audio samples array * size - the number of samples in snd * clip - the maximum magnitude in the output Any element in snd that has a magnitude greater than clip * will be set to clip or – clip to preserve the sign number of samples that had their values changed **/ 3 int fuzzBox(int snd[], int size, int clip) { int cnt = 0 ; for ( int i=0 ; i < size; i++) { if(snd[i] > clip){ snd [ i ] = clip; cnt++; } else if (snd[i]<-clip) { snd[i]= -clip; cnt++; } return cnt; }

Example (from Final Review Sheet on the website)  Write the contract and implementation for function named "reverseArray" that takes as its arguments the following: (1) an array of double values; (2) an integer that tells the size of the array  The function must reverse the order of the values in the array. Thus, for example, if the array that's passed to the function looks like this: 5.8 | 2.6 | 9.0 | 3.4 | 7.1  then when the function returns, the array will have been modified so that it looks like this: 7.1 | 3.4 | 9.0 | 2.6 | 5.8  The function should not return any value. 4

/** reverseArray *************************************************** * reverse the order of the values in the array. dArray - an array of doubles * size - the number of elements in the size > 0 * dArray - elements are reversed order nothing ********************************************************************/ void reverseArray(double dArray[], int size) { 5 for(int i= 0; i<size/2; i++){ double tmp = dArray[i]; dArray[i]=dArray[size-1-i]; dArray[size-1-i]=tmp; }

Exercise  Spring 2013:  Consider our maze solving problem using the 3  robot. We'd like to extend the solution so that, having found its way to the target and optimized the route, the 3  will turn around and re-trace the route back to the starting point (i.e., so we don't need to pick it up and place it back at the beginning). One part of a solution to this is a function to compute the reverse route corresponding to the forward route that we've just found. The intersections in the reverse route are in reverse order, and the turns are reciprocal. In the space below you are to write the contract [5 points] and implementation [8 points] for a function to compute the reverse route from the forward route. It should take as input the forward route and its length, and fill the reverse route into a separate array that can be assumed to be appropriately sized. 6

/** reverseRoute **************************************************** * Make a copy of the route going in the reverse direction route -- sequence of 'L', 'R' or 'S' representing a route * through the maze * revRoute -- placeholder for 'reversed' version of route size is at least len * len -- number of steps in route revRoute has 'L', 'R' or 'S' put in so that it will guide * the 3pi on a return journey. */ void reverseRoute(char route[], char revRoute[], int len){ 7 for(int i=0 ; i <len ; i++){ if(route[len-i-1]=='L'){ revRoute[i]='R'; } else if(route[len-i-1]=='R'){ revRoute[i]='L'; } else{ revRoute[i]='S'; }

Image Histogram In the image processing image project, write a function that can calculate the histogram of an image and store the values in an array. The histogram of an image is how many times each value from 0 to 255 was in that image. The histogram will be saved in an array hist that has 256 entries. For example, if the image had 10 pixels, all with value 32, then the result array hist will have hist[32] = 10; all other entries in the array hist will be 0. 8

for(int i = 0 ; i < histSize; i++){ hist[i] = 0; for (int r=0 ; r<rows;r++){ for (int c= 0 ; c< cols; c++){ if (A[r*cols+c] == i) hist[i]++; } } } } 9 /* Q14. Histogram****************************** param: A- the input Image * rows: number of rows in the image * cols: number of columns in the image * hist : the histogram array pre: histSize- the size of this array hist =256 modify: hist- will updated to have the histogram of the image * */ void histogram (int A[], int rows, int cols, int hist[], int histSize){

From the review sheet on website Write a function to determine if a string is a palindrome. Recall that a palindrom is a string that reads backwards the same as forward. For example, "MADAM" and "ABLE WAS I ERE I SAW ELBA" are palindromes, while "BERT WACHSMUTH" is not a palindrome 10 /* Q9. isPalindrome ****************************** * a function to check if a string is palindrome * param: input- input string * modify: nothing if the string is palindrome */

bool isPalindrome (string input) { bool result=true; for(int i=0 ; i< input.length()/2; i++){ if(input[i]!= input[input.length()-1-i]) result= false; } return result; } 11