Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Size: px
Start display at page:

Download "Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved."

Transcription

1

2 Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

3 Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4 Procedural Abstractio 4.5 Local Variables 4.6 Overloadig Fuctio Names Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-3

4 4.1 Top-Dow Desig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

5 Top Dow Desig To write a program Develop the algorithm that the program will use Traslate the algorithm ito the programmig laguage Top Dow Desig (also called stepwise refiemet) Break the algorithm ito subtasks Break each subtask ito smaller subtasks Evetually the smaller subtasks are trivial to implemet i the programmig laguage Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-5

6 Beefits of Top Dow Desig Subtasks, or fuctios i C++, make programs Easier to uderstad Easier to chage Easier to write Easier to test Easier to debug Easier for teams to develop Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-6

7 4.2 Predefied Fuctios Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

8 Predefied Fuctios C++ comes with libraries of predefied fuctios Example: sqrt fuctio the_root = sqrt(9.0); returs, or computes, the square root of a umber The umber, 9, is called the argumet the_root will cotai 3.0 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-8

9 Fuctio Calls sqrt(9.0) is a fuctio call It ivokes, or sets i actio, the sqrt fuctio The argumet (9), ca also be a variable or a expressio A fuctio call ca be used like ay expressio bous = sqrt(sales) / 10; Cout << The side of a square with area << area << is << sqrt(area); Display 4.1 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-9

10 Fuctio Call Sytax Fuctio_ame (Argumet_List) Argumet_List is a comma separated list: (Argumet_1, Argumet_2,, Argumet_Last) Example: side = sqrt(area); cout << 2.5 to the power 3.0 is << pow(2.5, 3.0); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-10

11 Fuctio Libraries Predefied fuctios are foud i libraries The library must be icluded i a program to make the fuctios available A iclude directive tells the compiler which library header file to iclude. To iclude the math library cotaiig sqrt(): #iclude <cmath> Newer stadard libraries, such as cmath, also require the directive usig amespace std; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-11

12 Other Predefied Fuctios abs(x) --- it value = abs(-8); Returs absolute value of argumet x Retur value is of type it Argumet is of type x Foud i the library cstdlib fabs(x) --- double value = fabs(-8.0); Returs the absolute value of argumet x Retur value is of type double Argumet is of type double Foud i the library cmath Display 4.2 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-12

13 Radom Number Geeratio Really pseudo-radom umbers 1. Seed the radom umber geerator oly oce #iclude <cstdlib> #iclude <ctime> srad(time(0)); 2. The rad() fuctio returs a radom iteger that is greater tha or equal to 0 ad less tha RAND_MAX rad(); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 1-13

14 Radom Numbers Use % ad + to scale to the umber rage you wat For example to get a radom umber from 1-6 to simulate rollig a six-sided die: it die = (rad() % 6) + 1; Ca you simulate rollig two dice? Geeratig a radom umber x where 10 < x < 21? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 1-14

15 Type Castig Recall the problem with iteger divisio: it total_cady = 9, umber_of_people = 4; double cady_per_perso; cady_per_perso = total_cady / umber_of_people; cady_per_perso = 2, ot 2.25! A Type Cast produces a value of oe type from aother type static_cast<double>(total_cady) produces a double represetig the iteger value of total_cady Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-15

16 Type Cast Example it total_cady = 9, umber_of_people = 4; double cady_per_perso; cady_per_perso = static_cast<double>(total_cady) / umber_of_people; cady_per_perso ow is 2.25! This would also work: cady_per_perso = total_cady / static_cast<double>( umber_of_people); This would ot! cady_per_perso = static_cast<double>( total_cady / umber_of_people); Iteger divisio occurs before type cast Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-16

17 Old Style Type Cast C++ is a evolvig laguage This older method of type castig may be discotiued i future versios of C++ cady_per_perso = double(total_cady)/umber_of_people; cady_per_perso = (double) total_cady /umber_of_people; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-17

18 Sectio 4.2 Coclusio Ca you Determie the value of d? double d = 11 / 2; Determie the value of pow(2,3) fabs(-3.5) sqrt(pow(3,2)) 7 / abs(-2) ceil(5.8) floor(5.8) x + y Covert the followig to C++ Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. b + 2 b 4ac 2a x y + 7 Slide 4-18

19 4.3 Programmer-Defied Fuctios Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

20 Programmer-Defied Fuctios Two compoets of a fuctio defiitio Fuctio declaratio (or fuctio prototype) Shows how the fuctio is called Must appear i the code before the fuctio ca be called Sytax: Type_retured Fuctio_Name(Parameter_List); //Commet describig what fuctio does ; Fuctio defiitio Describes how the fuctio does its task Ca appear before or after the fuctio is called Sytax: Type_retured Fuctio_Name(Parameter_List) { //code to make the fuctio work } Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-20

21 Fuctio Declaratio Tells the retur type Tells the ame of the fuctio Tells how may argumets are eeded Tells the types of the argumets Tells the formal parameter ames Formal parameters are like placeholders for the actual argumets used whe the fuctio is called Formal parameter ames ca be ay valid idetifier Example: double total_cost(it umber_par, double price_par); // Compute total cost icludig 5% sales tax o // umber_par items at cost of price_par each Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-21

22 Fuctio Defiitio Provides the same iformatio as the declaratio Describes how the fuctio does its task Example: fuctio header double total_cost(it umber_par, double price_par) { cost double TAX_RATE = 0.05; //5% tax double subtotal; subtotal = price_par * umber_par; retur (subtotal + subtotal * TAX_RATE); } fuctio body Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-22

23 The Retur Statemet Eds the fuctio call Returs the value calculated by the fuctio Sytax: retur expressio; expressio performs the calculatio or expressio is a variable cotaiig the calculated value Example: retur subtotal + subtotal * TAX_RATE; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-23

24 The Fuctio Call Tells the ame of the fuctio to use Lists the argumets Is used i a statemet where the retured value makes sese Example: double bill = total_cost(umber, price); Display 4.3 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-24

25 Fuctio Call Details The values of the argumets are plugged ito the formal parameters (Call-by-value mechaism with call-by-value parameters) The first argumet is used for the first formal parameter, the secod argumet for the secod formal parameter, ad so forth. The value plugged ito the formal parameter is used i all istaces of the formal parameter i the fuctio body Display 4.4 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-25

26 Alterate Declaratios Two forms for fuctio declaratios List formal parameter ames List types of formal parmeters, but ot ames First aids descriptio of the fuctio i commets Examples: double total_cost(it umber_par, double price_par); double total_cost(it, double); Fuctio headers must always list formal parameter ames! Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-26

27 Order of Argumets Compiler checks that the types of the argumets are correct ad i the correct sequece. Compiler caot check that argumets are i the correct logical order Example: Give the fuctio declaratio: char grade(it received_par, it mi_score_par); it received = 95, mi_score = 60; Display 4.5 (1) Display 4.5 (2) cout << grade( mi_score, received); Produces a faulty result because the argumets are ot i the correct logical order. The compiler will ot catch this! Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-27

28 Fuctio Defiitio Sytax Withi a fuctio defiitio Variables must be declared before they are used Variables are typically declared before the executable statemets begi At least oe retur statemet must ed the fuctio Each brach of a if-else statemet might have its ow retur statemet Display 4.6 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-28

29 Placig Defiitios A fuctio call must be preceded by either The fuctio s declaratio or The fuctio s defiitio If the fuctio s defiitio precedes the call, a declaratio is ot eeded Placig the fuctio declaratio prior to the mai fuctio ad the fuctio defiitio after the mai fuctio leads aturally to buildig your ow libraries i the future. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-29

30 bool Retur Values A fuctio ca retur a bool value Such a fuctio ca be used where a boolea expressio is expected Makes programs easier to read if (((rate >=10) && ( rate < 20)) (rate == 0)) is easier to read as if (appropriate (rate)) If fuctio appropriate returs a bool value based o the the expressio above Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 3-30

31 Fuctio appropriate To use fuctio appropriate i the if-statemet if (appropriate (rate)) { } appropriate could be defied as bool appropriate(it rate) { retur (((rate >=10) && ( rate < 20)) (rate == 0)); } Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 3-31

32 Sectio 4.3 Coclusio Ca you Write a fuctio declaratio ad a fuctio defiitio for a fuctio that takes three argumets, all of type it, ad that returs the sum of its three argumets? Describe the call-by-value parameter mechaism? Write a fuctio declaratio ad a fuctio defiitio for a fuctio that takes oe argumet of type it ad oe argumet of type double, ad that returs a value of type double that is the average of the two argumets? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-32

33 4.4 Procedural Abstractio Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

34 Procedural Abstractio The Black Box Aalogy A black box refers to somethig that we kow how to use, but the method of operatio is ukow A perso usig a program does ot eed to kow how it is coded A perso usig a program eeds to kow what the program does, ot how it does it Fuctios ad the Black Box Aalogy A programmer who uses a fuctio eeds to kow what the fuctio does, ot how it does it A programmer eeds to kow what will be produced if the proper argumets are put ito the box Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-34

35 Iformatio Hidig Desigig fuctios as black boxes is a example of iformatio hidig The fuctio ca be used without kowig how it is coded The fuctio body ca be hidde from view Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-35

36 Fuctio Implemetatios ad The Black Box Desigig with the black box i mid allows us To chage or improve a fuctio defiitio without forcig programmers usig the fuctio to chage what they have doe To kow how to use a fuctio simply by readig the fuctio declaratio ad its commet Display 4.7 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-36

37 Procedural Abstractio ad C++ Procedural Abstractio is writig ad usig fuctios as if they were black boxes Procedure is a geeral term meaig a fuctio like set of istructios Abstractio implies that whe you use a fuctio as a black box, you abstract away the details of the code i the fuctio body Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-37

38 Procedural Abstractio ad Fuctios Write fuctios so the declaratio ad commet is all a programmer eeds to use the fuctio Fuctio commet should tell all coditios required of argumets to the fuctio Fuctio commet should describe the retured value Variables used i the fuctio, other tha the formal parameters, should be declared i the fuctio body Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-38

39 Formal Parameter Names Fuctios are desiged as self-cotaied modules Differet programmers may write each fuctio Programmers choose meaigful ames for formal parameters Formal parameter ames may or may ot match variable ames used i the mai part of the program It does ot matter if formal parameter ames match other variable ames i the program Remember that oly the value of the argumet is plugged ito the formal parameter Display 4.8 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-39

40 Case Study Buyig Pizza What size pizza is the best buy? Which size gives the lowest cost per square ich? Pizza sizes give i diameter Quatity of pizza is based o the area which is proportioal to the square of the radius Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-40

41 Buyig Pizza Problem Defiitio Iput: Diameter of two sizes of pizza Cost of the same two sizes of pizza Output: Cost per square ich for each size of pizza Which size is the best buy Based o lowest price per square ich If cost per square ich is the same, the smaller size will be the better buy Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-41

42 Buyig Pizza Problem Aalysis Subtask 1 Get the iput data for each size of pizza Subtask 2 Compute price per ich for smaller pizza Subtask 3 Compute price per ich for larger pizza Subtask 4 Determie which size is the better buy Subtask 5 Output the results Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-42

43 Buyig Pizza Fuctio Aalysis Subtask 2 ad subtask 3 should be implemeted as a sigle fuctio because Subtask 2 ad subtask 3 are idetical tasks The calculatio for subtask 3 is the same as the calculatio for subtask 2 with differet argumets Subtask 2 ad subtask 3 each retur a sigle value Choose a appropriate ame for the fuctio We ll use uitprice Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-43

44 Buyig Pizza uitprice Declaratio double uitprice(it diameter, it double price); //Returs the price per square ich of a pizza //The formal parameter amed diameter is the //diameter of the pizza i iches. The formal // parameter amed price is the price of the // pizza. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-44

45 Buyig Pizza Algorithm Desig Subtask 1 Ask for the iput values ad store them i variables Subtask 4 diameter_small diameter_large price_small price_large Compare cost per square ich of the two pizzas usig the less tha operator Subtask 5 Stadard output of the results Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-45

46 Buyig Pizza uitprice Algorithm Subtasks 2 ad 3 are implemeted as calls to fuctio uitprice uitprice algorithm Compute the radius of the pizza π r 2 Computer the area of the pizza usig Retur the value of (price / area) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-46

47 Buyig Pizza uitprice Pseudocode Pseudocode Mixture of C++ ad eglish Allows us to make the algorithm more precise without worryig about the details of C++ sytax uitprice pseudocode radius = oe half of diameter; area = π * radius * radius retur (price / area) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-47

48 Buyig Pizza The Calls of uitprice Mai part of the program implemets calls of uitprice as double uit_price_small, uit_price_large; uit_price_small = uitprice(diameter_small, price_small); uit_price_large = uitprice(diameter_large, price_large); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-48

49 Buyig Pizza First try at uitprice double uitprice (it diameter, double price) { cost double PI = ; double radius, area; } radius = diameter / 2; area = PI * radius * radius; retur (price / area); Oops! Radius should iclude the fractioal part Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-49

50 Buyig Pizza Secod try at uitprice double uitprice (it diameter, double price) { cost double PI = ; double radius, area; } radius = diameter / static_cast<double>(2) ; area = PI * radius * radius; retur (price / area); Display 4.10 (1) Display 4.10 (2) Now radius will iclude fractioal parts radius = diameter / 2.0 ; // This would also work Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-50

51 Program Testig Programs that compile ad ru ca still produce errors Testig icreases cofidece that the program works correctly Ru the program with data that has kow output You may have determied this output with pecil ad paper or a calculator Ru the program o several differet sets of data Your first set of data may produce correct results i spite of a logical error i the code Remember the iteger divisio problem? If there is o fractioal remaider, iteger divisio will give apparetly correct results Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-51

52 Use Pseudocode Pseudocode is a mixture of Eglish ad the programmig laguage i use Pseudocode simplifies algorithm desig by allowig you to igore the specific sytax of the programmig laguage as you work out the details of the algorithm If the step is obvious, use C++ If the step is difficult to express i C++, use Eglish Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-52

53 Sectio 4.4 Coclusio Ca you Describe the purpose of the commet that accompaies a fuctio declaratio? Describe what it meas to say a programmer should be able to treat a fuctio as a black box? Describe what it meas for two fuctios to be black box equivalet? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-53

54 4.5 Local Variables Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

55 Local Variables Variables declared i a fuctio: Are local to that fuctio, they caot be used from outside the fuctio Have the fuctio as their scope Variables declared i the mai part of a program: Are local to the mai part of the program, they caot be used from outside the mai part Have the mai part as their scope Display 4.11 (1) Display 4.11 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-55

56 Global Costats Global Named Costat Available to more tha oe fuctio as well as the mai part of the program Declared outside ay fuctio body Declared outside the mai fuctio body Declared before ay fuctio that uses it Example: cost double PI = ; double volume(double); it mai() { } PI is available to the mai fuctio ad to fuctio volume Display 4.12 (1) Display 4.12 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-56

57 Global Variables Global Variable -- rarely used whe more tha oe fuctio must use a commo variable Declared just like a global costat except cost is ot used Geerally make programs more difficult to uderstad ad maitai Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-57

58 Formal Parameters are Local Variables Formal Parameters are actually variables that are local to the fuctio defiitio They are used just as if they were declared i the fuctio body Do NOT re-declare the formal parameters i the fuctio body, they are declared i the fuctio declaratio The call-by-value mechaism Whe a fuctio is called the formal parameters are iitialized to the values of the argumets i the fuctio call Display 4.13 (1) Display 4.13 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-58

59 Block Scope Local ad global variables coform to the rules of Block Scope The code block (geerally defied by the { }) where a idetifier like a variable is declared determies the scope of the idetifier Blocks ca be ested Display 4.14 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 1-59

60 Namespaces Revisited The start of a file is ot always the best place for usig amespace std; Differet fuctios may use differet amespaces Placig usig amespace std; iside the startig brace of a fuctio Allows the use of differet amespaces i differet fuctios Makes the usig directive local to the fuctio Display 4.15 (1) Display 4.15 (2) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-60

61 Example: Factorial! Represets the factorial fuctio! = 1 x 2 x 3 x x The C++ versio of the factorial fuctio foud i Display 3.14 Requires oe argumet of type it, Returs a value of type it Uses a local variable to store the curret product Decremets each time it does aother multiplicatio * -1 * -2 * * 1 Display 4.16 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-61

62 4.6 Overloadig Fuctio Names Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

63 Overloadig Fuctio Names C++ allows more tha oe defiitio for the same fuctio ame Very coveiet for situatios i which the same fuctio is eeded for differet umbers or types of argumets Overloadig a fuctio ame meas providig more tha oe declaratio ad defiitio usig the same fuctio ame Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-63

64 Overloadig Examples double ave(double 1, double 2) { retur ((1 + 2) / 2); } double ave(double 1, double 2, double 3) { retur (( ) / 3); } Compiler checks the umber ad types of argumets i the fuctio call to decide which fuctio to use cout << ave( 10, 20, 30); uses the secod defiitio Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-64

65 Overloadig Details Overloaded fuctios Must have differet umbers of formal parameters AND / OR Must have at least oe differet type of parameter Must retur a value of the same type Display 4.17 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-65

66 Overloadig Example Revisig the Pizza Buyig program Rectagular pizzas are ow offered! Chage the iput ad add a fuctio to compute the uit price of a rectagular pizza The ew fuctio could be amed uitprice_rectagular Or, the ew fuctio could be a ew (overloaded) versio of the uitprice fuctio that is already used Example: double uitprice(it legth, it width, double price) { double area = legth * width; retur (price / area); } Display 4.18 (1 3) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-66

67 Automatic Type Coversio Give the defiitio double mpg(double miles, double gallos) { retur (miles / gallos); } what will happe if mpg is called i this way? cout << mpg(45, 2) << miles per gallo ; The values of the argumets will automatically be coverted to type double (45.0 ad 2.0) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-67

68 Type Coversio Problem Give the previous mpg defiitio ad the followig defiitio i the same program it mpg(it goals, it misses) // returs the Measure of Perfect Goals { retur (goals misses); } what happes if mpg is called this way ow? cout << mpg(45, 2) << miles per gallo ; The compiler chooses the fuctio that matches parameter types so the Measure of Perfect Goals will be calculated Do ot use the same fuctio ame for urelated fuctios Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-68

69 Sectio 4.6 Coclusio Ca you Describe Top-Dow Desig? Describe the types of tasks we have see so far that could be implemeted as C++ fuctios? Describe the priciples of The black box Procedural abstractio Iformatio hidig Defie local variable? Overload a fuctio ame? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-69

70 Chapter 4 -- Ed Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-70

71 Display 4.1 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-71

72 Display 4.2 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-72

73 Display 4.3 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-73

74 Display 4.3 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-74

75 Display 4.4 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-75

76 Display 4.5 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-76

77 Display 4.5 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-77

78 Display 4.6 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-78

79 Display 4.7 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-79

80 Display 4.8 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-80

81 Display 4.9 (1/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-81

82 Display 4.9 (2/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-82

83 Display 4.9 (3/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-83

84 Display 4.10 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-84

85 Display 4.10 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-85

86 Display 4.11 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-86

87 Display 4.11 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-87

88 Display 4.12 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-88

89 Display 4.12 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-89

90 Display 4.13 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-90

91 Display 4.13 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-91

92 Display 4.14 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-92

93 Display 4.15 (1/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-93

94 Display 4.15 (2/2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-94

95 Display 4.16 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-95

96 Display 4.17 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-96

97 Display 4.18 (1/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-97

98 Display 4.18 (2/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-98

99 Display 4.18 (3/3) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 4-99

Chapter Procedural Abstraction and Functions That Return a Value. Overview. Top-Down Design. Benefits of Top Down Design.

Chapter Procedural Abstraction and Functions That Return a Value. Overview. Top-Down Design. Benefits of Top Down Design. Chapter 4 Procedural Abstraction and Functions That Return a Value Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value

Chapter 4. Procedural Abstraction and Functions That Return a Value Chapter 4 Procedural Abstraction and Functions That Return a Value Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstraction and Functions That Return a Value Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 4 Procedural Abstraction and Functions That Return a Value 1 Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables

More information

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig

More information

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 10 Defiig Classes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types 10.4 Itroductio to Iheritace Copyright 2015 Pearso Educatio,

More information

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 3 More Flow of Cotrol Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 3.1 Usig Boolea Expressios 3.2 Multiway Braches 3.3 More about C++ Loop Statemets 3.4 Desigig Loops Copyright

More information

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 1 Computers ad Programs 1 Objectives To uderstad the respective roles of hardware ad software i a computig system. To lear what computer scietists

More information

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup   Note: Chapter 4 Computatio Bjare Stroustrup www.stroustrup.com/programmig Abstract Today, I ll preset the basics of computatio. I particular, we ll discuss expressios, how to iterate over a series of values

More information

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Pseudocode ( 1.1) High-level descriptio of a algorithm More structured

More information

From last week. Lecture 5. Outline. Principles of programming languages

From last week. Lecture 5. Outline. Principles of programming languages Priciples of programmig laguages From last week Lecture 5 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l ML has o assigmet. Explai how to access a old bidig? Is & for

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

More information

Top-Down Design Predefined Functions Programmer-Defined Functions Procedural Abstraction Local Variables Overloading Function Names

Top-Down Design Predefined Functions Programmer-Defined Functions Procedural Abstraction Local Variables Overloading Function Names Chapter 4 In this chapter, you will learn about: Top-Down Design Predefined Functions Programmer-Defined Functions Procedural Abstraction Local Variables Overloading Function Names Top-Down Design Top-Down

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June CS 1313 010: Programmig for No-Majors, Summer 2007 Programmig Project #3: Two Little Calculatios Due by 12:00pm (oo) Wedesday Jue 27 2007 This third assigmet will give you experiece writig programs that

More information

Programmer-Defined Functions

Programmer-Defined Functions Functions Programmer-Defined Functions Local Variables in Functions Overloading Function Names void Functions, Call-By-Reference Parameters in Functions Programmer-Defined Functions function declaration

More information

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis Overview Chapter 6 Writig a Program Bjare Stroustrup Some thoughts o software developmet The idea of a calculator Usig a grammar Expressio evaluatio Program orgaizatio www.stroustrup.com/programmig 3 Buildig

More information

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis

More information

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects. The

More information

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time ( 3.1) Aalysis of Algorithms Iput Algorithm Output A algorithm is a step- by- step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects.

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Ruig Time Most algorithms trasform iput objects ito output objects. The

More information

How do we evaluate algorithms?

How do we evaluate algorithms? F2 Readig referece: chapter 2 + slides Algorithm complexity Big O ad big Ω To calculate ruig time Aalysis of recursive Algorithms Next time: Litterature: slides mostly The first Algorithm desig methods:

More information

Behavioral Modeling in Verilog

Behavioral Modeling in Verilog Behavioral Modelig i Verilog COE 202 Digital Logic Desig Dr. Muhamed Mudawar Kig Fahd Uiversity of Petroleum ad Mierals Presetatio Outlie Itroductio to Dataflow ad Behavioral Modelig Verilog Operators

More information

Computers and Scientific Thinking

Computers and Scientific Thinking Computers ad Scietific Thikig David Reed, Creighto Uiversity Chapter 15 JavaScript Strigs 1 Strigs as Objects so far, your iteractive Web pages have maipulated strigs i simple ways use text box to iput

More information

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS) CSC165H1, Witer 018 Learig Objectives By the ed of this worksheet, you will: Aalyse the ruig time of fuctios cotaiig ested loops. 1. Nested loop variatios. Each of the followig fuctios takes as iput a

More information

Algorithm. Counting Sort Analysis of Algorithms

Algorithm. Counting Sort Analysis of Algorithms Algorithm Coutig Sort Aalysis of Algorithms Assumptios: records Coutig sort Each record cotais keys ad data All keys are i the rage of 1 to k Space The usorted list is stored i A, the sorted list will

More information

Data Structures and Algorithms. Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms Data Structures ad Algorithms Aalysis of Algorithms Outlie Ruig time Pseudo-code Big-oh otatio Big-theta otatio Big-omega otatio Asymptotic algorithm aalysis Aalysis of Algorithms Iput Algorithm Output

More information

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs What are we goig to lear? CSC316-003 Data Structures Aalysis of Algorithms Computer Sciece North Carolia State Uiversity Need to say that some algorithms are better tha others Criteria for evaluatio Structure

More information

Elementary Educational Computer

Elementary Educational Computer Chapter 5 Elemetary Educatioal Computer. Geeral structure of the Elemetary Educatioal Computer (EEC) The EEC coforms to the 5 uits structure defied by vo Neuma's model (.) All uits are preseted i a simplified

More information

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then UCLA PIC 10 B Problem Solvig usig C++ Programmig Ivo Diov, Asst. Prof. i Mathematics, Neurology, Statistics Istructor: Teachig Assistat: Suzae Nezzar, Mathematics Chapter 13 Templates for More Abstractio

More information

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup Chapter 18 Vectors ad Arrays Bjare Stroustrup Vector revisited How are they implemeted? Poiters ad free store Destructors Iitializatio Copy ad move Arrays Array ad poiter problems Chagig size Templates

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programmig Laguages Fuctioal Programmig Prof. Robert va Egele Overview What is fuctioal programmig? Historical origis of fuctioal programmig Fuctioal programmig today Cocepts of fuctioal programmig

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle: Recursio Recursio Jordi Cortadella Departmet of Computer Sciece Priciple: Reduce a complex problem ito a simpler istace of the same problem Recursio Itroductio to Programmig Dept. CS, UPC 2 Mathematical

More information

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway. Bjare Stroustrup www.stroustrup.com/programmig Chapter 5 Errors Abstract Whe we program, we have to deal with errors. Our most basic aim is correctess, but we must deal with icomplete problem specificatios,

More information

The number n of subintervals times the length h of subintervals gives length of interval (b-a).

The number n of subintervals times the length h of subintervals gives length of interval (b-a). Simulator with MadMath Kit: Riema Sums (Teacher s pages) I your kit: 1. GeoGebra file: Ready-to-use projector sized simulator: RiemaSumMM.ggb 2. RiemaSumMM.pdf (this file) ad RiemaSumMMEd.pdf (educator's

More information

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1 Classes ad Objects jvo@ualg.pt José Valete de Oliveira 4-1 Agai: Distace betwee poits withi the first quadrat Sample iput Sample output 1 1 3 4 2 jvo@ualg.pt José Valete de Oliveira 4-2 1 The simplest

More information

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013 Code Review s Authors: Mika V. Mätylä ad Casper Lasseius Origial versio: 4 Sep, 2007 Made available olie: 24 April, 2013 This documet cotais further details of the code review defects preseted i [1]. of

More information

Task scenarios Outline. Scenarios in Knowledge Extraction. Proposed Framework for Scenario to Design Diagram Transformation

Task scenarios Outline. Scenarios in Knowledge Extraction. Proposed Framework for Scenario to Design Diagram Transformation 6-0-0 Kowledge Trasformatio from Task Scearios to View-based Desig Diagrams Nima Dezhkam Kamra Sartipi {dezhka, sartipi}@mcmaster.ca Departmet of Computig ad Software McMaster Uiversity CANADA SEKE 08

More information

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers? CSE401: Itroductio to Compiler Costructio Larry Ruzzo Sprig 2004 Today s objectives Admiistrative details Defie compilers ad why we study them Defie the high-level structure of compilers Associate specific

More information

Lecture 1: Introduction and Strassen s Algorithm

Lecture 1: Introduction and Strassen s Algorithm 5-750: Graduate Algorithms Jauary 7, 08 Lecture : Itroductio ad Strasse s Algorithm Lecturer: Gary Miller Scribe: Robert Parker Itroductio Machie models I this class, we will primarily use the Radom Access

More information

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering EE 4363 1 Uiversity of Miesota Midterm Exam #1 Prof. Matthew O'Keefe TA: Eric Seppae Departmet of Electrical ad Computer Egieerig Uiversity of Miesota Twi Cities Campus EE 4363 Itroductio to Microprocessors

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015. Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Hash Tables xkcd. http://xkcd.com/221/. Radom Number. Used with permissio uder Creative

More information

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0 Polyomial Fuctios ad Models 1 Learig Objectives 1. Idetify polyomial fuctios ad their degree 2. Graph polyomial fuctios usig trasformatios 3. Idetify the real zeros of a polyomial fuctio ad their multiplicity

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Ruig Time of a algorithm Ruig Time Upper Bouds Lower Bouds Examples Mathematical facts Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite

More information

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming Lecture Notes 6 Itroductio to algorithm aalysis CSS 501 Data Structures ad Object-Orieted Programmig Readig for this lecture: Carrao, Chapter 10 To be covered i this lecture: Itroductio to algorithm aalysis

More information

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS APPLICATION NOTE PACE175AE BUILT-IN UNCTIONS About This Note This applicatio brief is iteded to explai ad demostrate the use of the special fuctios that are built ito the PACE175AE processor. These powerful

More information

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence _9.qxd // : AM Page Chapter 9 Sequeces, Series, ad Probability 9. Sequeces ad Series What you should lear Use sequece otatio to write the terms of sequeces. Use factorial otatio. Use summatio otatio to

More information

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen COP4020 mig Laguages Compilers ad Iterpreters Prof. Robert va Egele Overview Commo compiler ad iterpreter cofiguratios Virtual machies Itegrated developmet eviromets Compiler phases Lexical aalysis Sytax

More information

The Magma Database file formats

The Magma Database file formats The Magma Database file formats Adrew Gaylard, Bret Pikey, ad Mart-Mari Breedt Johaesburg, South Africa 15th May 2006 1 Summary Magma is a ope-source object database created by Chris Muller, of Kasas City,

More information

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions U.C. Berkeley CS170 : Algorithms Midterm 1 Solutios Lecturers: Sajam Garg ad Prasad Raghavedra Feb 1, 017 Midterm 1 Solutios 1. (4 poits) For the directed graph below, fid all the strogly coected compoets

More information

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8) CIS 11 Data Structures ad Algorithms with Java Fall 017 Big-Oh Notatio Tuesday, September 5 (Make-up Friday, September 8) Learig Goals Review Big-Oh ad lear big/small omega/theta otatios Practice solvig

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity Time CSE 47: Algorithms ad Computatioal Readig assigmet Read Chapter of The ALGORITHM Desig Maual Aalysis & Sortig Autum 00 Paul Beame aalysis Problem size Worst-case complexity: max # steps algorithm

More information

Lecture 9: Exam I Review

Lecture 9: Exam I Review CS 111 (Law): Program Desig I Lecture 9: Exam I Review Robert H. Sloa & Richard Warer Uiversity of Illiois, Chicago September 22, 2016 This Class Discuss midterm topics Go over practice examples Aswer

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

One advantage that SONAR has over any other music-sequencing product I ve worked

One advantage that SONAR has over any other music-sequencing product I ve worked *gajedra* D:/Thomso_Learig_Projects/Garrigus_163132/z_productio/z_3B2_3D_files/Garrigus_163132_ch17.3d, 14/11/08/16:26:39, 16:26, page: 647 17 CAL 101 Oe advatage that SONAR has over ay other music-sequecig

More information

6.854J / J Advanced Algorithms Fall 2008

6.854J / J Advanced Algorithms Fall 2008 MIT OpeCourseWare http://ocw.mit.edu 6.854J / 18.415J Advaced Algorithms Fall 2008 For iformatio about citig these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.415/6.854 Advaced Algorithms

More information

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types Aoucemets HW9 due today HW10 comig up, will post after class Team assigmet Data abstractio (types) ad cotrol abstractio (parameter passig) Due o Tuesday, November 27 th Last Class Types Type systems Type

More information

Performance Plus Software Parameter Definitions

Performance Plus Software Parameter Definitions Performace Plus+ Software Parameter Defiitios/ Performace Plus Software Parameter Defiitios Chapma Techical Note-TG-5 paramete.doc ev-0-03 Performace Plus+ Software Parameter Defiitios/2 Backgroud ad Defiitios

More information

ENGI 4421 Probability and Statistics Faculty of Engineering and Applied Science Problem Set 1 Descriptive Statistics

ENGI 4421 Probability and Statistics Faculty of Engineering and Applied Science Problem Set 1 Descriptive Statistics ENGI 44 Probability ad Statistics Faculty of Egieerig ad Applied Sciece Problem Set Descriptive Statistics. If, i the set of values {,, 3, 4, 5, 6, 7 } a error causes the value 5 to be replaced by 50,

More information

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6 Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #5 due today Lab #3

More information

Chapter 3 Classification of FFT Processor Algorithms

Chapter 3 Classification of FFT Processor Algorithms Chapter Classificatio of FFT Processor Algorithms The computatioal complexity of the Discrete Fourier trasform (DFT) is very high. It requires () 2 complex multiplicatios ad () complex additios [5]. As

More information

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 6 I/O Streams as a Itroductio to Objects ad Classes Overview 6.1 Streams ad Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams ad Basic File I/O I/O Streams I/O refers

More information

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions CS 111: Program Desig I Lecture # 7: First Loop, Web Crawler, Fuctios Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 18, 2018 What will this prit? x = 5 if x == 3: prit("hi!")

More information

South Slave Divisional Education Council. Math 10C

South Slave Divisional Education Council. Math 10C South Slave Divisioal Educatio Coucil Math 10C Curriculum Package February 2012 12 Strad: Measuremet Geeral Outcome: Develop spatial sese ad proportioal reasoig It is expected that studets will: 1. Solve

More information

C++ Basics - 3 Rahul

C++ Basics - 3 Rahul C++ Basics - 3 Rahul Deodhar @rahuldeodhar www.rahuldeodhar.com rahuldeodhar@gmail.com Topics for today Func@ons Classwork Topics for today Homework Program Others Procedural Abstrac@on & Func@ons Top

More information

Location Steps and Paths

Location Steps and Paths Locatio Steps ad Paths 3 INTHIS CHAPTER Uderstadig Locatio Steps ad Paths How do locatio paths work? We took a look at locatio paths i the overview i Chapter 1, where we saw that locatio paths look much

More information

CSE 111 Bio: Program Design I Class 11: loops

CSE 111 Bio: Program Design I Class 11: loops SE 111 Bio: Program Desig I lass 11: loops Radall Muroe, xkcd.com/1411/ Robert H. Sloa (S) & Rachel Poretsky (Bio) Uiversity of Illiois, hicago October 2, 2016 Pytho ets Loopy! he Pytho, Busch ardes Florida

More information

Chapter 4 The Datapath

Chapter 4 The Datapath The Ageda Chapter 4 The Datapath Based o slides McGraw-Hill Additioal material 24/25/26 Lewis/Marti Additioal material 28 Roth Additioal material 2 Taylor Additioal material 2 Farmer Tae the elemets that

More information

Arithmetic Sequences

Arithmetic Sequences . Arithmetic Sequeces COMMON CORE Learig Stadards HSF-IF.A. HSF-BF.A.1a HSF-BF.A. HSF-LE.A. Essetial Questio How ca you use a arithmetic sequece to describe a patter? A arithmetic sequece is a ordered

More information

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70 NOTE:. Attempt all seve questios. Major CSL 02 2. Write your ame ad etry o o every sheet of the aswer script. Time 2 Hrs Max Marks 70 Q No Q Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 Total MM 6 2 4 0 8 4 6 70 Q. Write a

More information

DEFINITION OF CELL BEHAVIOUR. Actions and Behaviour. CELL = a CELL CELL = b CELL

DEFINITION OF CELL BEHAVIOUR. Actions and Behaviour. CELL = a CELL CELL = b CELL Actios ad Behaviour Let us start to itroduce some modellig laguage features which will allow us to model the behaviour of a cell compoet. Suppose the cell compoet holds a sigle piece of iformatio which

More information

condition w i B i S maximum u i

condition w i B i S maximum u i ecture 10 Dyamic Programmig 10.1 Kapsack Problem November 1, 2004 ecturer: Kamal Jai Notes: Tobias Holgers We are give a set of items U = {a 1, a 2,..., a }. Each item has a weight w i Z + ad a utility

More information

Topics. Instance object. Instance object. Fundamentals of OT. Object notation. How do objects collaborate? Pearson Education 2007 Appendix (RASD 3/e)

Topics. Instance object. Instance object. Fundamentals of OT. Object notation. How do objects collaborate? Pearson Education 2007 Appendix (RASD 3/e) Appedix (RASD 3/e) MACIASZEK, L.A. (2007): Requiremets Aalysis ad System Desig, 3 rd ed. Addiso Wesley, Harlow Eglad ISBN 978-0-321-44036-5 Appedix Fudametals of Object Techology Pearso Educatio Limited

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Uiversity of Waterloo Departmet of Electrical ad Computer Egieerig ECE 250 Algorithms ad Data Structures Midterm Examiatio ( pages) Istructor: Douglas Harder February 7, 2004 7:30-9:00 Name (last, first)

More information

GE FUNDAMENTALS OF COMPUTING AND PROGRAMMING UNIT III

GE FUNDAMENTALS OF COMPUTING AND PROGRAMMING UNIT III GE2112 - FUNDAMENTALS OF COMPUTING AND PROGRAMMING UNIT III PROBLEM SOLVING AND OFFICE APPLICATION SOFTWARE Plaig the Computer Program Purpose Algorithm Flow Charts Pseudocode -Applicatio Software Packages-

More information

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control EE 459/500 HDL Based Digital Desig with Programmable Logic Lecture 13 Cotrol ad Sequecig: Hardwired ad Microprogrammed Cotrol Refereces: Chapter s 4,5 from textbook Chapter 7 of M.M. Mao ad C.R. Kime,

More information

Exceptions. Your computer takes exception. The Exception Class. Causes of Exceptions

Exceptions. Your computer takes exception. The Exception Class. Causes of Exceptions Your computer takes exceptio s s are errors i the logic of a program (ru-time errors). Examples: i thread mai java.io.filenotfoud: studet.txt (The system caot fid the file specified.) i thread mai java.lag.nullpoiter:

More information

1.2 Binomial Coefficients and Subsets

1.2 Binomial Coefficients and Subsets 1.2. BINOMIAL COEFFICIENTS AND SUBSETS 13 1.2 Biomial Coefficiets ad Subsets 1.2-1 The loop below is part of a program to determie the umber of triagles formed by poits i the plae. for i =1 to for j =

More information

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output File class i Java File Iput ad Output TOPICS File Iput Exceptio Hadlig File Output Programmers refer to iput/output as "I/O". The File class represets files as objects. The class is defied i the java.io

More information

Examples and Applications of Binary Search

Examples and Applications of Binary Search Toy Gog ITEE Uiersity of Queeslad I the secod lecture last week we studied the biary search algorithm that soles the problem of determiig if a particular alue appears i a sorted list of iteger or ot. We

More information

Goals of the Lecture Object Constraint Language

Goals of the Lecture Object Constraint Language Goals of the Lecture Object Costrait Laguage Object-Orieted Aalysis ad Desig - Fall 1998 Preset the Object Costrait Laguage Ð As best as possible, with the limited iformatio available from UML i a Nutshell

More information

Parabolic Path to a Best Best-Fit Line:

Parabolic Path to a Best Best-Fit Line: Studet Activity : Fidig the Least Squares Regressio Lie By Explorig the Relatioship betwee Slope ad Residuals Objective: How does oe determie a best best-fit lie for a set of data? Eyeballig it may be

More information

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion Aoucemets HW6 due today HW7 is out A team assigmet Submitty page will be up toight Fuctioal correctess: 75%, Commets : 25% Last class Equality testig eq? vs. equal? Higher-order fuctios map, foldr, foldl

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004 8 Programs ad data This publicatio forms part of a Ope Uiversity course M150 Data, Computig ad Iformatio. Details of this ad other Ope Uiversity courses ca be obtaied from the Course Iformatio ad Advice

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions: CS 604 Data Structures Midterm Sprig, 00 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Istructios: Prit your ame i the space provided below. This examiatio is closed book ad closed

More information

WORKED EXAMPLE 7.1. Producing a Mass Mailing. We want to automate the process of producing mass mailings. A typical letter might look as follows:

WORKED EXAMPLE 7.1. Producing a Mass Mailing. We want to automate the process of producing mass mailings. A typical letter might look as follows: Worked Example 7.1 Producig a Mass Mailig 1 WORKED EXAMPLE 7.1 Producig a Mass Mailig We wat to automate the process of producig mass mailigs. A typical letter might look as follows: To: Ms. Sally Smith

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information