ENGR 490: Software Tools for Engineering Laboratory Lab 5: Flowchart and Pseudocode Demo due Friday, September 30 th, 2011 (by 4PM)

Similar documents
Lab 11. Simulations. The Concept

Ready, Set, Go! Math Games for Serious Minds

MA 1125 Lecture 14 - Expected Values. Friday, February 28, Objectives: Introduce expected values.

Lesson 4 What Is a Plant s Life Cycle? The Seasons of a Tree

After 3 races the player with the highest winnings has won that day s racing.

Dobbin Day - User Guide

Week 5: Expected value and Betting systems

Memory Management Simulation Interactive Lab

(Refer Slide Time: 2:03)

There are a number of superb online resources as well that provide excellent blackjack information as well. We recommend the following web sites:

Ch. 13.2: Mathematical Expectation

Analysis of Micromouse Maze Solving Algorithms

L OCUTOUR. Get Ready to Spell! MULTIMEDIA COGNITIVE REHABILITATION

Math Games For Skills and Concepts

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Automatic Bet Tracker!

How to Make the Most of Excel Spreadsheets

AP Computer Science Java Mr. Clausen Program 9A, 9B

4 Other useful features on the course web page. 5 Accessing SAS

1 Description of The Simpletron

Year 2 Summer Term Oral and Mental Starter Activity Bank

ECON 459 Game Theory. Lecture Notes Auctions. Luca Anderlini Spring 2015

Final Exam. Route Computation: One reason why link state routing is preferable to distance vector style routing.

Minimax Strategies. Minimax Strategies. Zero Sum Games. Why Zero Sum Games? An Example. An Example

Evaluating Trading Systems By John Ehlers and Ric Way

PaperStream Connect. Setup Guide. Version Copyright Fujitsu

5050 Getting Started

On-line Storage and Backup Services

In the situations that we will encounter, we may generally calculate the probability of an event

Module 6.3 Client Catcher The Sequence (Already Buying Leads)

Bar Graphs and Dot Plots

Copyrights PPC Bully (MyAdWise Ltd.) - Page 1 of 13

Lecture 2 Mathcad Basics

Lab Experience 17. Programming Language Translation

WARNING DO NOT UNDER ANY CIRCUMSTANCE RUN MORE THAN ONE VERSION OF THE GREY HORSE BOT ON THE SAME MARKET.

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 10

Data exploration with Microsoft Excel: univariate analysis

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Intro to Simulation (using Excel)

Thursday, November 13: 6.1 Discrete Random Variables

if and if-else: Part 1

Directions: Place greater than (>), less than (<) or equal to (=) symbols to complete the number sentences on the left.

Easy Casino Profits. Congratulations!!

7 6.2 Windows Vista / Windows IP Address Syntax Mobile Port Windows Vista / Windows Apply Rules To Your Device

Advanced Excel Charts : Tables : Pivots : Macros

Day 1. This is CS50 for MBAs. Harvard Busines School. Spring Cheng Gong

Page 18. Using Software To Make More Money With Surveys. Visit us on the web at:

HONORS STATISTICS. Mrs. Garrett Block 2 & 3

We { can see that if U = 2, 3, 7, 11, or 12 then the round is decided on the first cast, U = V, and W if U = 7, 11 X = L if U = 2, 3, 12.

Q&As: Microsoft Excel 2013: Chapter 2

LabVIEW Day 6: Saving Files and Making Sub vis

Figure 1: Graphical example of a mergesort 1.

DIVISION OF DECIMALS We then we multiply by the

Decision Theory Rational prospecting

School account creation guide

I n t e r a c t i n g G a l a x i e s - Making Ellipticals Te a c h e r N o t e s

Pseudo code Tutorial and Exercises Teacher s Version

Money Unit $$$$$$$$$$$$$$$$$$$$$$$$ First Grade

NF5-12 Flexibility with Equivalent Fractions and Pages

WORDS THEIR WAY. Thursday- FREE CHOICE: See the attached page with Free Choice options and assist your child in completing this activity.

SAT Math Facts & Formulas Review Quiz

Assessment of robust capacity utilisation in railway networks

THE WISDOM OF 14 ACCOUNTING TEXTBOOKS.

Computation and Economics - Spring 2012 Assignment #3: File Sharing

Fruit Machine. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

Dynamic Programming Problem Set Partial Solution CMPSC 465

Building Java Programs

CHM 579 Lab 1: Basic Monte Carlo Algorithm

Suite. How to Use GrandMaster Suite. Exporting with ODBC

National Championships Konami Digital Entertainment B.V. (KDE) Yu-Gi-Oh! TRADING CARD GAME 2016 WCQ National Championship FAQ.

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 6 8

Learn How to Create and Profit From Your Own Information Products!

The Taxman Game. Robert K. Moniot September 5, 2003

Crude: The Oil Game 1

CHAPTER 6: ANALYZE MICROSOFT DYNAMICS NAV 5.0 DATA IN MICROSOFT EXCEL

IBM SPSS Direct Marketing 23

The fairy tale Hansel and Gretel tells the story of a brother and sister who

MATHEMATICS Y3 Using and applying mathematics 3810 Solve mathematical puzzles and investigate. Equipment MathSphere

How to find (and change) facepanel pot priority settings

Module 4: Goal Setting and Planning

IBM SPSS Direct Marketing 22

CM HOST CM CardTransporter Fuel Communication and Management Software Software version up to 3.1

From The Little SAS Book, Fifth Edition. Full book available for purchase here.

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project

Logarithmic and Exponential Equations

WEEK #22: PDFs and CDFs, Measures of Center and Spread

FACT A computer CANNOT pick numbers completely at random!

- User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc.

EVENT REGISTRATION. Introduction. Feature Availability. Requirements. Table of Contents. Version 7/22/2012

Using Your TI-89 in Elementary Statistics

APP INVENTOR. Test Review

Your Personal Trading Journal

WHAT ELSE CAN YOUR HOME PHONE DO?

While Loops and Animations

Gaming the Law of Large Numbers

TEST 2 STUDY GUIDE. 1. Consider the data shown below.

TEACHER S GUIDE TO RUSH HOUR

PT AVENUE GUIDE OVERVIEW

Transcription:

1 ENGR 490: Software Tools for Engineering Laboratory Lab 5: Flowchart and Pseudocode Demo due Friday, September 30 th, 2011 (by 4PM) Objective We will discuss the software design using Flowchart and Pseudocode. In the assignment, students need to make the flowchart or pseudocode before writing the program. Part 0: Admin stuffs 1. Let s build the folder where you will save your project files. I suggest c:\projects\yourname\engr490\lab5. All files should be organized and put in dropbox. Part 1: Shuffle the array 1. If we want to make 1 random number, it will be very simple by calling rand() command. 2. How about if we want to make N random number that each number is not repeated. This application is suitable for making games, multiple choices. 3. There are many ways to do but Dr. Somsak will show you 2 methods using flowchart first. a. Create a new project called ExampleShuffleArray1 b. The first idea is to create an array with size N, and initialize with number from 0 to N-1 in order. c. Then we will pick 2 numbers from 0 to N-1 representing the indexes and swap the content inside that 2 locations. Repeat this process many times, eventually the content will be random and never repeat. See the flowchart.

4. If you agree that the flowchart is correct and covers everything that you need, we can start writing the code now. Run and you will see the results. At this point, I would recommend to include a bunch of header files since you don t remember which command is belong to which one. 5. Notice that way that I use #define instead of hard code number. Because we can change the size of array to anything easy by changing one place, instead of doing many times. 2 6. Run the program and see results. Try to remember the number for a few samples. Run again, see if it is random and never repeat. 7. You may be able to shorten the loop by doing just 1000 times, instead of 1 million. It should yield the fine result since it is too small array. 8. Try to make a random for array size 52. You can simple by changing the N in define.

Part 2: Shuffle the array part 2 1. The method in part 1 for shuffling array or generating nonrepeat numbers is simple. It has a disadvantage that we create the array size N ahead of time. If the N is big, 5000, it can use a lot of memory and time to shuffle. 2. Sometimes in application that we want to make a few array but the content is nonrepeat and big numbers. We should use different method. 3. The second method that we will use based on making one random number at the time. Each time that we make, we will check if it is already created, if yes we will repeat until it is never created. 4. As you can see, we know that we need to make N random number, use for-loop. 5. But we don t know how many times we need to check with the duplicated numbers. In this case, we will involve using while. 6. Following is the flowchart, see that is more complicate than the first one but it is faster to get the outputs. a. Variable i is for index of X, keep track the new random number b. Variable k is for index that checks duplicate with anything that X has so far. c. This method can do any range, does not need to be 0 to N-1, can be 1 million to 2 millions. 3

7. Make a new project, write this code. Run. You will see it makes 10 numbers from 100 to 1000. You can change any number in the define. 8. BUG: what happen if you define N is 10, and random max and min are 0 and 5 respectively. Try and run. Why nothing shows up? 9. In the future, feel free to use either one of this method to make shuffled array. 4

5 Part 3: Sorting Array 1. If you have the array size N and would like to sort from minimum to maximum (or max to min), there are several methods we can do such as bubble sort. 2. The idea of bubble sort is to compare 2 numbers at the time and switch them if it is not in order. The comparison will continue until there is nothing changed or swapped. 3. I recommend you to look at this link for visualization. http://en.wikipedia.org/wiki/bubble_sort 4. The pseudo code of this bubble sort can be written as 5. Copy part 2 code folder to a new one. Name the folder ExampleSort. 6. Add sorting once you have the random array, before printing out. Don t forget to declare variables for swapped and temp.

6 C code implementation //assume you have an unsorted array size N //use results from part 2 //see how I translate pseudocode to C code swapped = 1; while (swapped){ swapped = 0; for(i=0;i<n-1;i++){ if (X[i] > X[i+1]){ //swap 2 elements temp = X[i]; X[i] = X[i+1]; X[i+1] = temp; swapped = 1; } } } //show X 7. You should see that the outputs show array of random data that also sorted from min to max. 8. Question 1: can you simply modify a little, to sort from max to min. It should be easy. 9. Question 2: based on pseudo code and C code, can you write the flowchart? The solution is on the next page, don t look at it until you practice to write the flowchart. 10. If you want the program for drawing flowchart for report or website, Google Doc provides the flowchart program called drawing. You can login google account and find google doc. Create a new drawing file. Once finish, you export to a picture file.

7

8 ENGR 490: Software Tools for Engineering Lab Assignment 5: Flowchart and Pseudocode Source code and demo due by Friday, September 30 th, 2011 (by 4PM) 1. You should assign each person to take one question independently and discuss at the end. 2. For the hard question, you should work as a team, starting with design flowchart. Competition Rules and Award In this competition, Dr. Somsak will measure how effective and concise that you write the code. He will use the number of lines that you wrote on 2 problems, 1) salesman travel and 2) histrogram to measure. He will count the number of lines in the code, except { line, white space such as blank line. Then he will take log base 10 for the number of lines for each problem and sum. The team with lowest number is the winner. The award is 1 question off for the oral midterm. Each problem needs to start with flowchart before writing the code. Dr. Somsak will ask to see your flowchart each time you ask his help and demo time. Project 1: Roll roll the dice.. Crap Game (appleapple) Design a crap game. You will roll 2 dices. Use spacebar to simulate rolling the dice. You can do it by system( pause ); command. You will need to include stdlib.h. Use %c with the appropriate number to make sound. In this problem, you simply make 2 random numbers independently. I can repeat. Show the message of points, money. Start money with 200 dollars and you can bet each round that is less than the money that you have. If you bet more than the money that you have, the program should repeat ask you again. If you win, you get money back + same amount that you bet. You you lose, you will lose the bet. If the money reaches zero lose, if the point is over 999 win the game. Make the flowchart first.

9 Project 2: Histogram (appleappleapple) Competition problem Given that you have an array size 1000 containing salary of 1000 people. You can do this task with random data between 5000 and 25000. We want to find the histogram of data, basically the range of data and it will tell how many counts in there. The range is divided into 20 spacing equally, e.g. 5000-5999, 6000-6999 Count and assign each array elements into the histogram. The result should show o Bin 1: salary from??? to??? has xxxx persons o Bin 2: salary from??? to??? has yyyy persons Example: if I have 6 numbers 1 4 3 4 5 4. I want to break into 2 bins, it will be from bin#1 from 1 to 3 [1,3] and bin#2 from 3 to 6 (3,5]. The results will be Bin 1: from 1 to 3 has 2 populations. Bin 2: from 3 to 5 has 4 populations. Hint: if you are writing something that looks same same and tedious, try to make it shorter using C command such as for-loop. You need to find the pattern in it. Project 3: Statistics Part 2 (appleapple) Copy the code from previous lab to this week folder. We will modify the code to do more thing. 30 25 18 12 23 55 100 12 23 89 67 5 12 23 16 90 23 90 100 34 23 Print out on the screen to show the following statistics o Old stuffs: Min, Max.. Variance o Median (need to sort array first) o Mode (need to do histogram first, see project 2) Project 4: Salesman Travel (appleappleappleappleappleappleappleappleappleappleappleappleappleappleapple) 1. Competition problem 2. Imagine that you have the location of 10 cities on x-y plan. Each one has 2 numbers representing the location in x and y coordinates. To find the distance from one point to another point it will be d = ( x 1 x 2 ) 2 + ( y 1 y 2 ) 2.

10 3. The question is, if you start to travel from the city #0 and want to go to all cities and come back to city #0 again, what will be the good order in term of minimum total distance? To solve this, we can end up with so many possibilities and pick the one the have minimum distance. That will be about 10! = 3 million choices. 4. If the number of cities increase such as becomes 30, you will end up with trillion possibilities, take a year to get the answer. In this assignment, we will try to solve the minimum path for 10 cities. If you start at city#x and back at city#x again, e.g. city#5 and back to city#5 eventually. We will randomly generate sequence. o Start with random one sequence that start with 0, such as 0 5 3 1.. o Find the distance between cities and don t forget to add distance of the last one back to city#0 and use this one as the first result of distance and city. o Random the number again but it needs to start with 0 and the rest are 1 to 9 only never repeat. Find the distance + back to 0 of the last one, compare with the minimum that you have so far. o If it is lower, you will copy the data and print out sequence and result on screen. o Do it 3,000,000 random sequences, and the final answer will be somewhat minimum distance path that we try to search. o Print out the result of the minimum path including city sequences and total distance. o Use the following data. Use the graph to check if it makes sense to you. City 0 1 2 3 4 5 6 7 8 9 x 0.5-3 -2.5-3.2-0.1 1.9-0.3-0.2 2.4 1.5 y 3 0.2-0.4 2.5-2.7 1.2 3.2 2.4 0.8-1.5