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

Size: px
Start display at page:

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

Transcription

1

2 Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

3 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 Style Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-3

4 2.1 Variables ad Assigmets Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

5 Variables ad Assigmets Variables are like small blackboards We ca write a umber o them We ca chage the umber We ca erase the umber C++ variables are ames for memory locatios We ca write a value i them We ca chage the value stored there We caot erase the memory locatio Some value is always there Display 2.1 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-5

6 Idetifiers Variables ames are called idetifiers Choosig variable ames Use meaigful ames that represet data to be stored First character must be a letter the uderscore character Remaiig characters must be letters umbers uderscore character Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-6

7 Keywords Keywords (also called reserved words) Are used by the C++ laguage Must be used as they are defied i the programmig laguage Caot be used as idetifiers Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-7

8 Declarig Variables (Part 1) Before use, variables must be declared Tells the compiler the type of data to store Examples: it umber_of_bars; double oe_weight, total_weight; it is a abbreviatio for iteger. could store 3, 102, 3211, -456, etc. umber_of_bars is of type iteger double represets umbers with a fractioal compoet could store 1.34, 4.0, , etc. oe_weight ad total_weight are both of type double Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

9 Declarig Variables (Part 2) Immediately prior to use Two locatios for variable declaratios it mai() { it sum; sum = score1 + score 2; retur 0; } At the begiig it mai() { it sum; sum = score1 + score2; retur 0; } Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-9

10 Declarig Variables (Part 3) Declaratio sytax: Type_ame Variable_1, Variable_2,... ; Declaratio Examples: double average, m_score, total_score; double moo_distace; it age, um_studets; it cars_waitig; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-10

11 Assigmet Statemets A assigmet statemet chages the value of a variable total_weight = oe_weight + umber_of_bars; total_weight is set to the sum oe_weight + umber_of_bars Assigmet statemets ed with a semi-colo The sigle variable to be chaged is always o the left of the assigmet operator = O the right of the assigmet operator ca be Costats -- age = 21; Variables -- my_cost = your_cost; Expressios -- circumferece = diameter * ; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-11

12 Assigmet Statemets ad Algebra The = operator i C++ is ot a equal sig The followig statemet caot be true i algebra umber_of_bars = umber_of_bars + 3; I C++ it meas the ew value of umber_of_bars is the previous value of umber_of_bars plus 3 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-12

13 Iitializig Variables Declarig a variable does ot give it a value Givig a variable its first value is iitializig the variable Variables are iitialized i assigmet statemets double mpg; // declare the variable mpg = 26.3; // iitialize the variable Declaratio ad iitializatio ca be combied usig two methods Method 1 double mpg = 26.3, area = 0.0, volume; Method 2 double mpg(26.3), area(0.0), volume; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-13

14 Sectio 2.1 Coclusio Ca you Declare ad iitialize two itegers variables to zero? The variables are amed feet ad iches. Declare ad iitialize two variables, oe it ad oe double? Both should be iitialized to the appropriate form of 5. Give good variable ames for idetifiers to store the speed of a automobile? a hourly pay rate? the highest score o a exam? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-14

15 2.2 Iput ad Output Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

16 Iput ad Output A data stream is a sequece of data Typically i the form of characters or umbers A iput stream is data for the program to use Typically origiates at the keyboard at a file A output stream is the program s output Destiatio is typically the moitor a file Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-16

17 Output usig cout cout is a output stream sedig data to the moitor The isertio operator "<<" iserts data ito cout Example: cout << umber_of_bars << " cady bars\"; This lie seds two items to the moitor The value of umber_of_bars The quoted strig of characters " cady bars\" Notice the space before the c i cady The \ causes a ew lie to be started followig the s i bars A ew isertio operator is used for each item of output Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-17

18 Examples Usig cout This produces the same result as the previous sample cout << umber_of_bars ; cout << " cady bars\"; Here arithmetic is performed i the cout statemet cout << "Total cost is $" << (price + tax); Quoted strigs are eclosed i double quotes ("Walter") Do t use two sigle quotes (') A blak space ca also be iserted with cout << " " ; if there are o strigs i which a space is desired as i " cady bars\" Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-18

19 Iclude Directives Iclude Directives add library files to our programs To make the defiitios of the ci ad cout available to the program: #iclude <iostream> Usig Directives iclude a collectio of defied ames To make the ames ci ad cout available to our program: usig amespace std; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-19

20 Escape Sequeces Escape sequeces tell the compiler to treat characters i a special way '\' is the escape character To create a ewlie i output use \ cout << "\"; or the ewer alterative cout << edl; Other escape sequeces: \t -- a tab \\ -- a backslash character \" -- a quote character Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-20

21 Formattig Real Numbers Real umbers (type double) produce a variety of outputs double price = 78.5; cout << "The price is $" << price << edl; The output could be ay of these: The price is $78.5 The price is $ The price is $ e01 The most ulikely output is: The price is $78.50 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-21

22 Showig Decimal Places cout icludes tools to specify the output of type double To specify fixed poit otatio setf(ios::fixed) To specify that the decimal poit will always be show setf(ios::showpoit) To specify that two decimal places will always be show precisio(2) Example: cout.setf(ios::fixed); cout.setf(ios::showpoit); cout.precisio(2); cout << "The price is " << price << edl; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-22

23 Iput Usig ci ci is a iput stream brigig data from the keyboard The extractio operator (>>) removes data to be used Example: cout << "Eter the umber of bars i a package\"; cout << " ad the weight i ouces of oe bar.\"; ci >> umber_of_bars; ci >> oe_weight; This code prompts the user to eter data the reads two data items from ci The first value read is stored i umber_of_bars The secod value read is stored i oe_weight Data is separated by spaces whe etered Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-23

24 Readig Data From ci Multiple data items are separated by spaces Data is ot read util the eter key is pressed Allows user to make correctios Example: ci >> v1 >> v2 >> v3; Requires three space separated values User might type <eter key> Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-24

25 Desigig Iput ad Output Prompt the user for iput that is desired cout statemets provide istructios cout << "Eter your age: "; ci >> age; Notice the absece of a ew lie before usig ci Echo the iput by displayig what was read Gives the user a chace to verify data cout << age << " was etered." << edl; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-25

26 Sectio 2.2 Coclusio Ca you write a iput statemet to place a value i the variable the_umber? Write the output statemet to prompt for the value to store i the_umber? Write a output statemet that produces a ewlie? Format output of ratioal umbers to show 4 decimal places? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-26

27 2.3 Data Types ad Expressios Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

28 Data Types ad Expressios 2 ad 2.0 are ot the same umber A whole umber such as 2 is of type it A real umber such as 2.0 is of type double Numbers of type it are stored as exact values Numbers of type double may be stored as approximate values due to limitatios o umber of sigificat digits that ca be represeted Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-28

29 Writig Iteger costats Type it does ot cotai decimal poits Examples: Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-29

30 Writig Double Costats Type double ca be writte i two ways Simple form must iclude a decimal poit Examples: Floatig Poit Notatio (Scietific Notatio) Examples: 3.41e1 meas e17 meas e-6 meas Number left of e does ot require a decimal poit Expoet caot cotai a decimal poit Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-30

31 Other Number Types Various umber types have differet memory requiremets More precisio requires more bytes of memory Very large umbers require more bytes of memory Very small umbers require more bytes of memory Display 2.2 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-31

32 Iteger types log or log it (ofte 4 bytes) Equivalet forms to declare very large itegers log big_total; log it big_total; short or short it (ofte 2 bytes) Equivalet forms to declare smaller itegers short small_total; short it small_total; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-32

33 Floatig poit types log double (ofte 10 bytes) Declares floatig poit umbers with up to 19 sigificat digits log double big_umber; float (ofte 4 bytes) Declares floatig poit umbers with up to 7 sigificat digits float ot_so_big_umber; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-33

34 Type char Computers process character data too char Short for character Ca be ay sigle character from the keyboard To declare a variable of type char: char letter; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-34

35 char costats Character costats are eclosed i sigle quotes char letter = 'a'; Strigs of characters, eve if oly oe character is eclosed i double quotes "a" is a strig of characters cotaiig oe character 'a' is a value of type character Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-35

36 C++11 Types The size of umeric data types ca vary from oe machie to aother. For example, a it might be 32 bits or 64 bits C++11 itroduced ew iteger types that specify exactly the size ad whether or ot the data type is siged or usiged Display 2.3 C++11 also has a auto type that deduces the type of the variable based o the expressio o the right had side of the assigmet auto x = 2.4 * 10; // x becomes a double due to 2.4 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-36

37 Readig Character Data ci skips blaks ad lie breaks lookig for data The followig reads two characters but skips ay space that might be betwee char symbol1, symbol2; ci >> symbol1 >> symbol2; User ormally separate data items by spaces J D Results are the same if the data is ot separated by spaces JD Display 2.4 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-37

38 Type strig strig is a class, differet from the primitive data types discussed so far Differece is discussed i Chapter 8 Use double quotes aroud the text to store ito the strig variable Requires the followig be added to the top of your program: #iclude <strig> To declare a variable of type strig: Display 2.5 strig ame = "Apu Nahasapeemapetilo"; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-38

39 Type Compatibilities I geeral store values i variables of the same type This is a type mismatch: it it_variable; it_variable = 2.99; If your compiler allows this, it_variable will most likely cotai the value 2, ot 2.99 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-39

40 it ßà double (part 1) Variables of type double should ot be assiged to variables of type it it it_variable; double double_variable; double_variable = 2.00; it_variable = double_variable; If allowed, it_variable cotais 2, ot 2.00 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-40

41 it ßà double (part 2) Iteger values ca ormally be stored i variables of type double double double_variable; double_variable = 2; double_variable will cotai 2.0 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-41

42 char ß à it The followig actios are possible but geerally ot recommeded! It is possible to store char values i iteger variables it value = 'A'; value will cotai a iteger represetig 'A' It is possible to store it values i char variables char letter = 65; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-42

43 bool ß à it The followig actios are possible but geerally ot recommeded! Values of type bool ca be assiged to it variables True is stored as 1 False is stored as 0 Values of type it ca be assiged to bool variables Ay o-zero iteger is stored as true Zero is stored as false Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-43

44 Arithmetic Arithmetic is performed with operators + for additio - for subtractio * for multiplicatio / for divisio Example: storig a product i the variable total_weight total_weight = oe_weight * umber_of_bars; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-44

45 Results of Operators Arithmetic operators ca be used with ay umeric type A operad is a umber or variable used by the operator Result of a operator depeds o the types of operads If both operads are it, the result is it If oe or both operads are double, the result is double Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-45

46 Divisio of Doubles Divisio with at least oe operator of type double produces the expected results. double divisor, divided, quotiet; divisor = 3; divided = 5; quotiet = divided / divisor; quotiet = Result is the same if either divided or divisor is of type it Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-46

47 Divisio of Itegers Be careful with the divisio operator! it / it produces a iteger result (true for variables or umeric costats) it divided, divisor, quotiet; divided = 5; divisor = 3; quotiet = divided / divisor; The value of quotiet is 1, ot Iteger divisio does ot roud the result, the fractioal part is discarded! Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-47

48 Iteger Remaiders % operator gives the remaider from iteger divisio it divided, divisor, remaider; divided = 5; divisor = 3; remaider = divided % divisor; The value of remaider is 2 Display 2.6 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-48

49 Arithmetic Expressios Use spacig to make expressios readable Which is easier to read? x+y*z or x + y * z Display 2.7 Precedece rules for operators are the same as used i your algebra classes Use paretheses to alter the order of operatios x + y * z ( y is multiplied by z first) (x + y) * z ( x ad y are added first) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-49

50 Operator Shorthad Some expressios occur so ofte that C++ cotais to shorthad operators for them All arithmetic operators ca be used this way += cout = cout + 2; becomes cout += 2; *= bous = bous * 2; becomes bous *= 2; /= time = time / rush_factor; becomes time /= rush_factor; %= remaider = remaider % (ct1+ ct2); becomes remaider %= (ct1 + ct2); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-50

51 2.4 Simple Flow of Cotrol Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

52 Simple Flow of Cotrol Flow of cotrol The order i which statemets are executed Brach Lets program choose betwee two alteratives Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-52

53 Brach Example To calculate hourly wages there are two choices Regular time ( up to 40 hours) gross_pay = rate * hours; Overtime ( over 40 hours) gross_pay = rate * * rate * (hours - 40); The program must choose which of these expressios to use Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-53

54 Desigig the Brach Decide if (hours >40) is true If it is true, the use gross_pay = rate * * rate * (hours - 40); If it is ot true, the use gross_pay = rate * hours; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-54

55 Implemetig the Brach if-else statemet is used i C++ to perform a brach if (hours > 40) gross_pay = rate * * rate * (hours - 40); else gross_pay = rate * hours; Display 2.8 Display 2.9 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-55

56 Boolea Expressios Boolea expressios are expressios that are either true or false compariso operators such as '>' (greater tha) are used to compare variables ad/or umbers (hours > 40) Icludig the paretheses, is the boolea expressio from the wages example A few of the compariso operators that use two symbols (No spaces allowed betwee the symbols!) >= greater tha or equal to!= ot equal or iequality = = equal or equivalet Display 2.10 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-56

57 if-else Flow Cotrol (1) if (boolea expressio) true statemet else false statemet Whe the boolea expressio is true Oly the true statemet is executed Whe the boolea expressio is false Oly the false statemet is executed Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-57

58 if-else Flow Cotrol (2) if (boolea expressio) { true statemets } else { false statemets } Whe the boolea expressio is true Oly the true statemets eclosed i { } are executed Whe the boolea expressio is false Oly the false statemets eclosed i { } are executed Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-58

59 AND Boolea expressios ca be combied ito more complex expressios with && -- The AND operator True if both expressios are true Sytax: (Compariso_1) && (Compariso_2) Example: if ( (2 < x) && (x < 7) ) True oly if x is betwee 2 ad 7 Iside paretheses are optioal but ehace meaig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-59

60 OR -- The OR operator (o space!) True if either or both expressios are true Sytax: (Compariso_1) (Compariso_2) Example: if ( ( x = = 1) ( x = = y) ) True if x cotais 1 True if x cotais the same value as y True if both comparisos are true Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-60

61 NOT! -- egates ay boolea expressio!( x < y) True if x is NOT less tha y!(x = = y) True if x is NOT equal to y! Operator ca make expressios difficult to uderstad use oly whe appropriate Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-61

62 Iequalities Be careful traslatig iequalities to C++ if x < y < z traslates as if ( ( x < y ) && ( y < z ) ) NOT if ( x < y < z ) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-62

63 Pitfall: Usig = or == ' = ' is the assigmet operator Used to assig values to variables Example: x = 3; '= = ' is the equality operator Used to compare values Example: if ( x == 3) The compiler will accept this error: if (x = 3) but stores 3 i x istead of comparig x ad 3 Sice the result is 3 (o-zero), the expressio is true Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-63

64 Compoud Statemets A compoud statemet is more tha oe statemet eclosed i { } Braches of if-else statemets ofte eed to execute more that oe statemet Example: if (boolea expressio) { true statemets } else { false statemets } Display 2.11 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-64

65 Braches Coclusio Ca you Write a if-else statemet that outputs the word High if the value of the variable score is greater tha 100 ad Low if the value of score is at most 100? The variables are of type it. Write a if-else statemet that outputs the word Warig provided that either the value of the variable temperature is greater tha or equal to 100, or the of the variable pressure is greater tha or equal to 200, or both. Otherwise, the if_else sttemet outputs the word OK. The variables are of type it. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-65

66 Simple Loops Whe a actio must be repeated, a loop is used C++ icludes several ways to create loops We start with the while-loop Example: while (cout_dow > 0) { cout << "Hello "; cout_dow -= 1; } Output: Hello Hello Hello whe cout_dow starts at 3 Display 2.12 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-66

67 While Loop Operatio First, the boolea expressio is evaluated If false, the program skips to the lie followig the while loop If true, the body of the loop is executed Durig executio, some item from the boolea expressio is chaged After executig the loop body, the boolea expressio is checked agai repeatig the process util the expressio becomes false A while loop might ot execute at all if the boolea expressio is false o the first check Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-67

68 while Loop Sytax while (boolea expressio is true) { statemets to repeat } Semi-colos are used oly to ed the statemets withi the loop while (boolea expressio is true) statemet to repeat Display 2.13 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-68

69 do-while loop A variatio of the while loop. A do-while loop is always executed at least oce The body of the loop is first executed The boolea expressio is checked after the body has bee executed Sytax: do { statemets to repeat Display 2.14 Display 2.15 } while (boolea_expressio); Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-69

70 Icremet/Decremet Uary operators require oly oe operad + i frot of a umber such as +5 - i frot of a umber such as icremet operator Adds 1 to the value of a variable x ++; is equivalet to x = x + 1; -- decremet operator Subtracts 1 from the value of a variable x --; is equivalet to x = x 1; Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-70

71 Sample Program Bak charge card balace of $50 2% per moth iterest How may moths without paymets before your balace exceeds $100 After 1 moth: $50 + 2% of $50 = $51 After 2 moths: $51 + 2% of $51 = $52.02 After 3 moths: $ % of $52.02 Display 2.16 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-71

72 Ifiite Loops Loops that ever stop are ifiite loops The loop body should cotai a lie that will evetually cause the boolea expressio to become false Example: Prit the odd umbers less tha 12 x = 1; while (x!= 12) { cout << x << edl; x = x + 2; } Better to use this compariso: while ( x < 12) Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-72

73 Sectio 2.4 Coclusio Ca you Show the output of this code if x is of type it? x = 10; while ( x > 0) { cout << x << edl; x = x 3; } Show the output of the previous code usig the compariso x < 0 istead of x > 0? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-73

74 2.5 Program Style Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

75 Program Style A program writte with attetio to style is easier to read easier to correct easier to chage Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-75

76 Program Style - Idetig Items cosidered a group should look like a group Skip lies betwee logical groups of statemets Idet statemets withi statemets if (x = = 0) statemet; Braces {} create groups Idet withi braces to make the group clear Braces placed o separate lies are easier to locate Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-76

77 Program Style - Commets // is the symbol for a sigle lie commet Commets are explaatory otes for the programmer All text o the lie followig // is igored by the compiler Example: //calculate regular wages gross_pay = rate * hours; /* ad */ eclose multiple lie commets Example: /* This is a commet that spas multiple lies without a commet symbol o the middle lie */ Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-77

78 Program Style - Costats Number costats have o memoic value Number costats used throughout a program are difficult to fid ad chage whe eeded Costats Allow us to ame umber costats so they have meaig Allow us to chage all occurreces simply by chagig the value of the costat Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-78

79 Costats cost is the keyword to declare a costat Example: cost it WINDOW_COUNT = 10; declares a costat amed WINDOW_COUNT Its value caot be chaged by the program like a variable It is commo to ame costats with all capitals Display 2.17 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-79

80 Sectio 2.5 Coclusio Ca you Create a amed costat of type double? Determie if a program ca modify the value of a costat? Describe the beefits of commets? Explai why idetig is importat i a program? Explai why blak lies are importat i a program? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-80

81 Chapter 2 -- Ed Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-81

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

83 Display 2.1 (2 /2) Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-83

84 Display 2.2 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-84

85 Display 2.3 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-85

86 Display 2.4 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-86

87 Display 2.5 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-87

88 Display 2.6 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-88

89 Display 2.7 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-89

90 Display 2.8 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-90

91 Display 2.9 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-91

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

93 Display 2.11 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-93

94 Display 2.12 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-94

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

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

97 Display 2.15 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-97

98 Display 2.16 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-98

99 Display 2.17 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 2-99

Chapter 2. C++ Basics

Chapter 2. C++ Basics Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

More information

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Copyright 2011 Pearson Addison-Wesley. All rights

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 Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

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

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

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

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

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

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

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

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

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

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

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

. 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 3. Floating Point Arithmetic

Chapter 3. Floating Point Arithmetic COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 3 Floatig Poit Arithmetic Review - Multiplicatio 0 1 1 0 = 6 multiplicad 32-bit ALU shift product right multiplier add

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

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

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

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

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

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

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

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

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

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

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

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

Java Expressions & Flow Control

Java Expressions & Flow Control Java Expressios & Flow Cotrol Rui Moreira Expressio Separators:. [ ] ( ), ; Dot used as decimal separator or to access attributes ad methods double d = 2.6; Poto poto = ew Poto(2, 3); it i = poto.x; it

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

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

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

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

Appendix D. Controller Implementation

Appendix D. Controller Implementation COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Appedix D Cotroller Implemetatio Cotroller Implemetatios Combiatioal logic (sigle-cycle); Fiite state machie (multi-cycle, pipelied);

More information

Exercise 6 (Week 42) For the foreign students only.

Exercise 6 (Week 42) For the foreign students only. These are the last exercises of the course. Please, remember that to pass exercises, the sum of the poits gathered by solvig the questios ad attedig the exercise groups must be at least 4% ( poits) of

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

The VSS CCD photometry spreadsheet

The VSS CCD photometry spreadsheet The VSS CCD photometry spreadsheet Itroductio This Excel spreadsheet has bee developed ad tested by the BAA VSS for aalysig results files produced by the multi-image CCD photometry procedure i AIP4Wi v2.

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

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

Investigation Monitoring Inventory

Investigation Monitoring Inventory Ivestigatio Moitorig Ivetory Name Period Date Art Smith has bee providig the prits of a egravig to FieArt Gallery. He plas to make just 2000 more prits. FieArt has already received 70 of Art s prits. The

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

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

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

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

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

It just came to me that I 8.2 GRAPHS AND CONVERGENCE

It just came to me that I 8.2 GRAPHS AND CONVERGENCE 44 Chapter 8 Discrete Mathematics: Fuctios o the Set of Natural Numbers (a) Take several odd, positive itegers for a ad write out eough terms of the 3N sequece to reach a repeatig loop (b) Show that ot

More information

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer Departmet of Computer ciece Columbia Uiversity olutios to Fial COM W45 Programmig Laguages ad Traslators Moday, May 4, 2009 4:0-5:25pm, 309 Havemeyer Closed book, o aids. Do questios 5. Each questio is

More information

Introduction CHAPTER Computers

Introduction CHAPTER Computers Iside a Computer CHAPTER Itroductio. Computers A computer is a electroic device that accepts iput, stores data, processes data accordig to a set of istructios (called program), ad produces output i desired

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

Math 3201 Notes Chapter 4: Rational Expressions & Equations

Math 3201 Notes Chapter 4: Rational Expressions & Equations Learig Goals: See p. tet.. Equivalet Ratioal Epressios ( classes) Read Goal p. 6 tet. Math 0 Notes Chapter : Ratioal Epressios & Equatios. Defie ad give a eample of a ratioal epressio. p. 6. Defie o-permissible

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

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

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Part A Datapath Design

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Part A Datapath Design COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter The Processor Part A path Desig Itroductio CPU performace factors Istructio cout Determied by ISA ad compiler. CPI ad

More information

12-5A. Equivalent Fractions and Decimals. 1 Daily Common Core Review. Common Core. Lesson. Lesson Overview. Math Background

12-5A. Equivalent Fractions and Decimals. 1 Daily Common Core Review. Common Core. Lesson. Lesson Overview. Math Background Lesso -A Equivalet Fractios ad Decimals Commo Core Lesso Overview Domai Number ad Operatios Fractios Cluster Uderstad decimal otatio for fractios, ad compare decimal fractios. Stadards.NF. Use decimal

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

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs CHAPTER IV: GRAPH THEORY Sectio : Itroductio to Graphs Sice this class is called Number-Theoretic ad Discrete Structures, it would be a crime to oly focus o umber theory regardless how woderful those topics

More information

implement language system

implement language system Outlie Priciples of programmig laguages Lecture 3 http://few.vu.l/~silvis/ppl/2007 Part I. Laguage systems Part II. Fuctioal programmig. First look at ML. Natalia Silvis-Cividjia e-mail: silvis@few.vu.l

More information

Descriptive Statistics Summary Lists

Descriptive Statistics Summary Lists Chapter 209 Descriptive Statistics Summary Lists Itroductio This procedure is used to summarize cotiuous data. Large volumes of such data may be easily summarized i statistical lists of meas, couts, stadard

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 18 Strategies for Query Processig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio DBMS techiques to process a query Scaer idetifies

More information

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method A ew Morphological 3D Shape Decompositio: Grayscale Iterframe Iterpolatio Method D.. Vizireau Politehica Uiversity Bucharest, Romaia ae@comm.pub.ro R. M. Udrea Politehica Uiversity Bucharest, Romaia mihea@comm.pub.ro

More information

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only Edited: Yeh-Liag Hsu (998--; recommeded: Yeh-Liag Hsu (--9; last updated: Yeh-Liag Hsu (9--7. Note: This is the course material for ME55 Geometric modelig ad computer graphics, Yua Ze Uiversity. art of

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

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

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

Computer Systems - HS

Computer Systems - HS What have we leared so far? Computer Systems High Level ENGG1203 2d Semester, 2017-18 Applicatios Sigals Systems & Cotrol Systems Computer & Embedded Systems Digital Logic Combiatioal Logic Sequetial Logic

More information

BaanERP Tools. Programming features

BaanERP Tools. Programming features BaaERP Tools A publicatio of: Baa Developmet B.V. P.O.Box 143 3770 AC Bareveld The Netherlads Prited i the Netherlads Baa Developmet B.V. 1998. All rights reserved. The iformatio i this documet is subject

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

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

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

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

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions

A Generalized Set Theoretic Approach for Time and Space Complexity Analysis of Algorithms and Functions Proceedigs of the 10th WSEAS Iteratioal Coferece o APPLIED MATHEMATICS, Dallas, Texas, USA, November 1-3, 2006 316 A Geeralized Set Theoretic Approach for Time ad Space Complexity Aalysis of Algorithms

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

Getting Started. Getting Started - 1

Getting Started. Getting Started - 1 Gettig Started Gettig Started - 1 Issue 1 Overview of Gettig Started Overview of Gettig Started This sectio explais the basic operatios of the AUDIX system. It describes how to: Log i ad log out of the

More information

Lecture 28: Data Link Layer

Lecture 28: Data Link Layer Automatic Repeat Request (ARQ) 2. Go ack N ARQ Although the Stop ad Wait ARQ is very simple, you ca easily show that it has very the low efficiecy. The low efficiecy comes from the fact that the trasmittig

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

Here are the coefficients of the terms listed above: 3,5,2,1,1 respectively.

Here are the coefficients of the terms listed above: 3,5,2,1,1 respectively. *. Operatios with Poloials: Let s start b defiig soe words. Ter: A ter is a uber, variable or the product of a uber ad variable(s). For eaple:,, z, a Coefficiet: A coefficiet is the ueric factor of the

More information

Big-O Analysis. Asymptotics

Big-O Analysis. Asymptotics Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses

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

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server:

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server: 3 Usig MySQL Programs This chapter provides a brief overview of the programs provided by MySQL AB ad discusses how to specify optios whe you ru these programs. Most programs have optios that are specific

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

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

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

MOTIF XF Extension Owner s Manual

MOTIF XF Extension Owner s Manual MOTIF XF Extesio Ower s Maual Table of Cotets About MOTIF XF Extesio...2 What Extesio ca do...2 Auto settig of Audio Driver... 2 Auto settigs of Remote Device... 2 Project templates with Iput/ Output Bus

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13 CIS Data Structures ad Algorithms with Java Sprig 08 Stacks ad Queues Moday, February / Tuesday, February Learig Goals Durig this lab, you will: Review stacks ad queues. Lear amortized ruig time aalysis

More information

NTH, GEOMETRIC, AND TELESCOPING TEST

NTH, GEOMETRIC, AND TELESCOPING TEST NTH, GEOMETRIC, AND TELESCOPING TEST Sectio 9. Calculus BC AP/Dual, Revised 08 viet.dag@humbleisd.et /4/08 0:0 PM 9.: th, Geometric, ad Telescopig Test SUMMARY OF TESTS FOR SERIES Lookig at the first few

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

Analysis of Algorithms

Analysis of Algorithms Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Aalysis of Algorithms Iput 2015 Goodrich ad Tamassia Algorithm Aalysis of Algorithms

More information

UNIVERSITY OF MORATUWA

UNIVERSITY OF MORATUWA UNIVERSITY OF MORATUWA FACULTY OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING B.Sc. Egieerig 2014 Itake Semester 2 Examiatio CS2052 COMPUTER ARCHITECTURE Time allowed: 2 Hours Jauary 2016

More information

EE260: Digital Design, Spring /16/18. n Example: m 0 (=x 1 x 2 ) is adjacent to m 1 (=x 1 x 2 ) and m 2 (=x 1 x 2 ) but NOT m 3 (=x 1 x 2 )

EE260: Digital Design, Spring /16/18. n Example: m 0 (=x 1 x 2 ) is adjacent to m 1 (=x 1 x 2 ) and m 2 (=x 1 x 2 ) but NOT m 3 (=x 1 x 2 ) EE26: Digital Desig, Sprig 28 3/6/8 EE 26: Itroductio to Digital Desig Combiatioal Datapath Yao Zheg Departmet of Electrical Egieerig Uiversity of Hawaiʻi at Māoa Combiatioal Logic Blocks Multiplexer Ecoders/Decoders

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