Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyChapter 5Functions for All Subtasks Slide 5- 3Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyOverview5.1 void Functions 5.2 Call-By-Reference Parameters5.3 Using Procedural Abstraction5.4 Testing and Debugging Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley5.1void Functions Slide 5- 5Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-FunctionsIn top-down design, a subtask might produceNo value (just input or output for example)One value More than one valueWe have seen how to implement functions thatreturn one valueA void-function implements a subtask that returns no value or more than one value Slide 5- 6Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.1void-Function DefinitionTwo main differences between void-function definitions and the definitions of functions that return one valueKeyword void replaces the type of the value returnedvoid means that no value is returned by the functionThe return statement does not include and expressionExample:void show_results(double f_degrees, double c_degrees) { using namespace std; cout << f_degrees << “ degrees Fahrenheit is euivalent to “ << endl << c_degrees << “ degrees Celsius.” << endl; return;} Slide 5- 7Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyUsing a void-Functionvoid-function calls are executable statementsThey do not need to be part of another statementThey end with a semi-colonExample: show_results(32.5, 0.3); NOT: cout << show_results(32.5, 0.3); Slide 5- 8Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-Function CallsMechanism is nearly the same as the function calls we have seenArgument values are substituted for the formal parameters It is fairly common to have no parameters in void-functionsIn this case there will be no arguments in the function callStatements in function body are executedOptional return statement ends the functionReturn statement does not include a value to returnReturn statement is implicit if it is not included Slide 5- 9Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.2 (1)Display 5.2 (2)Example: Converting TemperaturesThe functions just developed can be used in a program to convert Fahrenheit temperatures toCelcius using the formula C = (5/9) (F – 32)Do you see the integer division problem? Slide 5- 10Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.3void-FunctionsWhy Use a Return?Is a return-statement ever needed in avoid-function since no value is returned?Yes!What if a branch of an if-else statement requires that the function ends to avoid producing more output, or creating a mathematical error?void-function in Display 5.3, avoids division by zerowith a return statement [...]... a call-by-reference or call-by-value formal parameter is needed? Does the function need to change the value of the variable used as an argument? Yes? Use a call-by-reference formal parameter No? Use a call-by-value formal parameter Slide 5- 22 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Section 5.2 Conclusion Can you Write a void-function definition for. .. 5- 19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Mixed Parameter Lists Call-by-value and call-by-reference parameters can be mixed in the same function Example: void good_stuff(int& par1, int par2, double& par3); par1 and par3 are call-by-reference formal parameters Changes in par1 and par3 change the argument variable par2 is a call-by-value ENGLISH SERIES OF PRACTICE TESTS FOR STUDENTS & TEACHERS PRACTICE TEST 02 Choose the best option among A, B, C, or D provided to finish each of the following sentences eight musicians in the band A They will consist B They are being C There is D There will be We are very grateful your help A to B at C with D for He wear a pair of glasses A used to B used C use D use to Do you remember Mrs Goddard, taught us English composition? - I certainly A who B whom C that D which It was too small It wasn't A enough big B big enough C fairly big D rather big There is too much noise in this room I can't understand what A is the professor saying B is saying the professor C that is the professor saying D the professor is saying Don't forget home as soon as you arrive at your destination A to call B calling C having called D to be called They wanted to know if the woman had died of the rare A illness B pain C ache D hurt New York, Tokyo and Paris are all A big cities B capital cities C central cities D in Europe 10 I'll see you A short B after C next D later 11 Go and sit Richard A beside B next to C by D all are correct 12 This is the boy father is an architect A who B his C whose D which 13 I English for years now A am studying B will have studied C have been studied D have been studying 14 My uncle has given up A smoke B smoking C to smoke D smoked 15 Have you been Ho Chi Minh city? A Until you not B Already not C Still not D Not yet 16 I've got a new grammar book - A How many cost? B How much price? C How much is it? D How much you pay? 17 At four o'clock Mr Huchinson still had some to in his garden A work B job C effort D take 18 He has always been generous and he still A has been B was C is D has 19 Thank you for me A invite B invited C inviting D invitation 20 The lesson is difficult that nobody can understand it A so B such C very D a lot 21 That umbrella is A our B our's C ours D to our 22 What to the beggar? A did happen B was happened C happening D happened 23 Please smoke in the room A smoke B smokes C smoking D smoked 24 We've got food in the house A plenty of B plenty C lots D very much 25 Up to now I a lot of information about her A would learn B have learnt C have learn D will learn By Do Binh – Lien son High School, Lap thach, Vinh Phuc www.violet.vn/quocbinh72 Trang ENGLISH SERIES OF PRACTICE TESTS FOR STUDENTS & TEACHERS 26 Mrs Smith, husband is a diplomat, gives cooking lessons A whom B who C whose D who's 27 He was arrested He A escaped B was caught C was stopped D was seen 28 He heard a noise coming from the bar A which was B who was C that is D which is 29 I live a few yards the bus stop A off B away C from D with 30 We in this village 10 years ago A have lived B were living C used to live D lived 31 I have a lot of books, which I haven't read A many of B most of C some of D all are correct 32 I'm sorry I haven't got any money I've my wallet at home A missed B left C let D forgotten 33 If someone into the store, smile and say, "May I help you?" A comes B came C would come D could come 34 The children have gone A for shopping B to shop C shopping D to make shopping 35 Life on earth destroyed unless nuclear tests stop A would be B will C will be D is 36 The doctor succeeded the patient's life A when he saves B saving C to save D in saving 37 She eats too much and now she is A weighed B weight C overweigh D overweight 38 Lots of people yoga to relax A give up B take up C D make 39 The people thought he was a bit strange A which he worked with B with which he worked C with whom he worked D he worked with 40 A musician is a person music A who plays B whose C who play D which plays 41 Do you know a good to paint my house? A painting B paint C who D painter 42 Please don't touch anything the police arrive A when B if C unless D until 43 These apples are different the ones you bought yesterday A from B with C at D about 44 He spent a lot of time reading books A on B at C in D no word is needed 45 They treat women more equally than people in the North A very B too C so D much 46 Many Welsh people speak English as their language A home B first C family D mother 47 Even if you can't stop driving altogether, at least try to cut A off B down C up D out 48 The crowd at a football match are often A excite B excited C exciting D being excited 49 If there gravity, water wouldn't run downhill A aren't B isn't C wasn't D weren't 50 Your brother is very tall What is his exact ? A size B length C height D measure _THE END _ KEY Test 10 By Do Binh – Lien son High School, Lap thach, Vinh Phuc www.violet.vn/quocbinh72 Trang ENGLISH SERIES OF PRACTICE TESTS FOR STUDENTS & TEACHERS I- A D A A B D A A A 10 D 11 D 12 C 13 D 14 B 15 D 16 C 17 A 18 C 19 C 20 A 21 C 22 D 23 C 24 A 25 B 26 C 27 A 28 A 29 C 30 D 31 D 32 B 33 A 34 D ... Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyChapter 5Functions for All Subtasks Slide 5- 3Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyOverview5.1 void Functions 5.2 Call-By-Reference Parameters5.3 Using Procedural Abstraction5.4 Testing and Debugging Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley5.1void Functions Slide 5- 5Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-FunctionsIn top-down design, a subtask might produceNo value (just input or output for example)One value More than one valueWe have seen how to implement functions thatreturn one valueA void-function implements a subtask that returns no value or more than one value Slide 5- 6Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.1void-Function DefinitionTwo main differences between void-function definitions and the definitions of functions that return one valueKeyword void replaces the type of the value returnedvoid means that no value is returned by the functionThe return statement does not include and expressionExample:void show_results(double f_degrees, double c_degrees) { using namespace std; cout << f_degrees << “ degrees Fahrenheit is euivalent to “ << endl << c_degrees << “ degrees Celsius.” << endl; return;} Slide 5- 7Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyUsing a void-Functionvoid-function calls are executable statementsThey do not need to be part of another statementThey end with a semi-colonExample: show_results(32.5, 0.3); NOT: cout << show_results(32.5, 0.3); Slide 5- 8Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-Function CallsMechanism is nearly the same as the function calls we have seenArgument values are substituted for the formal parameters It is fairly common to have no parameters in void-functionsIn this case there will be no arguments in the function callStatements in function body are executedOptional return statement ends the functionReturn statement does not include a value to returnReturn statement is implicit if it is not included Slide 5- 9Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.2 (1)Display 5.2 (2)Example: Converting TemperaturesThe functions just developed can be used in a program to convert Fahrenheit temperatures toCelcius using the formula C = (5/9) (F – 32)Do you see the integer division problem? Slide 5- 10Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.3void-FunctionsWhy Use a Return?Is a return-statement ever needed in avoid-function since no value is returned?Yes!What if a branch of an if-else statement requires that the function ends to avoid producing more output, or creating a mathematical error?void-function in Display 5.3, avoids division by zerowith a return statement [...]... a call-by-reference or call-by-value formal parameter is needed? Does the function need to change the value of the variable used as an argument? Yes? Use a call-by-reference formal parameter No? Use a call-by-value formal parameter Slide 5- 22 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Section 5.2 Conclusion Can you Write a void-function definition for. .. 5- 19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Mixed Parameter Lists Call-by-value and call-by-reference parameters can be mixed in the same function Example: void good_stuff(int& par1, int par2, double& par3); par1 and par3 are call-by-reference formal parameters Changes in par1 and par3 change the argument variable par2 is a call-by-value ENGLISH SERIES OF PRACTICE Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyChapter 5Functions for All Subtasks Slide 5- 3Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyOverview5.1 void Functions 5.2 Call-By-Reference Parameters5.3 Using Procedural Abstraction5.4 Testing and Debugging Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley5.1void Functions Slide 5- 5Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-FunctionsIn top-down design, a subtask might produceNo value (just input or output for example)One value More than one valueWe have seen how to implement functions thatreturn one valueA void-function implements a subtask that returns no value or more than one value Slide 5- 6Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.1void-Function DefinitionTwo main differences between void-function definitions and the definitions of functions that return one valueKeyword void replaces the type of the value returnedvoid means that no value is returned by the functionThe return statement does not include and expressionExample:void show_results(double f_degrees, double c_degrees) { using namespace std; cout << f_degrees << “ degrees Fahrenheit is euivalent to “ << endl << c_degrees << “ degrees Celsius.” << endl; return;} Slide 5- 7Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyUsing a void-Functionvoid-function calls are executable statementsThey do not need to be part of another statementThey end with a semi-colonExample: show_results(32.5, 0.3); NOT: cout << show_results(32.5, 0.3); Slide 5- 8Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-Function CallsMechanism is nearly the same as the function calls we have seenArgument values are substituted for the formal parameters It is fairly common to have no parameters in void-functionsIn this case there will be no arguments in the function callStatements in function body are executedOptional return statement ends the functionReturn statement does not include a value to returnReturn statement is implicit if it is not included Slide 5- 9Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.2 (1)Display 5.2 (2)Example: Converting TemperaturesThe functions just developed can be used in a program to convert Fahrenheit temperatures toCelcius using the formula C = (5/9) (F – 32)Do you see the integer division problem? Slide 5- 10Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.3void-FunctionsWhy Use a Return?Is a return-statement ever needed in avoid-function since no value is returned?Yes!What if a branch of an if-else statement requires that the function ends to avoid producing more output, or creating a mathematical error?void-function in Display 5.3, avoids division by zerowith a return statement [...]... a call-by-reference or call-by-value formal parameter is needed? Does the function need to change the value of the variable used as an argument? Yes? Use a call-by-reference formal parameter No? Use a call-by-value formal parameter Slide 5- 22 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Section 5.2 Conclusion Can you Write a void-function definition for. .. 5- 19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Mixed Parameter Lists Call-by-value and call-by-reference parameters can be mixed in the same function Example: void good_stuff(int& par1, int par2, double& par3); par1 and par3 are call-by-reference formal parameters Changes in par1 and par3 change the argument variable par2 is a call-by-value SERIES OF PRACTICE TESTS Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyChapter 5Functions for All Subtasks Slide 5- 3Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyOverview5.1 void Functions 5.2 Call-By-Reference Parameters5.3 Using Procedural Abstraction5.4 Testing and Debugging Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley5.1void Functions Slide 5- 5Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-FunctionsIn top-down design, a subtask might produceNo value (just input or output for example)One value More than one valueWe have seen how to implement functions thatreturn one valueA void-function implements a subtask that returns no value or more than one value Slide 5- 6Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.1void-Function DefinitionTwo main differences between void-function definitions and the definitions of functions that return one valueKeyword void replaces the type of the value returnedvoid means that no value is returned by the functionThe return statement does not include and expressionExample:void show_results(double f_degrees, double c_degrees) { using namespace std; cout << f_degrees << “ degrees Fahrenheit is euivalent to “ << endl << c_degrees << “ degrees Celsius.” << endl; return;} Slide 5- 7Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyUsing a void-Functionvoid-function calls are executable statementsThey do not need to be part of another statementThey end with a semi-colonExample: show_results(32.5, 0.3); NOT: cout << show_results(32.5, 0.3); Slide 5- 8Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesleyvoid-Function CallsMechanism is nearly the same as the function calls we have seenArgument values are substituted for the formal parameters It is fairly common to have no parameters in void-functionsIn this case there will be no arguments in the function callStatements in function body are executedOptional return statement ends the functionReturn statement does not include a value to returnReturn statement is implicit if it is not included Slide 5- 9Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.2 (1)Display 5.2 (2)Example: Converting TemperaturesThe functions just developed can be used in a program to convert Fahrenheit temperatures toCelcius using the formula C = (5/9) (F – 32)Do you see the integer division problem? Slide 5- 10Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyDisplay 5.3void-FunctionsWhy Use a Return?Is a return-statement ever needed in avoid-function since no value is returned?Yes!What if a branch of an if-else statement requires that the function ends to avoid producing more output, or creating a mathematical error?void-function in Display 5.3, avoids division by zerowith a return statement [...]... a call-by-reference or call-by-value formal parameter is needed? Does the function need to change the value of the variable used as an argument? Yes? Use a call-by-reference formal parameter No? Use a call-by-value formal parameter Slide 5- 22 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Section 5.2 Conclusion Can you Write a void-function definition for. .. 5- 19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Mixed Parameter Lists Call-by-value and call-by-reference parameters can be mixed in the same function Example: void good_stuff(int& par1, int par2, double& par3); par1 and par3 are call-by-reference formal parameters Changes in par1 and par3 change the argument variable par2 is a call-by-value ENGLISH SERIES OF PRACTICE ... some of D all are correct 32 I'm sorry I haven't got any money I've my wallet at home A missed B left C let D forgotten 33 If someone into the store, smile and say, "May I help you? " A...ENGLISH SERIES OF PRACTICE TESTS FOR STUDENTS & TEACHERS 26 Mrs Smith, husband is a diplomat, gives cooking lessons A whom B who C... different the ones you bought yesterday A from B with C at D about 44 He spent a lot of time reading books A on B at C in D no word is needed 45 They treat women more equally than people