1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.

Slides:



Advertisements
Similar presentations
Introduction to arrays
Advertisements

What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
1 Various Methods of Populating Arrays Randomly generated integers.
1 Project 6: Tic Tac Toe. 2 Tic Tac Toe A Challange Project 10 Points extra credit on final grade OK to work in groups of 2 or 3.
Zhang Hongyi CSCI2100B Data Structures Tutorial 2
1 Lab Session-VI CSIT-120 Spring 2001 Let us look at C++ syntax rules in brief Exercise VI-A (Demo Required) Lab Assignment#4 Due May 1st, 2001 (No Lab.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
CS 106 Introduction to Computer Science I 02 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Searching and Sorting Arrays
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special character.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
12-2 Know how if and switch C statements control the sequence of execution of statements. Be able to use relational and logical operators in the conditional.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
1 Project 6: Cats in Tree. 2 Project 3: Cats in Tree In this project you will Create a class definition for a Cat class. Populate a BST with Cat information.
1 Project 7: Huffman Code. 2 Extend the most recent version of the Huffman Code program to include decode information in the binary output file and use.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 10 Scott Marino.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
1 Project 4: Vehicle Inventory. 2 Write a program to read a text file containing information about vehicles and output the information First in the order.
Chapter 8 Searching and Sorting Arrays Csc 125 Introduction to C++ Fall 2005.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
1 Project 5: New Venue. 2 New Venue Based on the posted New Venue scenario 077_Ticket_Booth_Scenarios.pdf.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
11 Project 2 Towers of Hanoi. 22 Towers of Hanoi is a well known puzzle that can be very difficult to solve manually but can be programmed very easily.
1 Flight Times. 2 Problem Specification 3 Additional Specifications You may assume that the input is a valid 24 hour time. Output the time entered by.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
1 Project 5: Printing Address Labels. 2 Assignment Write a Windows forms program to display and print a set of address labels. Input from a csv file.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Homework #2: Functions and Arrays By J. H. Wang Mar. 20, 2012.
1 Project 3 The Kumquat Society Conference. 2 Conference Registration In this project you will write a program to handle a conference registration. The.
Exercise 1 Introduction to C# CIS Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing.
Project 3: Ticket Printer
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
1 Project 1: Tickets. 2 Class Ticket Write a definition for class Ticket. A Ticket object corresponds to a physical ticket for a stage show. Attributes.
1 Project 2: Sorting Cats. Write a C++ console application to read a text file containing information about cats and output the information to the screen.
1 Project 3: Farey Sequences. 2 Farey Sequences Further details about Farey sequences, and more examples, can be found in the Wikipedia article:
Data Structures Arrays and Lists Part 2 More List Operations.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
11 Project 2 Temperature Conversion. 22 Project 2: Temperature Conversion Write an ASP.NET Web Forms app to convert temperatures from Fahrenheit to Celsius.
CS 116 Object Oriented Programming II Lecture 4 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
1 Project 4: Palindrome Detector. 2 Assignment Write a C++ program that reads a line of text from the keyboard and reports to the user whether the text.
1 Project 4: Venue Sort. 2 This project is an exercise in Using C++ strings. Operator overloading. Text File Input.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
1 Project 12: Cars from File. This is an extension of Project 11, Car Class You may use the posted solution for Project 11 as a starting point for this.
C++ Memory Management – Homework Exercises
Chapter 7 Part 1 Edited by JJ Shepherd
Pointers.
Conditions and Ifs BIS1523 – Lecture 8.
25 Searching and Sorting Many slides modified by Prof. L. Lilien (even many without an explicit message indicating an update). Slides added or modified.
24 Searching and Sorting.
Presentation transcript:

1 Project 5: Median

2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or equal. If the numbers are arranged in order, and there is an odd number of values, the median is the middle value. Example: 1, 2, 3, 4, 5, 6, 7 If there is an even number of values, there are two “middle” values. Use the first of these. Example: 1, 2, 3, 4, 5, 6

3 Project 5: Median Write a program that accepts up to 10 integers from the user and finds the median value. Values can be either positive or negative. Values must be greater than INT_MIN. User can enter a letter to indicate no more values. OK to terminate input when any non-digit is entered. Output an error message if no numbers are entered. Think about what can go wrong.

4 Implementation Specifications Provide an array in main to hold the numbers. Write a function to get keyboard input and put the values into the array. Call from main. Write a function that takes the array, and number of values, as parameters and returns the median value. This function will sort the numbers, determine the median, and return the median to the caller. Call from main. int median (int numbers[], int length)

5 Implementation Specifications Write a function to sort the array. void sort(int numbers[], int length) Call from median Use any sorting algorithm you like Example on next slide. Let the sort function call a function to swap values. The swap function will take two pointers to integer as arguments and exchange the values to which they point. void swap (int* n1, int* n2) Call from sort

6 Sorting Algorithm You may use this inefficient, but very simple, sorting algorithm if you wish: Simple Exchange Sort Given an array of numbers, Compare each entry after the first to the preceding entry. If the preceding entry is larger, exchange them. Repeat the above until no exchange is done.

7 Sample Run 212 Sun Server:~/test: gcc -Wall median.c 213 Sun Server:~/test: a.out This program determines the median of a list of numbers All numbers must be greater than Please enter up to 10 integers Enter any letter to terminate input before 10 entries 1: : : -21 4: : 199 6: x The median value is Sun Server:~/test:

8 Sample Run 214 Sun Server:~/test: a.out This program determines the median of a list of numbers All numbers must be greater than Please enter up to 10 integers Enter any letter to terminate input before 10 entries 1: 10 2: 9 3: 8 4: 7 5: 6 6: 5 7: 4 8: 3 9: 2 10: 1 The median value is Sun Server:~/test:

9 Sample Run 215 Sun Server:~/test: 215 Sun Server:~/test: a.out This program determines the median of a list of numbers All numbers must be greater than Please enter up to 10 integers Enter any letter to terminate input before 10 entries 1: abc No numbers were entered 216 Sun Server:~/test:

10 Sample Run 216 Sun Server:~/test: 216 Sun Server:~/test: a.out This program determines the median of a list of numbers All numbers must be greater than Please enter up to 10 integers Enter any letter to terminate input before 10 entries 1: : The median value is Sun Server:~/test:

11 Implementation Specifications This is an exercise in using functions and passing arrays and pointers as arguments to functions. To get full credit, your program must Include a function to fill the array with keyboard input. Include a function to find the median of an array of intergers. Include a function to sort an array of integers. Include a function to exchange two integers.

12 Submission Submit just your source file. No test plan. No executable file. Project is due by midnight, Sunday night, March 5 No late submissions will be accepted. Turn in your your source code through Blackboard Assignments for this class. Not Digital Dropbox Not

13 The Usual Ground Rules Apply This is an individual project. It is OK to discuss the project. BUT: Don’t let anyone see or copy your work. Don’t look at or copy anyone else’s work. Be sure your source file is read & write protected. Files will be checked for plagarism. End of Presentation