Tic Tac Toe Game! Day 8

Size: px
Start display at page:

Download "Tic Tac Toe Game! Day 8"

Transcription

1 Tic Tac Toe Game! Day 8

2 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 to design one with the computer using random numbers :) For this game, there will be two players one represented as x and one as o. The first turn is Player X s turn. Each player can place one piece on the board during their turn. The player decides where to place their piece by inputting a row and column coordinate. A player wins when 3 of their pieces form a line; diagonal, horizontal, and vertical all count.

3 Example Run:

4 Creating the tic-tac-toe board (part 1) In order to create the tic-tac-toe board, we store it as a string. But first let s write the board as a series of strings! The first row of the board as a string would be: string row1 = 1 2 3\n ; index counting: string row2 = 1 \n ; index counting: string row3 = \n ; index counting: // what are the last 3 rows? // remember that \n is ONE character

5 Creating the tic-tac-toe board (part 2) Once you have all the rows stored in strings, we want to put them into one string. Remember from earlier: string str1 = pan ; string str2 = cake ; string str3 = str1 + str2; // what does str3 store? So if we currently have string row1 = 1 2 3\n ; string row2 = 1 \n ; string row3 = \n ; etcetera, how would we put them into one string that stores the whole board? string board = ;

6 printboard This function should take in a string that represents the entire board. Then it should output the string to the console. HINT: do not return the string! For aesthetic purposes, maybe cout newlines before and after the board so it is separated a bit from the other outputs.

7 String [] The string class has the bracket function. It can take in an index position inside the [] and will return the character at that position. This function is unique because it allows you to change the value of the char inside the string. Ex. // These do the same thing string word = California Adventure ; char letter1 = word.substr(1,1); char letter2 = word[1]; //But, we can edit chars in the string! word[1] = A ; cout << word; //What is the output?

8 getindex This function should accept two int parameters, a row position and a column position. It should return the index in the giant string board where that coordinate is located at. Ex: getindex(1,1); string row1&2 = 1 2 3\n1 \n ; If I want to change the value in the string, I would have to know the index. Which is why we need this function.

9 Indexing board: Remember! The entire string board written out would look like: string board = " 1 2 3\n1 \n \n2 \n \n3 \n"; If we wanted the index of position (1,1), the function getindex would return 14. If we wanted the index of position (1,2), the function getindex would return 18. If we wanted the index of position (1,3), the function getindex would return \n1 \n

10 getindex int getindex(int row, int col){ if(row == 1 && col == 1){ return 14; } else if( row == 1 && col == 2){ return 18; } else if( row == 1 && col == 3){ return 22; } // what is the rest of the code? }

11 Passing by Value Let s create a function that adds ten to the number inputted into the function //Outside of main int add_10(int val){ val += 10; return val; } //Using in main int main(){ int numb = 20; add_10(numb); cout << numb; return 0; } We had explained earlier that a variable passed into the functions would be only take the value of it. This line is taking the value of 10 and saving 10 into val. When this function is returned, this line will have a value of 20. But has numb changed? What if we want numb to change?

12 Passing by Reference When declaring a function, we can pass in a variable by reference which means it will be able to update changes to the variable passed in a function. If you want to pass in a variable by reference, you will include an & before the name of the variable in the function parameter list. Ex: int add_10(int &val){ } val += 10; return val; Can only use this with variables passed in! int main(){ int numb = 10; add_10(numb); add_10(numb); add_10(numb); add_10(10); //ERROR! DO NOT DO PLz } cout << numb; //what is the output

13 Visual Representation

14 mark : Place pieces on board This function will place an x or o in a position, given as row and column, on the board. What information (parameters) do we need to make this function? What data types are the parameters? What would the return type be?

15 mark So mark needs : Row number where the piece will be placed (int) Column number where the piece will be placed (int) Entire board (string) Which piece it is, either x or o (char) Should any be passed by reference?

16 win: checking to see if someone won Write a function called win which checks to see if someone won! You decide on which parameters the function should have. We recommend that function returns a bool (true if someone won and false if someone has not won). Remember, there are 8 ways to win tic tac toe!

17 win General idea: we want to see if there are three of the same mark in a row. Example: //checking to see if there are three x s in the first row if (board[14] == x && board[18] == x && board[22] == x ) { return true; } //what are the other 7 ways for x to win? What about o winning? Note: we must use the single quotes when writing x because the viewing brackets look at a char within the string at a particular index.

18 Optional Functions printboard, getindex, mark, and win are the four functions that are necessary for the tic tac toe game to work. However, you can also write other functions that may be helpful in your code! One suggestion is making a winner function, which will cout a message depending on who won (or if no one won). If you have any other function in mind that you want to code, let one of us know and we can help you construct it!

19 Writing the tic tac toe program Most games that we know are repetitive in some way or another. Tic Tac Toe is not any different. Therefore, it would be a good idea to use a loop somewhere in our game. Think about it... What parts of the game are repeated? What is the most number of times this process is repeated? What is the least number of times this process is repeated? When should the repeated process stop? (What are the conditions?) What would be the best loop to use?

20 Alternating Turns Within the loop, Player X and Player O alternate turns. This means that: if (it is Player X s turn), certain code should be executed, or else it is Player O x turn and certain code should be executed. There are several different ways that we can write the conditions for this code. Please share with us your ideas on how we could do this!

21 Player X s Turn First the computer will tell them it s their turn as well as asking them where would they like to move. Then the player must enter the row and column of where they would like to move. The numbers should be separated by a space. Lastly the board is printed with their move. How would we code this? Remember! Use your functions.

22 Player O s Turn Player O s turn is very similar to Player X s turn! First the computer will tell them it s their turn as well as asking them where would they like to move. Then the player must enter the row and column of where they would like to move. The numbers should be separated by a space. Lastly the board is printed with their move. How would we code this? Remember! Use your functions.

23 Concluding the game After the game, if you want to print a message based off of who won, or a tie, this code or (function) would be used after the loop! If you do not wish to include this part, that s fine. Congratulations! You have created a tic-tac-toe game! We thank you for sticking around the entire two weeks (:

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

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

Lab Activity #7 2D Arrays and File Streams

Lab Activity #7 2D Arrays and File Streams Lab Activity #7 2D Arrays and File Streams Exercise #1: Write a program that declares a two-dimensional array named myfancyarray of the type double. Initialize the array to the following values: 23 14.12

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

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

Functionally Modular. Self-Review Questions

Functionally Modular. Self-Review Questions Functionally Modular 5 Self-Review Questions Self-review 5.1 Which names are local, which are global and which are built-in in the following code fragment? Global names: Built-in names: space_invaders

More information

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class For this assignment we will be developing a text-based Tic Tac Toe game 1. The key to this assignment is that we re going

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

CSci 1113 Lab Exercise 6 (Week 7): Arrays & Strings

CSci 1113 Lab Exercise 6 (Week 7): Arrays & Strings CSci 1113 Lab Exercise 6 (Week 7): Arrays & Strings Strings Representing textual information using sequences of characters is common throughout computing. Names, sentences, text, prompts, etc. all need

More information

CSC 108. Prof. Yue-Ling Wong. Lab 6: Tic-tac-toe Game

CSC 108. Prof. Yue-Ling Wong. Lab 6: Tic-tac-toe Game CSC 108 Spring 2010 Prof Yue-Ling Wong Lab 6: Tic-tac-toe Game 1 What you have for Lab06 so far two 2-D arrays to model the tic-tac-toe game board: board: to store the movieclip instance names of the cells

More information

Lecture 10: for, do, and switch

Lecture 10: for, do, and switch Lecture 10: for, do, and switch Jiajia Liu Recall the while Loop The while loop has the general form while ( boolean condition ) { The while loop is like a repeated if statement. It will repeat the statements

More information

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132) BoredGames Language Reference Manual A Language for Board Games Brandon Kessler (bpk2107) and Kristen Wise (kew2132) 1 Table of Contents 1. Introduction... 4 2. Lexical Conventions... 4 2.A Comments...

More information

CS159 Midterm #1 Review

CS159 Midterm #1 Review Name: CS159 Midterm #1 Review 1. Choose the best answer for each of the following multiple choice questions. (a) What is the effect of declaring a class member to be static? It means that the member cannot

More information

Two Dimensional Arrays

Two Dimensional Arrays + Two Dimensional Arrays + Two Dimensional Arrays So far we have studied how to store linear collections of data using a single dimensional array. However, the data associated with certain systems (a digital

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

Haskell Refresher Informatics 2D

Haskell Refresher Informatics 2D Haskell Purely functional! : Everything is a function Haskell Refresher Informatics 2D Kobby. K.A. Nuamah 30 January 2015 Main topics: Recursion Currying Higher-order functions List processing functions

More information

Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015

Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015 Classwork 7: Craps N. Duong & R. Rodriguez, Java Crash Course January 6, 2015 For this classwork, you will be writing code for the game Craps. For those of you who do not know, Craps is a dice-rolling

More information

Question 1 [20 points]

Question 1 [20 points] Question 1 [20 points] a) Write the following mathematical expression in Java. c=math.sqrt(math.pow(a,2)+math.pow(b,2)- 2*a*b*Math.cos(gamma)); b) Write the following Java expression in mathematical notation.

More information

CS 102 Lab 3 Fall 2012

CS 102 Lab 3 Fall 2012 Name: The symbol marks programming exercises. Upon completion, always capture a screenshot and include it in your lab report. Email lab report to instructor at the end of the lab. Review of built-in functions

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

BEGINNER PHP Table of Contents

BEGINNER PHP Table of Contents Table of Contents 4 5 6 7 8 9 0 Introduction Getting Setup Your first PHP webpage Working with text Talking to the user Comparison & If statements If & Else Cleaning up the game Remembering values Finishing

More information

Tic-Tac-Toe. By the time you are done with this activity, you and your team should be able to:

Tic-Tac-Toe. By the time you are done with this activity, you and your team should be able to: Tic-Tac-Toe Team Name: Manager: Recorder: Presenter: Analyst: This is a Process Oriented Guided Inquiry Learning (POGIL) activity. You and your team will examine a working program. A series of questions

More information

1) Log on to the computer using your PU net ID and password.

1) Log on to the computer using your PU net ID and password. CS 150 Lab Logging on: 1) Log on to the computer using your PU net ID and password. Connecting to Winter: Winter is the computer science server where all your work will be stored. Remember, after you log

More information

Session 8.2. Finding Winners Using Arrays

Session 8.2. Finding Winners Using Arrays 1 Session 8.2 Finding Winners Using Arrays 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

More information

Exercise: Inventing Language

Exercise: Inventing Language Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Lab 9: Pointers and arrays

Lab 9: Pointers and arrays CMSC160 Intro to Algorithmic Design Blaheta Lab 9: Pointers and arrays 3 Nov 2011 As promised, we ll spend today working on using pointers and arrays, leading up to a game you ll write that heavily involves

More information

Blocky: A Game of Falling Blocks

Blocky: A Game of Falling Blocks ECE220: Computer Systems and Programming Machine Problem 6 Spring 2018 Honors Section due: Thursday 1 March, 11:59:59 p.m. Blocky: A Game of Falling Blocks Your task this week is to implement a game of

More information

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week!

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week! 6.189 Project 1 Readings Get caught up on all the readings from this week! What to hand in Print out your hangman code and turn it in Monday, Jaunary 10 at 2:10 PM. Be sure to write your name and section

More information

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) Review Final exam Final exam will be 12 problems, drop any 2 Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) 2 hours exam time, so 12 min per problem (midterm 2 had

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

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017 EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017 Name: Lecture time (circle 1): 8-8:50 (Sec. 201) 12-12:50 (Sec. 203) 1-1:50 (Sec. 202) For this exam, you may use only one 8.5

More information

Final Exam, 3/17/2016 CIS330, Winter 2016

Final Exam, 3/17/2016 CIS330, Winter 2016 Final Exam, 3/17/2016 CIS330, Winter 2016 You have 2 hours to complete this exam. You are not allowed to use any books, notes, calculators, or electronic devices. Feel free to separate pages, just make

More information

COMP1917: 09 Arrays and Strings

COMP1917: 09 Arrays and Strings COMP1917: 09 Arrays and Strings Sim Mautner s.mautner@unsw.edu.au August 15, 2016 Sim Mautner (UNSW) COMP1917: 09 Arrays and Strings August 15, 2016 1 / 14 Arrays int sum(int n1, int n2); int sum(int n1,

More information

EECS 183. Week 3 - Diana Gage. www-personal.umich.edu/ ~drgage

EECS 183. Week 3 - Diana Gage. www-personal.umich.edu/ ~drgage EECS 183 Week 3 - Diana Gage www-personal.umich.edu/ ~drgage Upcoming Deadlines Lab 3 and Assignment 3 due October 2 nd (this Friday) Project 2 will be due October 6 th (a week from Friday) Get started

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

More Arrays. Last updated 2/6/19

More Arrays. Last updated 2/6/19 More Last updated 2/6/19 2 Dimensional Consider a table 1 2 3 4 5 6 5 4 3 2 12 11 13 14 15 19 17 16 3 1 4 rows x 5 columns 2 tj 2 Dimensional Consider a table 1 2 3 4 5 6 5 4 3 2 12 11 13 14 15 19 17 16

More information

Declaring and ini,alizing 2D arrays

Declaring and ini,alizing 2D arrays Declaring and ini,alizing 2D arrays 4 2D Arrays (Savitch, Chapter 7.5) TOPICS Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe Game // se2ng up a 2D array final int M=3, N=4;

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

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world! 6.S189 Homework 1 http://web.mit.edu/6.189/www/materials.html What to turn in Do the warm-up problems for Days 1 & 2 on the online tutor. Complete the problems below on your computer and get a checkoff

More information

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski) THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in

More information

This Week s Agenda (Part A) CS121: Computer Programming I. The Games People Play. Data Types & Structures. The Array in Java.

This Week s Agenda (Part A) CS121: Computer Programming I. The Games People Play. Data Types & Structures. The Array in Java. CS121: Computer Programming I A) Collections B) File I/O & Error Handling Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use

More information

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 3 Matrix Math Introduction Reading In this lab you will write a

More information

Structs. Comp Sci 1570 Introduction to C++ Introduction. Aggregate data. Example. General syntax Object initialization Initialization and access

Structs. Comp Sci 1570 Introduction to C++ Introduction. Aggregate data. Example. General syntax Object initialization Initialization and access Structs Comp Sci 1570 to C++ Outline 1 2 3 The struct A structure is a group of elements grouped together under one name. These elements, known as members, can have different types and different lengths.

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

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Unit 7. 'while' Loops

Unit 7. 'while' Loops 1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #54. Organizing Code in multiple files

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #54. Organizing Code in multiple files Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #54 Organizing Code in multiple files (Refer Slide Time: 00:09) In this lecture, let us look at one particular

More information

Noughts and Crosses. Step 1: Drawing the grid. Introduction

Noughts and Crosses. Step 1: Drawing the grid. Introduction 6 Noughts and Crosses These projects are for use inside the UK only. All Code Clubs must be registered. You can check registered clubs at www.codeclub.org.uk/. This coursework is developed in the open

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

ROCK PAPER SCISSORS Rock Paper Scissors Lab Project Using C or C++

ROCK PAPER SCISSORS Rock Paper Scissors Lab Project Using C or C++ ROCK PAPER SCISSORS Rock Paper Scissors Lab Project Using C or C++ Copyright 2014 Dan McElroy Project Definition Truth Tables Topics Covered Keyboard Character Input (C and C++) Converting Characters to

More information

SFU CMPT Topic: Control Statements

SFU CMPT Topic: Control Statements SFU CMPT-212 2008-1 1 Topic: Control Statements SFU CMPT-212 2008-1 Topic: Control Statements Ján Maňuch E-mail: jmanuch@sfu.ca Wednesday 23 rd January, 2008 SFU CMPT-212 2008-1 2 Topic: Control Statements

More information

Introduction to Computer Programming

Introduction to Computer Programming Introduction to Computer Programming Lecture #7 - Conditional Loops The Problem with Counting Loops Many jobs involving the computer require repetition, and that this can be implemented using loops. Counting

More information

Control Structures: The IF statement!

Control Structures: The IF statement! Control Structures: The IF statement! 1E3! Topic 5! 5 IF 1 Objectives! n To learn when and how to use an IF statement.! n To be able to form Boolean (logical) expressions using relational operators! n

More information

I101/B100 Problem Solving with Computers

I101/B100 Problem Solving with Computers I101/B100 Problem Solving with Computers By: Dr. Hossein Computer Science and Informatics IU South Bend 1 What do we need to learn in order to write computer programs? Fundamental programming constructs:

More information

Lab 4 Due April 18 th

Lab 4 Due April 18 th Lab 4 Due April 18 th (100 pts) You may work with a partner if you want. Turn in one version with 2 names on it. Do not forget your partner s name. Or work alone. Your choice. Problem 1 (10 pts): Create

More information

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods Learning objec-ves 2D Arrays (Savitch, Chapter 7.5) TOPICS Using 2D arrays Decomposi-on of a solu-on into objects and methods Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe

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

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types datatype CS200: Computer Science I Module 14 More Data Types Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 More Data Types in addition to the data types double and int we

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

Final Exam, 3/17/2016 CIS330, Winter 2016

Final Exam, 3/17/2016 CIS330, Winter 2016 Final Exam, 3/17/2016 CIS330, Winter 2016 You have 2 hours to complete this exam. You are not allowed to use any books, notes, calculators, or electronic devices. Feel free to separate pages, just make

More information

//If target was found, then //found == true and a[index] == target.

//If target was found, then //found == true and a[index] == target. 230 CHAPTER 5 Arrays //If target was found, then //found == true and a[index] == target. } if (found) where = index; return found; 20. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 21. int a[4][5]; int index1, index2;

More information

CSE120 Wi18 Final Review

CSE120 Wi18 Final Review CSE120 Wi18 Final Review Practice Question Solutions 1. True or false? Looping is necessary for complex programs. Briefly explain. False. Many loops can be explicitly written out as individual statements

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

EECE.2160: ECE Application Programming Fall 2017

EECE.2160: ECE Application Programming Fall 2017 EECE.2160: ECE Application Programming Fall 2017 1. (34 points) Structures Exam 3 Solution a. (14 points) Show the output of the short program below exactly as it will appear on the screen. Be sure to

More information

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12 CS31 Discussion 1E Jie(Jay) Wang Week3 Oct.12 Outline Problems from Project 1 Review of lecture String, char, stream If-else statements Switch statements loops Programming challenge Problems from Project

More information

Lab 12: Lijnenspel revisited

Lab 12: Lijnenspel revisited CMSC160 Intro to Algorithmic Design Blaheta Lab 12: Lijnenspel revisited 16 April 2015 Today s lab will revisit and rework the Lijnenspel game code from Lab 7, possibly using my version as a starting point.

More information

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space. Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

More information

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment Practical 01: Printing to the Shell To program in Python you need the latest version of Python, which is freely available at www.python.org. Your school will have this installed on the computers for you,

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

CS 103 Lab - Party Like A Char Star

CS 103 Lab - Party Like A Char Star 1 Introduction In this lab you will implement a "hangman" game where the user is shown blanks representing letter of a word and then tries to guess and fill in the letters with a limited number of guesses.

More information

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Variables You have to instruct your computer every little thing it needs to do even

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

[ the academy_of_code] Senior Beginners

[ the academy_of_code] Senior Beginners [ the academy_of_code] Senior Beginners 1 Drawing Circles First step open Processing Open Processing by clicking on the Processing icon (that s the white P on the blue background your teacher will tell

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

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

Informatics 2D. Coursework 1: Search and Games

Informatics 2D. Coursework 1: Search and Games Informatics 2D. Coursework 1: Search and Games Stefanie Speichert, Vaishak Belle January 30, 2019 1 Introduction The objective of this assignment is to help you understand the various search algorithms

More information

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block THE IF STATEMENT The if statement is used to check a condition: if the condition is true, we run a block of statements (called the if-block), elsewe process another block of statements (called the else-block).

More information

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8 today: strings what are strings what are strings and why to use them reading: textbook chapter 8 a string in C++ is one of a special kind of data type called a class we will talk more about classes in

More information

Basic Computer Programming (Processing)

Basic Computer Programming (Processing) Contents 1. Basic Concepts (Page 2) 2. Processing (Page 2) 3. Statements and Comments (Page 6) 4. Variables (Page 7) 5. Setup and Draw (Page 8) 6. Data Types (Page 9) 7. Mouse Function (Page 10) 8. Keyboard

More information

CS Homework 10 p. 1. CS Homework 10

CS Homework 10 p. 1. CS Homework 10 CS 111 - Homework 10 p. 1 Deadline 11:59 pm on Friday, December 2, 2016 How to submit Each time you would like to submit your work: CS 111 - Homework 10 If your files are not already on nrs-labs, be sure

More information

Computer Science 252 Problem Solving with Java The College of Saint Rose Spring Topic Notes: Collections

Computer Science 252 Problem Solving with Java The College of Saint Rose Spring Topic Notes: Collections Computer Science 252 Problem Solving with Java The College of Saint Rose Spring 2014 Topic Notes: Collections Our next major topic involves additional common mechanisms for naming collections of items.

More information

CS31 Discussion 1E Spring 17 : week 08

CS31 Discussion 1E Spring 17 : week 08 CS31 Discussion 1E Spring 17 : week 08 TA: Bo-Jhang Ho bojhang@cs.ucla.edu Credit to former TA Chelsea Ju Project 5 - Map cipher to crib Approach 1: For each pair of positions, check two letters in cipher

More information

CPE Summer 2015 Exam I (150 pts) June 18, 2015

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one

More information

Lecture #9 **go to Blackboard ** Review from Shackelford Reading If statements Loops. Using if statements and loops

Lecture #9 **go to Blackboard ** Review from Shackelford Reading If statements Loops. Using if statements and loops Today in CS161 Lecture #9 **go to Blackboard ** Practicing Review from Shackelford Reading If statements Loops Begin writing Programs Using if statements and loops Graphics Begin creating the tic tac toe

More information

Computer Programming for Engineering Applica4ons. Intro to Programming 10/22/13 1 ECE 175. Mul4- dimensional Arrays

Computer Programming for Engineering Applica4ons. Intro to Programming 10/22/13 1 ECE 175. Mul4- dimensional Arrays Computer Programming for Engineering Applica4ons ECE 75 Intro to Programming Mul4- dimensional Arrays Declara4on of arrays with more than one dimension Syntax: data type array_name[size][size] Example:

More information

Python Games. Session 1 By Declan Fox

Python Games. Session 1 By Declan Fox Python Games Session 1 By Declan Fox Rules General Information Wi-Fi Name: CoderDojo Password: coderdojowireless Website: http://cdathenry.wordpress.com/ Plans for this year Command line interface at first

More information

Assignment #1 Simple C++

Assignment #1 Simple C++ Eric Roberts Handout #5 CS 106B January 7, 2015 Assignment #1 Simple C++ Due: Friday, January 16 Part 1. Get Qt Creator working Parts of this handout were written by Julie Zelenski. Your first task is

More information

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... CISC 2000 Computer Science II Fall, 2014 Note 12/1/2014 1 Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... (a) What s the purpose of inheritance?

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

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet)

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet) CS1114 Spring 2015 Test ONE ANSWER KEY page 1 of 8 pages (counting the cover sheet) For the following questions, use these variable definitions a = 36 b = 3 c = 12 d = '3' What is the type and value of

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Introduction to Programming I COS1511 School of Computing Revision Notes

Introduction to Programming I COS1511 School of Computing Revision Notes Introduction to Programming I COS1511 School of Computing Revision Notes UNISA 2018 1 Introduction Some key basic principles to remember: Apply the BODMAS rules of Mathematics for all calculations; The

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Study Guide for Test 2

Study Guide for Test 2 Study Guide for Test 2 Topics: decisions, loops, arrays, c-strings, linux Material Selected from: Chapters 4, 5, 6, 7, 10.1, 10.2, 10.3, 10.4 Examples 14 33 Assignments 4 8 Any syntax errors are unintentional

More information

Java Identifiers, Data Types & Variables

Java Identifiers, Data Types & Variables Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char

More information

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS These are sample pages from Kari Laitinen s book "A Natural Introduction to Computer Programming with Java". For more information, please visit http://www.naturalprogramming.com/javabook.html CHAPTER 5

More information

Ensuring a Rigorous Curriculum: Practices and Goals

Ensuring a Rigorous Curriculum: Practices and Goals Ensuring a Rigorous Curriculum: Practices and Goals Allen B. Tucker Bowdoin College www.bowdoin.edu/~allen April 12, 2002 1 of 30 Goals of an Undergraduate Program To prepare graduates for the computing

More information

CS12020 for CGVG. Practical 2. Jim Finnis

CS12020 for CGVG. Practical 2. Jim Finnis CS12020 for CGVG Practical 2 Jim Finnis (jcf1@aber.ac.uk) This week Solution to last week and discussion Global variables and the model The Main Loop pattern States and the State Machine pattern Random

More information