Session 8.2. Finding Winners Using Arrays

Size: px
Start display at page:

Download "Session 8.2. Finding Winners Using Arrays"

Transcription

1 1 Session 8.2 Finding Winners Using Arrays

2 Chapter 8.2: Finding Winners Using Arrays 2 Session Overview Find out how the C# language makes it easy to create an array that contains multiple values of a particular type Learn how to work with individual values stored as part of an array Use arrays to make a program that automatically displays the winning score from the Reaction Timer game Use an array as a look-up table to identify the winning players of the Reaction Timer game

3 Chapter 8.2: Finding Winners Using Arrays 3 Reaction Timer Winner Display At the moment the players have to decide who won a Reaction Timer game They have to find the lowest button time and then work out which player had that time It would be nice if the game program could do this

4 Chapter 8.2: Finding Winners Using Arrays 4 Finding the Winning Score A winning score is one which is greater than 0, and less than any other score This means that the player pressed their button before anyone else We can create a condition that will test if a particular score is the winning one The program just has to compare the value with all the ones that it needs to beat

5 Chapter 8.2: Finding Winners Using Arrays 5 Finding the Winning Score if ( ascore1 > 0 ) if ( ascore1 < bscore1 && ascore1 < xscore1 && ascore1 < yscore1 ) // if we get here button A of Gamepad 1 has won This code tests to see if button A has beaten all the other buttons on gamepad 1 To make the test for all the gamepads would require another 12 tests

6 Chapter 8.2: Finding Winners Using Arrays 6 The C# Array To solve this problem we need another way of accessing data We need a way that a program can work through a list of score values and find the smallest one that is the winner In computer language terms we need to use an array We know that computers can work with very large amounts of data, now we are going to find out how

7 Chapter 8.2: Finding Winners Using Arrays 7 Creating a One Dimensional Array int[] scores = new int[4]; An array is declared like any other variable The [] characters (square brackets) are very important The above array is called scores and it has been created with a capacity of 4 values The array is of type int, i.e. it can hold 4 integers We can create arrays of any type we like

8 Chapter 8.2: Finding Winners Using Arrays 8 Visualizing the Array You can visualize an array as a row of numbered boxes In the case of the scores array there are four such boxes, each of which can hold a single integer The first box in the row has the number 0, the last box has the number 3

9 Chapter 8.2: Finding Winners Using Arrays 9 Arrays and Elements Each box in the array is called an element When an integer array is created all the elements are initialized to the value 0 A C# program can read and write the values in the elements in an array

10 Chapter 8.2: Finding Winners Using Arrays 10 Using a Subscript to Access an Element scores[1] = 99; A program can access a particular element by using a subscript value The subscript is given in square brackets, as shown above

11 Chapter 8.2: Finding Winners Using Arrays 11 Falling Off the End of the Array scores[4] = 99; An attempt to access an array element that does not exist will cause the program to fail with an exception

12 Chapter 8.2: Finding Winners Using Arrays 12 Storing Reactions Scores in an Array if (oldpad1.buttons.a == ButtonState.Released && pad1.buttons.a == ButtonState.Pressed && scores[0] == 0) scores[0] = timer; This code replaces the variable ascore1 with the element at the start of the scores array We can do this for all the other score values in the game, so that the time values are all held in the scores array

13 Chapter 8.2: Finding Winners Using Arrays 13 Storing the Scores in an Array After a game has been played we might have a set of results as shown above We now need to create some C# code that will find the winning score We need to find the smallest score value which is greater than zero

14 Chapter 8.2: Finding Winners Using Arrays 14 An Algorithm to Find the Winning Score Look at each element in the array in turn. If the element contains a better value than the one you presently have, that is now the new best value This is what you actually did when you worked out the answer If you had to do this for 10,000 score values you would write down the best value you had seen so far, so that you didn t forget it and have to start again

15 Chapter 8.2: Finding Winners Using Arrays 15 Using a For Loop to Find the winner int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; This loop will find the winning score value It will work for any sized array

16 Chapter 8.2: Finding Winners Using Arrays 16 Creating Our Highest So Far Winning Value int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; Create a variable to hold the winning score Set it to a very large value which is not a winner

17 Chapter 8.2: Finding Winners Using Arrays 17 Declaring and Setting Up Our Loop Counter int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; C# lets you declare and initialize a variable to be used as a loop counter in a single statement

18 Chapter 8.2: Finding Winners Using Arrays 18 Checking the End Condition of the Loop int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; If we try to use the subscript 4 the program will throw an exception, so the loop must stop when i reaches 4

19 Chapter 8.2: Finding Winners Using Arrays 19 Moving on to the Next Element int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; Once we have tested one element we need to move on to the next one in the array

20 Chapter 8.2: Finding Winners Using Arrays 20 Test for a Valid Score int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; Only score values greater than 0 are valid Less than 0 means the button was pressed early

21 Chapter 8.2: Finding Winners Using Arrays 21 Test for a Winning Score int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; If this score value is less than the present winner then we have a new winning value

22 Chapter 8.2: Finding Winners Using Arrays 22 Updating the Winning Score int winningvalue = 120; for (int i = 0; i < 4; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; If we have a new winner, store it in the winningvalue variable

23 Chapter 8.2: Finding Winners Using Arrays 23 Identifying the Winning Player At the moment the program just works out the winning score It does not say which button achieved that score The program must display the winner as well This means that it must remember the position in the array of the winning score value We can then use this position to identify the winning player

24 Chapter 8.2: Finding Winners Using Arrays 24 Storing the Winner Subscript int winningvalue = 120; int winnersubscript = 0; for (int i = 0; i < 16; i++) if (scores[i] > 0) if (scores[i] < winningvalue) winningvalue = scores[i]; winnersubscript = i; The value of i for a high score is stored in winnersubscript

25 Chapter 8.2: Finding Winners Using Arrays 25 Identifying the Winner Using a Look-Up Table We now have code that will find out the position in the scores array of the winning score We can create a second array which lets the program look up the name of button that generated this score The names array is an array of strings Each element holds the name of a button

26 Chapter 8.2: Finding Winners Using Arrays 26 Declaring a Look-Up Table string[] names = new string[] "Gamepad 1 A", "Gamepad 1 B", "Gamepad 1 X", "Gamepad 1 Y" ; The names array is an array of strings which are pre-set with the button names The C# compiler can work out how many elements are being created, so there is no need to set the size of the names array The text lines up with the elements in scores

27 Chapter 8.2: Finding Winners Using Arrays 27 Displaying the Winner if (winningvalue!= 120) winnername = names[winnersubscript]; else winnername = "**NO WINNER**"; This code sets a string variable in the game world called winnername to the name of the winner If there are no winners (nobody pressed their button) the string is set to No Winner The string is displayed by the Draw method

28 Chapter 8.2: Finding Winners Using Arrays 28 Timing the Game play if (timer == 120) // find the winning score // set the variable winnername to the winner The game will display the winner two seconds after the sound effect was played Code in the Update method can test for the timer value reaching 120 and trigger the code that finds the winning score and sets it for display

29 Chapter 8.2: Finding Winners Using Arrays Reaction Timer with Winner This version of the reaction timer game uses the algorithm described above The name of the winner is displayed

30 Chapter 8.2: Finding Winners Using Arrays 30 Summary A C# array allows a programmer to create a single variable that holds a large number of items of a particular type Each item in an array is called an element, and particular elements are identified by means of a subscript value In an array of size n, the subscript values range from 0 to n-1 Attempts to use an invalid subscript value will cause a program to throw an exception

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9 D - Tic Tac Toe Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9 INTRODUCTION Let's use our 9 sparkles to build a tic tac toe game! Step 1 Assemble the Robot

More information

V2 3/5/2012. Programming in C. Introduction to Arrays. 111 Ch 07 A 1. Introduction to Arrays

V2 3/5/2012. Programming in C. Introduction to Arrays. 111 Ch 07 A 1. Introduction to Arrays Programming in C 1 Introduction to Arrays A collection of variable data Same name Same type Contiguous block of memory Can manipulate or use Individual variables or List as one entity 2 Celsius temperatures:

More information

Introduction to Computer Science Midterm 3 Fall, Points

Introduction to Computer Science Midterm 3 Fall, Points Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do

More information

Chapter 9 Introduction to Arrays. Fundamentals of Java

Chapter 9 Introduction to Arrays. Fundamentals of Java Chapter 9 Introduction to Arrays Objectives Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced

More information

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof. GridLang: Grid Based Game Development Language Language Reference Manual Programming Language and Translators - Spring 2017 Prof. Stephen Edwards Akshay Nagpal Dhruv Shekhawat Parth Panchmatia Sagar Damani

More information

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018 Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Spring 2018 Jill Seaman 1 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements...

More information

Class C{ int a; } what variables below are objects : a. C c; b. String str; c. Scanner scanner; d. int num; e. float f;

Class C{ int a; } what variables below are objects : a. C c; b. String str; c. Scanner scanner; d. int num; e. float f; Class C{ int a; } what variables below are objects : a. C c; b. String str; c. Scanner scanner; d. int num; e. float f; Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter

More information

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:

More information

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where

More information

Weighted Powers Ranking Method

Weighted Powers Ranking Method Weighted Powers Ranking Method Introduction The Weighted Powers Ranking Method is a method for ranking sports teams utilizing both number of teams, and strength of the schedule (i.e. how good are the teams

More information

Tic Tac Toe Game! Day 8

Tic Tac Toe Game! Day 8 Tic Tac Toe Game! Day 8 Game Description We will be working on an implementation of a Tic-Tac-Toe Game. This is designed as a two-player game. As you get more involved in programming, you might learn how

More information

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming Arrays: Higher Dimensional Arrays CS0007: Introduction to Computer Programming Review If the == operator has two array variable operands, what is being compared? The reference variables held in the variables.

More information

(8-1) Arrays I H&K Chapter 7. Instructor - Andrew S. O Fallon CptS 121 (October 8, 2018) Washington State University

(8-1) Arrays I H&K Chapter 7. Instructor - Andrew S. O Fallon CptS 121 (October 8, 2018) Washington State University (8-1) Arrays I H&K Chapter 7 Instructor - Andrew S. O Fallon CptS 121 (October 8, 2018) Washington State University What is an array? A sequence of items that are contiguously allocated in memory All items

More information

Arrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA.

Arrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA. Arrays Defining arrays, declaration and initialization of arrays Introduction Many applications require the processing of multiple data items that have common characteristics (e.g., a set of numerical

More information

EECE.2160: ECE Application Programming Fall 2017

EECE.2160: ECE Application Programming Fall 2017 EECE.2160: ECE Application Programming Fall 2017 1. (35 points) Functions Exam 2 Solution a. (15 points) Show the output of the short program below exactly as it will appear on the screen. Be sure to clearly

More information

Functions, Arrays & Structs

Functions, Arrays & Structs Functions, Arrays & Structs Unit 1 Chapters 6-7, 11 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where a parameter is: datatype identifier

More information

TOPICS TO COVER:-- Array declaration and use.

TOPICS TO COVER:-- Array declaration and use. ARRAYS in JAVA TOPICS TO COVER:-- Array declaration and use. One-Dimensional Arrays. Passing arrays and array elements as parameters Arrays of objects Searching an array Sorting elements in an array ARRAYS

More information

Multiple-Subscripted Arrays

Multiple-Subscripted Arrays Arrays in C can have multiple subscripts. A common use of multiple-subscripted arrays (also called multidimensional arrays) is to represent tables of values consisting of information arranged in rows and

More information

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class:

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class: More on Classes tostring One special method in Java is the tostring method. The method (regardless of which class it s added to) has the following prototype: public String tostring(); The job of this method

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays A First Book of ANSI C Fourth Edition Chapter 8 Arrays Objectives One-Dimensional Arrays Array Initialization Arrays as Function Arguments Case Study: Computing Averages and Standard Deviations Two-Dimensional

More information

ECE15: Lab #4. Problem 1. University of California San Diego

ECE15: Lab #4. Problem 1. University of California San Diego University of California San Diego ECE15: Lab #4 This lab is a cumulative wrap-up assignment for the entire course. As such, it relates to the material covered in Lecture Units 1 5 and 7 9 in class. Here

More information

Lab Session # 5 Arrays. ALQUDS University Department of Computer Engineering

Lab Session # 5 Arrays. ALQUDS University Department of Computer Engineering 2013/2014 Programming Fundamentals for Engineers Lab Lab Session # 5 Arrays ALQUDS University Department of Computer Engineering Objective: After completing this session, the students should be able to:

More information

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable Today in CS161 Lecture #12 Arrays Learning about arrays Being able to store more than one item using a variable Examples Tic Tac Toe board as an array Graphical User interaction for the tic tac toe program

More information

Chapter 6: Arrays. Starting Out with Games and Graphics in C++ Second Edition. by Tony Gaddis

Chapter 6: Arrays. Starting Out with Games and Graphics in C++ Second Edition. by Tony Gaddis Chapter 6: Arrays Starting Out with Games and Graphics in C++ Second Edition by Tony Gaddis 6.1 Array Basics An array allows you to store a group of items of the same data type together in memory Why?

More information

RANDOM NUMBER GAME PROJECT

RANDOM NUMBER GAME PROJECT Random Number Game RANDOM NUMBER GAME - Now it is time to put all your new knowledge to the test. You are going to build a random number game. - The game needs to generate a random number between 1 and

More information

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I C++ ARRAYS POINTERS POINTER ARITHMETIC Problem Solving with Computers-I General model of memory Sequence of adjacent cells Each cell has 1-byte stored in it Each cell has an address (memory location) Memory

More information

CS 314 Exam 2 Spring

CS 314 Exam 2 Spring Points off 1 2 3 4 5 Total off CS 314 Exam 2 Spring 2017 Your Name Your UTEID Instructions: 1. There are 5 questions on this test. 100 points available. Scores will be scaled to 200 points. 2. You have

More information

COMP 110 Introduction to Programming. What did we discuss?

COMP 110 Introduction to Programming. What did we discuss? COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? 1 Today Announcements Assignment

More information

COMP 110 Programming Exercise: Simulation of the Game of Craps

COMP 110 Programming Exercise: Simulation of the Game of Craps COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,

More information

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018 Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018 Due: Tuesday, September 18, 11:59 pm Collaboration Policy: Level 1 (review full policy for details) Group Policy: Individual This lab will give you experience

More information

Chapter 6: Using Arrays

Chapter 6: Using Arrays Chapter 6: Using Arrays Declaring an Array and Assigning Values to Array Array Elements A list of data items that all have the same data type and the same name Each item is distinguished from the others

More information

Arrays. Array Basics. Chapter 8 Spring 2017, CSUS. Chapter 8.1

Arrays. Array Basics. Chapter 8 Spring 2017, CSUS. Chapter 8.1 Arrays Chapter 8 Spring 2017, CSUS Array Basics Chapter 8.1 1 Array Basics Normally, variables only have one piece of data associated with them An array allows you to store a group of items of the same

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using

More information

Lecture (07) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Fall 2015, Programming I

Lecture (07) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Fall 2015, Programming I Lecture (07) Arrays By: Dr Ahmed ElShafee ١ introduction An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type Instead

More information

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1 Ba Arrays Arrays A normal variable holds value: An array variable holds a collection of values: 4 Naming arrays An array has a single name, so the elements are numbered or indexed. 0 3 4 5 Numbering starts

More information

CS 101, Spring 2016 March 22nd Exam 2

CS 101, Spring 2016 March 22nd Exam 2 CS 101, Spring 2016 March 22nd Exam 2 Name: Question 1. [3 points] Which of the following loop statements would most likely cause the loop to execute exactly n times? You may assume that n will be set

More information

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections C++ Programming Chapter 6 Arrays and Vectors Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics

More information

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays Chapter 5 Arrays Learning Objectives Introduction to Arrays Declaring and referencing arrays For-loops and arrays Arrays in memory Arrays in Functions Arrays as function arguments, return values Programming

More information

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) For this lab you may work with a partner, or you may choose to work alone. If you choose to work with a partner, you are still responsible for the lab

More information

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing

More information

The Simon State Machine Part 1

The Simon State Machine Part 1 The Simon State Machine Part 1 Lab Summary This lab is the first part to a two-part lab where you will be combining all the components you created throughout the semester into one functioning state machine.

More information

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays A First Book of ANSI C Fourth Edition Chapter 8 Arrays One-Dimensional Arrays Array Initialization Objectives Arrays as Function Arguments Case Study: Computing Averages and Standard Deviations Two-Dimensional

More information

FORM 2 (Please put your name and form # on the scantron!!!!)

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7) Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants

More information

Condition Controlled Loops. Introduction to Programming - Python

Condition Controlled Loops. Introduction to Programming - Python Condition Controlled Loops Introduction to Programming - Python Decision Structures Review Programming Challenge: Review Ask the user for a number from 1 to 7. Tell the user which day of the week was selected!

More information

Pointers, Arrays and Parameters

Pointers, Arrays and Parameters Pointers, Arrays and Parameters This exercise is different from our usual exercises. You don t have so much a problem to solve by creating a program but rather some things to understand about the programming

More information

Programming for Engineers Arrays

Programming for Engineers Arrays Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that

More information

CSC 1300 Exam 4 Comprehensive-ish and Structs

CSC 1300 Exam 4 Comprehensive-ish and Structs CSC 1300 Exam 4 Comprehensive-ish and Structs December 8, 2017 Name: Read through the entire test first BEFORE starting Multiple Choice and T/F sections should be completed on the scantron Test has two

More information

Chapter 7 Arrays. One-Dimensional Arrays. Fred Jack. Anna. Sue. Roy

Chapter 7 Arrays. One-Dimensional Arrays. Fred Jack. Anna. Sue. Roy Chapter 7 Arrays High-level languages provide programmers with a variety of ways of organising data. There are not only simple data types, but also data structures. A data structure is a data type composed

More information

Arrays. Arizona State University 1

Arrays. Arizona State University 1 Arrays CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 8 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

IT115: Introduction to Java Programming 1. IT115: Introduction to Java Programming. Tic Tac Toe Application. Trina VanderLouw

IT115: Introduction to Java Programming 1. IT115: Introduction to Java Programming. Tic Tac Toe Application. Trina VanderLouw IT115: Introduction to Java Programming 1 IT115: Introduction to Java Programming Tic Tac Toe Application Trina VanderLouw Professor Derek Peterson Colorado Technical University Online October 28, 2011

More information

CS 223: Data Structures and Programming Techniques. Exam 2. April 19th, 2012

CS 223: Data Structures and Programming Techniques. Exam 2. April 19th, 2012 CS 223: Data Structures and Programming Techniques. Exam 2 April 19th, 2012 Instructor: Jim Aspnes Work alone. Do not use any notes or books. You have approximately 75 minutes to complete this exam. Please

More information

Arrays OBJECTIVES. In this chapter you will learn:

Arrays OBJECTIVES. In this chapter you will learn: 7 Arrays Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then

More information

2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier

2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier Lesson 4 Arrays and Lists Review CSC 123 Fall 2018 Answer Sheet Short Answers 1. In an array declaration, this indicates the number of elements that the array will have. b a. subscript b. size declarator

More information

Computing and Programming

Computing and Programming Computing and Programming Notes for CSC 100 - The Beauty and Joy of Computing The University of North Carolina at Greensboro Reminders: What you should be doing! Blown to Bits, Chapter 1: Should have completed

More information

Computing and Programming. Notes for CSC The Beauty and Joy of Computing The University of North Carolina at Greensboro

Computing and Programming. Notes for CSC The Beauty and Joy of Computing The University of North Carolina at Greensboro Computing and Programming Notes for CSC 100 - The Beauty and Joy of Computing The University of North Carolina at Greensboro Reminders: What you should be doing! Blown to Bits, Chapter 1: Should have completed

More information

AP Computer Science Lists The Array type

AP Computer Science Lists The Array type AP Computer Science Lists There are two types of Lists in Java that are commonly used: Arrays and ArrayLists. Both types of list structures allow a user to store ordered collections of data, but there

More information

2D Array Practice. Lecture 26

2D Array Practice. Lecture 26 2D Array Practice Lecture 26 Announcements Worksheet 6 and Problem Set 6 Posted to COMP110.com Final Deliverables of the Semester! PS6 - Compstagram Demo Regular Review Session Schedule General - Wednesday

More information

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz Senet Language Reference Manual 26 th October 2015 Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz 1. Overview Past projects for Programming Languages and Translators have

More information

Procedural Programming

Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Procedural Programming Session Five: Arrays Name: First Name: Tutor: Matriculation-Number: Group-Number: Date: Prof. Dr.Ing. Axel Hunger Dipl.-Ing.

More information

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section:

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section: 7 Arrays Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then

More information

NCAA Instructions Nerdy for Sports

NCAA Instructions Nerdy for Sports Home Page / Login 2 Registration 3 Main Menu 4 Making your Picks 5 Editing your Picks 7 View your Picks 8 Double Check your Picks 9 Actual Results 11 Payouts 12 Reports 12 League History 16 Contact Us

More information

Introduction to Computer Science Unit 3. Programs

Introduction to Computer Science Unit 3. Programs Introduction to Computer Science Unit 3. Programs This section must be updated to work with repl.it Programs 1 to 4 require you to use the mod, %, operator. 1. Let the user enter an integer. Your program

More information

CS1 Studio Project: Connect Four

CS1 Studio Project: Connect Four CS1 Studio Project: Connect Four Due date: November 8, 2006 In this project, we will implementing a GUI version of the two-player game Connect Four. The goal of this project is to give you experience in

More information

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous

More information

Objective-C. Stanford CS193p Fall 2013

Objective-C. Stanford CS193p Fall 2013 New language to learn! Strict superset of C Adds syntax for classes, methods, etc. A few things to think differently about (e.g. properties, dynamic binding) Most important concept to understand today:

More information

Dim there(2) As Double represents? been changed. You can access the elements of the array in any

Dim there(2) As Double represents? been changed. You can access the elements of the array in any Last weeks program contains some first syntax apart from procedure and data. As part of the data structure, we used an array to hold the three components of the three dimensional coordinates here and there.

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

GridLang: Grid Based Game Development Language. Programming Language and Translators - Spring 2017 Prof. Stephen Edwards

GridLang: Grid Based Game Development Language. Programming Language and Translators - Spring 2017 Prof. Stephen Edwards GridLang: Grid Based Game Development Language Programming Language and Translators - Spring 2017 Prof. Stephen Edwards Akshay Nagpal Dhruv Shekhawat Parth Panchmatia Sagar Damani an2756 @columbia.edu

More information

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory Pointers A pointer is simply a reference to a variable/object Compilers automatically generate code to store/retrieve variables from memory It is automatically generating internal pointers We don t have

More information

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key CIS 110 Fall 2016 Midterm 1 CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key 1.) The Easy One (1 point total) Check cover sheet for name, recitation #, PennKey,

More information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

Distributions of Continuous Data

Distributions of Continuous Data C H A P T ER Distributions of Continuous Data New cars and trucks sold in the United States average about 28 highway miles per gallon (mpg) in 2010, up from about 24 mpg in 2004. Some of the improvement

More information

Chapter 7: Arrays and the ArrayList Class

Chapter 7: Arrays and the ArrayList Class Chapter 7: Arrays and the ArrayList Class Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 7 discusses the following main topics: Introduction

More information

Java Programming: from the Beginning

Java Programming: from the Beginning CSc 2310: Principle of Programming g( (Java) Spring 2013 Java Programming: from the Beginning Chapter 5 Arrays 1 Copyright 2000 W. W. Norton & Company. All rights reserved. Outline 5.1 Creating and Using

More information

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013 Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

More information

1 Short Answer (2 Points Each)

1 Short Answer (2 Points Each) Fall 013 Exam # Key COSC 117 1 Short Answer ( Points Each) 1. What is the scope of a method/function parameter? The scope of a method/function parameter is in the method only, that is, it is local to the

More information

Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level

Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level www.xtremepapers.com Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level *0007615708* COMPUTING 9691/21 Paper 2 May/June 2015 2 hours Candidates answer on

More information

Add the backgrounds. Add the font.

Add the backgrounds. Add the font. To find all sprites, font, and backgrounds look in your resources folder under card game. Pick sprites for the following: The Mouse Desired Objects A disappearing animation for the desired objects Clutter

More information

Lecture 14. 'for' loops and Arrays

Lecture 14. 'for' loops and Arrays Lecture 14 'for' loops and Arrays For Loops for (initiating statement; conditional statement; next statement) // usually incremental body statement(s); The for statement provides a compact way to iterate

More information

Expressions and Casting

Expressions and Casting Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

More information

MICROPROCESSORS A (17.383) Fall Lecture Outline

MICROPROCESSORS A (17.383) Fall Lecture Outline MICROPROCESSORS A (17.383) Fall 2010 Lecture Outline Class # 04 September 28, 2010 Dohn Bowden 1 Today s Lecture Syllabus review Microcontroller Hardware and/or Interface Programming/Software Lab Homework

More information

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #7 Arrays Part II Passing Array to a Function

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Recap of Function Calls and Parameter Passing Dr. Deepak B. Phatak & Dr. Supratik

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

Introduction to Arrays

Introduction to Arrays Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an

More information

CS 537: Intro to Operating Systems (Fall 2017) Worksheet 3 - Scheduling & Process API Due: Sep 27 th 2017 (Wed) in-class OR Simmi before 5:30 pm

CS 537: Intro to Operating Systems (Fall 2017) Worksheet 3 - Scheduling & Process API Due: Sep 27 th 2017 (Wed) in-class OR  Simmi before 5:30 pm CS 537: Intro to Operating Systems (Fall 2017) Worksheet 3 - Scheduling & Process API Due: Sep 27 th 2017 (Wed) in-class OR email Simmi before 5:30 pm 1. Basic Scheduling Assume a workload with the following

More information

Maltepe University Computer Engineering Department. BİL 133 Algorithms and Programming. Chapter 8: Arrays

Maltepe University Computer Engineering Department. BİL 133 Algorithms and Programming. Chapter 8: Arrays Maltepe University Computer Engineering Department BİL 133 Algorithms and Programming Chapter 8: Arrays What is an Array? Scalar data types use a single memory cell to store a single value. For many problems

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game

More information

An algorithm may be expressed in a number of ways:

An algorithm may be expressed in a number of ways: Expressing Algorithms pseudo-language 1 An algorithm may be expressed in a number of ways: natural language: flow charts: pseudo-code: programming language: usually verbose and ambiguous avoid most (if

More information

ESC101N: Fundamentals of Computing End-sem st semester

ESC101N: Fundamentals of Computing End-sem st semester ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.

More information

CSCI 162 Dr. Stephanie Schwartz Fall 2014 Review Questions for Exam 1 ** adapted from Ms. Katz and Dr. Hutchens **

CSCI 162 Dr. Stephanie Schwartz Fall 2014 Review Questions for Exam 1 ** adapted from Ms. Katz and Dr. Hutchens ** CSCI 162 Dr. Stephanie Schwartz Fall 2014 Review Questions for Exam 1 ** adapted from Ms. Katz and Dr. Hutchens ** (answers to select problems) 4. (3 pts) Describe the purpose of the instance variables

More information

ECE4530 Fall 2015: The Codesign Challenge I Am Seeing Circles. Application: Bresenham Circle Drawing

ECE4530 Fall 2015: The Codesign Challenge I Am Seeing Circles. Application: Bresenham Circle Drawing ECE4530 Fall 2015: The Codesign Challenge I Am Seeing Circles Assignment posted on Thursday 11 November 8AM Solutions due on Thursday 3 December 8AM The Codesign Challenge is the final assignment in ECE

More information

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question Page 1 of 6 Template no.: A Course Name: Computer Programming1 Course ID: Exam Duration: 2 Hours Exam Time: Exam Date: Final Exam 1'st Semester Student no. in the list: Exam pages: Student's Name: Student

More information

Homework 1. Hadachi&Lind October 25, Deadline for doing homework is 3 weeks starting from now due date is:

Homework 1. Hadachi&Lind October 25, Deadline for doing homework is 3 weeks starting from now due date is: Homework 1 Hadachi&Lind October 25, 2017 Must Read: 1. Deadline for doing homework is 3 weeks starting from now 2017.10.25 due date is: 2017.11.15 5:59:59 EET 2. For any delay in submitting the homework

More information

BOREDGAMES Language for Board Games

BOREDGAMES Language for Board Games BOREDGAMES Language for Board Games I. Team: Rujuta Karkhanis (rnk2112) Brandon Kessler (bpk2107) Kristen Wise (kew2132) II. Language Description: BoredGames is a language designed for easy implementation

More information

General Certificate of Education Advanced Subsidiary Examination June 2010

General Certificate of Education Advanced Subsidiary Examination June 2010 General Certificate of Education Advanced Subsidiary Examination June 2010 Computing COMP1/PM/C# Unit 1 Problem Solving, Programming, Data Representation and Practical Exercise Preliminary Material A copy

More information

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1 FACULTY OF SCIENCE AND TECHNOLOGY SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1 ACADEMIC SESSION 2014; SEMESTER 3 PRG102D: BASIC PROGRAMMING CONCEPTS Section A Compulsory section Question

More information