11 aprile 2002 Avvisi: 1 o Esonero: mercoledi 17 aprile ore 11:30 – 14:00 consulta la pag. WEB alla voce esoneri si raccomanda la puntualita!

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

AP STUDY SESSION 2.
1
Feichter_DPG-SYKL03_Bild-01. Feichter_DPG-SYKL03_Bild-02.
Slide 1Fig. 20.1, p.607. Slide 2Table 20.1, p.608.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
UNITED NATIONS Shipment Details Report – January 2006.
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination. Introduction to the Business.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt BlendsDigraphsShort.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Break Time Remaining 10:00.
PP Test Review Sections 6-1 to 6-6
EU market situation for eggs and poultry Management Committee 20 October 2011.
Bright Futures Guidelines Priorities and Screening Tables
Bellwork Do the following problem on a ½ sheet of paper and turn in.
2 |SharePoint Saturday New York City
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
VOORBLAD.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
LO: Count up to 100 objects by grouping them and counting in 5s 10s and 2s. Mrs Criddle: Westfield Middle School.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Note to the teacher: Was 28. A. to B. you C. said D. on Note to the teacher: Make this slide correct answer be C and sound to be “said”. to said you on.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Subtraction: Adding UP
Januar MDMDFSSMDMDFSSS
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Clock will move after 1 minute
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Select a time to count down from the clock above
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
Presentation transcript:

11 aprile 2002 Avvisi: 1 o Esonero: mercoledi 17 aprile ore 11:30 – 14:00 consulta la pag. WEB alla voce esoneri si raccomanda la puntualita!

Calcolare la Media, la Mediana e la Moda usando array Media Mediana – numero a meta della lista ordinata. –1, 2, 3, 4, 5 3 e la mediana Moda - numero che occorre piu spesso –1, 1, 1, 2, 3, 3, 4, 5 1 e la moda

1/* Fig. 6.16: fig06_16.c 2 Analisi di un insieme di dati. Calcolo della media, 3 della mediana e della moda di un insieme di dati */ 4#include 5#define SIZE void mean( const int [] ); 8void median( int [] ); 9void mode( int [], const int [] ) ; 10void bubbleSort( int [] ); 11void printArray( const int [] ); 12 13int main() 14{ 15 int frequency[ 10 ] = { 0 }; 16 int response[ SIZE ] = 17 { 6, 7, 8, 9, 8, 7, 8, 9, 8, 9, 18 7, 8, 9, 5, 9, 8, 7, 8, 7, 8, 19 6, 7, 8, 9, 3, 9, 8, 7, 8, 7, 20 7, 8, 9, 8, 9, 8, 9, 7, 8, 9, 21 6, 7, 8, 7, 8, 7, 9, 8, 9, 2, 22 7, 8, 9, 8, 9, 8, 9, 7, 5, 3, 23 5, 6, 7, 2, 5, 3, 9, 4, 6, 4, 24 7, 8, 9, 6, 8, 7, 8, 9, 7, 8, 25 7, 4, 4, 2, 5, 3, 8, 7, 5, 6, 26 4, 5, 6, 1, 6, 5, 7, 8, 7 }; 27

28 mean( response ); 29 median( response ); 30 mode( frequency, response ); 31 return 0; 32} ******** Mean ******** The mean is the average value of the data items. The mean is equal to the total of all the data items divided by the number of data items (99). The mean value for this run is: 681 / 99 = Output Vediamo prima loutput, poi la funzione…

33 34void mean( const int answer[] ) 35{ 36 int j, total = 0; printf( "%s\n%s\n%s\n", "********", " Mean", "********" ); for ( j = 0; j <= SIZE - 1; j++ ) 41 total += answer[ j ]; printf( "The mean is the average value of the data\n" 44 "items. The mean is equal to the total of\n" 45 "all the data items divided by the number\n" 46 "of data items ( %d ). The mean value for\n" 47 "this run is: %d / %d = %.4f\n\n", 48 SIZE, total, SIZE, ( double ) total / SIZE ); 49} 50

Output ******** Median ******** The unsorted array of responses is The sorted array is The median is element 49 of the sorted 99 element array. For this run the median is 7 Vediamo prima loutput, poi la funzione…

51void median( int answer[] ) 52{ 53 printf( "\n%s\n%s\n%s\n%s", 54 "********", " Median", "********", 55 "The unsorted array of responses is" ); printArray( answer ); 58 bubbleSort( answer ); 59 printf( "\n\nThe sorted array is" ); 60 printArray( answer ); 61 printf( "\n\nThe median is element %d of\n" 62 "the sorted %d element array.\n" 63 "For this run the median is %d\n\n", 64 SIZE / 2, SIZE, answer[ SIZE / 2 ] ); 65}

******** Mode ******** Response Frequency Histogram * 2 3 *** 3 4 **** 4 5 ***** 5 8 ******** 6 9 ********* 7 23 *********************** 8 27 *************************** 9 19 ******************* The mode is the most frequent value. For this run the mode is 8 which occurred 27 times. Vediamo prima loutput, poi la funzione…

66 67void mode( int freq[], const int answer[] ) 68{ 69 int rating, j, h, largest = 0, modeValue = 0; printf( "\n%s\n%s\n%s\n", 72 "********", " Mode", "********" ); for ( rating = 1; rating <= 9; rating++ ) 75 freq[ rating ] = 0; for ( j = 0; j <= SIZE - 1; j++ ) 78 ++freq[ answer[ j ] ]; printf( "%s%11s%19s\n\n%54s\n%54s\n\n", 81 "Response", "Frequency", "Histogram", 82 " ", " " ); for ( rating = 1; rating <= 9; rating++ ) { 85 printf( "%8d%11d ", rating, freq[ rating ] ); if ( freq[ rating ] > largest ) { 88 largest = freq[ rating ]; 89 modeValue = rating; 90 } Nota che lindice in frequency[] e il valore di un elemento in response[] ( answer[] )

95 printf( "\n" ); 96 } printf( "The mode is the most frequent value.\n" 99 "For this run the mode is %d which occurred" 100 " %d times.\n", modeValue, largest ); 101} void bubbleSort( int a[] ) 104{ 105 int pass, j, hold; for ( pass = 1; pass <= SIZE - 1; pass++ ) for ( j = 0; j <= SIZE - 2; j++ ) if ( a[ j ] > a[ j + 1 ] ) { 112 hold = a[ j ]; 113 a[ j ] = a[ j + 1 ]; 114 a[ j + 1 ] = hold; 115 } 116} for ( h = 1; h <= freq[ rating ]; h++ ) 93 printf( "*" ); 94 Scrive * a seconda del valore di frequency[] Bubble sort: se due elementi non sono in ordine, li scambia

printf( "%2d", a[ j ] ); 128 } 129} void printArray( const int a[] ) 119{ 120 int j; for ( j = 0; j <= SIZE - 1; j++ ) { if ( j % 20 == 0 ) 125 printf( "\n" );

Output ******** Mean ******** The mean is the average value of the data items. The mean is equal to the total of all the data items divided by the number of data items (99). The mean value for this run is: 681 / 99 = ******** Median ******** The unsorted array of responses is The sorted array is The median is element 49 of the sorted 99 element array. For this run the median is 7

******** Mode ******** Response Frequency Histogram * 2 3 *** 3 4 **** 4 5 ***** 5 8 ******** 6 9 ********* 7 23 *********************** 8 27 *************************** 9 19 ******************* The mode is the most frequent value. For this run the mode is 8 which occurred 27 times.

Ricerca su array: ricerca lineare e ricerca binaria Ricerca di un valore chiave in un array Ricerca lineare –Semplice –Confronta ogni elemento dellarray con la chiave –Utile nel caso di array piccoli e completamente non ordinati.

1./* Fig6_18.c Ricerca lineare in un array */ 2.#include 3.#define SIZE int linearSearch(int [], int, int); 5.main() 6.{ 7. int a[SIZE], x, searchKey, element; 8. for (x = 0; x <= SIZE - 1; x++) /* create some data */ 9. a[x] = 2 * x; 10. printf("Enter integer search key:\n"); 11. scanf("%d", &searchKey); 12. element = linearSearch(a, searchKey, SIZE); 13. if (element != -1) 14. printf("Found value in element %d\n", element); 15. else 16. printf("Value not found\n"); 17. return 0; 18.}

19.int linearSearch(int array[], int key, int size) 20.{ 21. int n; 22. for (n = 0; n <= size - 1; ++n) 23. if (array[n] == key) 24. return n; 25. return -1; 26.} Enter integer search key: 87 Value not found Enter integer search key: 88 Found value in element 44 Output

Ricerca su array: ricerca lineare e ricerca binaria Ricerca binaria –Su array ordinati –Confronta lelemento di mezzo (med) con la chiave Se uguali, elemento trovato Se chiave < med, guarda la prima meta dell array Se chiave > med, guarda la seconda meta Ripete –Molto veloce; al piu log n passi, dove n> 2 e il numero di elementi dellarray. Per un array di 30 elementi bastano 5 confronti

1./* Fig6_19.c Ricerca binaria in un array */ 2.#include 3.#define SIZE 15 4.int binarySearch(int [], int, int, int); 5.void printHeader(void); 6.void printRow(int [], int, int, int); 7.main() 8.{ 9. int a[SIZE], i, key, result; 10. for (i = 0; i <= SIZE - 1; i++) 11. a[i] = 2 * i; 12. printf("Enter a number between 0 and 28: "); 13. scanf("%d", &key); 14. printHeader(); 15. result = binarySearch(a, key, 0, SIZE - 1); 16. if (result != -1) 17. printf("\n%d found in array element %d\n", key, result); 18. else 19. printf("\n%d not found\n", key); 20. return 0; 21.}

22.int binarySearch(int b[], int searchKey, int low, int high) 23.{ 24. int middle; 25. while (low <= high) { 26. middle = (low + high) / 2; 27. printRow(b, low, middle, high); 28. if (searchKey == b[middle]) 29. return middle; 30. else if (searchKey < b[middle]) 31. high = middle - 1; 32. else 33. low = middle + 1; 34. } 35. return -1; /* chiave non trovata */ 36.}

37./* Stampa lintestazione per loutput */ 38.void printHeader(void) 39.{ 40. int i; 41. printf("\nSubscripts:\n"); 42. for (i = 0; i <= SIZE - 1; i++) 43. printf("%3d ", i); 44. printf("\n"); 45. for (i = 1; i <= 4 * SIZE; i++) 46. printf("-"); 47. printf("\n"); 48.}

49./* Stampa una riga delloutput mostrando la parte corrente dellarray su ci si sta lavorando. */ 50.void printRow(int b[], int low, int mid, int high) 51.{ 52. int i; 53. for (i = 0; i <= SIZE - 1; i++) 54. if (i high) 55. printf(" "); 56. else if (i == mid) 57. printf("%3d*", b[i]); /* segna il valore di mezzo */ 58. else 59. printf("%3d ", b[i]); 60. printf("\n"); 61.}

Output Enter a number between 0 and 28: 2 Subscripts: * * * 4 2 found in array element 1 Enter a number between 0 and 28: 24 Subscripts: * * * 28 24* 24 found in array element 12