The Princeton Egg The Global Consciousness Project (video)The Global Consciousness Project (video) Princeton Egg Website Our Egg: PrincetonEgg.cppPrincetonEgg.cpp.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

Computer Science 1620 Math Library. Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to.
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Exercise 4 1. Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the.
Chapter 5 Functions.
True or false A variable of type char can hold the value 301. ( F )
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Announcements The first graded lab will be posted Sunday 2/15 and due Friday 2/27 at midnight It is brand new, so please don’t hand in last semester’s.
Functions. COMP104 Lecture 13 / Slide 2 Review of Array: Bubble Sort for (j=0; j List[j+1]) swap(List[j], List[j+1]); }
Computer Science 1620 Programming & Problem Solving.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Libraries Programs that other people write that help you. #include // enables C++ #include // enables human-readable text #include // enables math functions.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Random Number Generator. Using Software We can generate random number by: 1- table 2- hardware 3-- software Function to generate RN by SW is: 1-rand 2-
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
Chapter 3 Expressions and Interactivity Department of Computer Science Missouri State Univeristy.
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
CSE1222: Lecture 3The Ohio State University1. Assignment Operations  The C++ assignment operator is: =  Examples: x = 3 * 5; y = x – 7; y = y + 4; Do.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Today’s Lecture Predefined Functions. Introduction to Functions  Reuse Issue  Building Blocks of Programs  Two types of functions  Predefined  Programmer.
First steps Jordi Cortadella Department of Computer Science.
CSIS 113A Lecture 5 Random Numbers, while, do-while.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
CS221 Random Numbers. Random numbers are often very important in programming Suppose you are writing a program to play the game of roulette The numbers.
Lecture 7: Making Decisions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 6.
Introduction to Functions.  A complex problem is often easier to solve by dividing it into several smaller parts, each of which can be solved by itself.
Variables and memory addresses
CSci 162 Lecture 7 Martin van Bommel. Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
CSE202: Lecture 13The Ohio State University1 Function Scope.
Advanced loop controls. Loop Controls Recall from last week loop controls Event-controlled loops using sentinels repeats until a control variable takes.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 Generating Random Numbers Textbook ch.6, pg
MR. CRONE Generating Random Numbers. Random Numbers Many programs require the computer to generate random numbers Random numbers are used in many applications.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
CS 31 Discussion, Week 2 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:30-1:30pm (today)
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
Functions and Libraries. The idea of a function Functions in programming A function is a block of code that has been given a name. To invoke that code.
Introduction to Computer Programming
Monte Carlo Methods Some example applications in C++
Why they aren't really random
Computing and Statistical Data Analysis Lecture 2
EMT 101 – Engineering Programming
Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based on input values Some applications.
Iterative Constructs Review
CMPT 201 Functions.
Random Number Generation
Screen output // Definition and use of variables
הרצאה 03 אבני היסוד של תוכנית ב- C
Counting Loops.
Starting Out with C++: From Control Structures through Objects
Iterative Constructs Review
Dry run Fix Random Numbers
Wednesday 09/23/13.
Summary Two basic concepts: variables and assignments Basic types:
CS150 Introduction to Computer Science 1
Fundamental Programming
Introduction to Functions
Presentation transcript:

The Princeton Egg The Global Consciousness Project (video)The Global Consciousness Project (video) Princeton Egg Website Our Egg: PrincetonEgg.cppPrincetonEgg.cpp

a few things will help us design our own Princeton Egg a coin flipper

"for" loop boundaries // int x is the for loop variable counting // coin flips: int x = 0; for (x=1; x<=100; x=x+1) { cout << "X in for loop: " << x << endl; } cout << "X after for loop: " << x << endl;

Domain of a variable for (int x=1; x<=100; x=x+1) { cout << "X in for loop: " << x << endl; } cout << "X after for loop: " << x << endl; // error, x not useable outside for loop

#include rand( ); - "pseudo" random number randomNumber = rand( )%10; // generate random number 0 thru 9 srand( int seed ); - seed the random number

remember... calling a library function int ranNum; ranNum = rand( ) %2; // random one or zero The result of the library function is placed into ranNum. The rand()%2 function returns a random 0 or 1 as a “service”.

two problems with rand( ) 1. random numbers are the same every time you run it (the algorithm starts at a consistent place) 2. rand( )%2 gives equally spaced 0s and 1s (not random for these low numbers) on old computers (32 bit)

getting a coin flip int seed = 0; int randomNumber = 0; cout << "type a number to seed generator"; cin >> seed; srand( seed ); randomNumber = rand( )%2; // 0 or 1

#include time( 0 ); - returns the number of seconds since Jan I have no idea why. But, not an integer, some mutant "time" string… so: #include srand ( (int) time(0) ); // seed random number generator with time

actually, time(0) is a "structure" a structure, or "struct" in C++, is a meta-variable, that contains many variables… one main, and a number of auxiliary values the "time" struct contains the number of seconds (its main value), but also month, day, date and year which we can access when we get good at this

#include using namespace std; int main( ) {

Our Princeton Egg Elementary Statistics

Design 1. Flip some coins: a lot of them, in a for loop - use rand to generate numbers are heads, 5-9 are tails 2. Count the number of heads and the number of tails

Design 3. abs(heads - tails) / 2 is the number of errant coin flips e.g. For 10 flips, if you get 6 heads and 4 tails, / 2 = 1 coin flip was errant NOTE THAT THIS INVOLVES DIVIDING INTEGERS

we will use Casting ints and doubles ARE interchangeable but we have to cast int x; double y; x = 10; y = (double)x;

casting int numberOfFlips=0; int numberOfHeads=0; int numberOfTails=0; int diff = 0; // mistake double percentage = 0.0; diff = abs( numberOfHeads - numberOfTails )/2; // no division should EVER be done with integers

best: all divisions done with doubles double diff = 0.0; diff = (double) (abs( numberOfHeads - numberOfTails )) /2.0; 4. Calculate total % of errant flips percentage = (diff/(double)(numberOfFlips)) * 100.0;

Design 5. Finally, is percentage greater than 10%? - stay home