Basic Programming II. Outline Standard Deviation Function (SD) Complex Guessing Game.

Slides:



Advertisements
Similar presentations
Prepared 7/28/2011 by T. O’Neil for 3460:677, Fall 2011, The University of Akron.
Advertisements

MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
PSEUDOCODE & FLOW CHART
1 Array Knowledge Understand the execute technique of array Skill Can write application program using one and two dimensional array.
Measures of Spread The Range, Variance, and Standard Deviation.
Variability Measures of spread of scores range: highest - lowest standard deviation: average difference from mean variance: average squared difference.
Computer Science 1620 Programming & Problem Solving.
Chapter 4 Control Structure: Loop Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Selection in C.
Objectives The student will be able to: find the variance of a data set. find the standard deviation of a data set. SOL: A
Standard Deviation. Two classes took a recent quiz. There were 10 students in each class, and each class had an average score of 81.5.
An Introduction to Textual Programming
Measures of Dispersion Week 3. What is dispersion? Dispersion is how the data is spread out, or dispersed from the mean. The smaller the dispersion values,
C programming: Variables, Expressions part II. Data Types of Arithmetic Expressions Relational Expressions Logical Expressions Multiple Assignments Compound.
Standard Deviation!. Let’s say we randomly select 9 men and 9 women and ask their GPAs and get these data: MENWOMEN
Statistics: For what, for who? Basics: Mean, Median, Mode.
A First Book of ANSI C Fourth Edition
UNIT - 1Topic - 3. Computer software is a program that tells a computer what to do. Computer software, or just software, is any set of machine-readable.
Which Language is Better?
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
CS102 Introduction to Computer Programming Chapter 4 Making Decisions.
Writing Program Code in BASIC Write a program to prompt for and accept values into TWO variables, numx and numy. The program should square the value stored.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
1 C Programming Week 2 Variables, flow control and the Debugger.
6.3 THE CENTRAL LIMIT THEOREM. DISTRIBUTION OF SAMPLE MEANS  A sampling distribution of sample means is a distribution using the means computed from.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 9 Functions (continued)
Lecture 05 Functions II, Storage Class, Scope, rand() METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet.
Three Broad Purposes of Quantitative Research 1. Description 2. Theory Testing 3. Theory Generation.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Example # 1 Draw a flowchart for calculating the area of a room:
CSC 270 – Survey of Programming Languages Loops in C Modified from Dr. Robert Siegfried’s Presentation.
Objectives The student will be able to:
1.4 Defining Data Spread An average alone doesn’t always describe a set of data effectively or completely. An average doesn’t indicate whether the data.
Standard Deviation A Measure of Variation in a set of Data.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Functions. What is a function? It’s a group of statements that has a specific purpose and can be be repeatedly executed as needed. By using functions:
Standard Deviation. Two classes took a recent quiz. There were 10 students in each class, and each class had an average score of 81.5.
UNIT 11 Random Numbers.
Principle Prog Revision. Question 1 (a) Identify errors in the following program segment and how the errors can be corrected. void main(){ constant int.
Computer Programming for Engineers
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Engineering Problem#1 Engr201 Computer Programming for Engineers Faculty of Engineering Chiang Mai University 1.
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
Introduction to Programming Using C Basic Logic. 2 Contents Conditional programming If statement Relational operators Compound statements Loops While.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Normal Distribution Students will be able to: find the variance of a data set. find the standard deviation of a data set. use normal distribution curve.
Objectives The student will be able to:
CMPT 201 Functions.
9P9: Solve 2X2 systems by substitution
CS1010 Programming Methodology
Functions.
Standard Deviation Calculate the mean Given a Data Set 12, 8, 7, 14, 4
Objectives The student will be able to:
Learning Targets I can: find the variance of a data set.
Objectives The student will be able to: find the standard deviation of a data set.
Objectives The student will be able to:
Standard Deviation!.
Objectives The student will be able to:
The while Looping Structure
The while Looping Structure
Standard Deviation Mean - the average of a set of data
Calculating Standard Deviation
The Mean Variance Standard Deviation and Z-Scores
Presentation transcript:

Basic Programming II

Outline Standard Deviation Function (SD) Complex Guessing Game

Standard Deviation (SD) For the group of data, the standard deviation measures the spread of the data. Given a set of data the standard deviation (SD) is calculated as

Standard Deviation (SD) the procedure to compute the SD 1. Obtain the data, 2. Compute the average, 2. Compute the sum, 3. Compute the SD,

Standard Deviation (SD): Accepting Data Task1: Obtain the set of data Store 10 scores from the user in variable a[0], a[1],...,a[9] #include void main() { int a[10],n; for ( n=0 ; n<10 ; n++ ) { printf("Enter your data:"); scanf("%d", &a[n]); }

Task 2 Compute the average, Question 1. What happens when we do not define csum=0 ? Standard Deviation (SD) #include void main() { int a[10], n; float csum = 0, avg; for ( n=0 ; n<10 ; n++ ) { printf("Enter your data:"); scanf("%d", &a[n]); csum = csum + a[n]; } avg=csum/10.; }

Task 3. Compute the sum of the square of the difference between the data and the average. This can be done using pow function pow((a[0]-avg),2) Standard Deviation (SD)

Task3. Continued Store the sum in the variable, sq_sum... #include... float sq_sum=0;... for ( n=0 ; n<10 ; n++ ) { sq_sum = sq_sum + pow((a[n]-avg),2); }

Standard Deviation (SD) Task 4: Divide it by 10 and the take the square root to complete the SD.... #include... float sq_sum = 0, sd;... for ( n=0 ; n<10 ; n++ ) { sq_sum = sq_sum + pow((a[n]-avg),2); } sd=sqrt(sq_sum/10);

Standard Deviation (SD) SD #include void main() { float csum=0, avg, sq_sum=0, sd; int a[10], n; //get data and compute avg for ( n=0 ; n<10 ; n++ ) { printf("Enter your data:"); scanf("%d", &a[n]); csum = csum + a[n]; } avg=csum/10; //compute SD for ( n=0 ; n<10 ; n++ ) { sq_sum = sq_sum + pow((a[n]-avg),2); } sd=sqrt(sq_sum/10); printf(“SD = %.2f\n”, sd); }

Grade Assigning using SD Once the SD has been computed, it can be used to assign the grade for each of the score.

Guessing Game (Again) Previously on the Guessing game. #include void main() { int n, g, i = 1; srand(time(NULL)); n = rand() % 11; // generate a random number 0-10 do { printf("Guess a number[0,10]:"); scanf("%d", &g); i++; } while ((g!=n)&&(i<=5)); if (g == n) printf(“You got it.\n”); else printf("You failed. Please try again.\n"); }

Guessing Game (Again) Improve the guessing game so that it tells if the right answer is greater than the guess or less than the guess. Guess a number[0,10]:2 Greater than this. Guess a number[0,10]:6 Less than this. Guess a number[0,10]:5 You got it.

The random number (answer) is stored in variable n n The guess is stored in variable g g Guessing Game (Again)

Flowchart showing the relationship between the guess and the number. {g==n You got it, g>n less than this, g < n greater than this} g==ng>n display ‘Less than this.’display ‘Greater than this.’ display ‘You got it.’ NN YY

Guessing Game (Again) According to the flowchart, the translation into code is if (g==n) { printf("You got it.\n"); } else if (g>n) { printf("Less than this.\n"); } else { printf("Greater than this.\n"); }

#include void main() { int n, g, i = 1; srand(time(NULL)); n = rand() % 11; // generate a random number 0-10 do { printf("Guess a number[0,10]:"); scanf("%d", &g); if (g==n) { printf("You got it.\n"); } else if (g>n) { printf("Less than this.\n"); } else { printf("Greater than this.\n"); } i++; } while ((g!=n)&&(i<=5)); if (g != n) printf("You failed. Please try again.\n"); }

Summary Using flowchart can help us on planning the program; When you cannot see the solution right away, break the problem into smaller pieces and solve one at a time.