1 / 9

Computer Science 2

Computer Science 2. 3/8/2018 Dry run Declarations Fix it Continue with Life, Magic and Catch -up. program Sample2; type rectype = record of a:integer; b:real; end; arraytype = array[1..5] of rectype; var data: arraytype; count:integer; begin for count := 1 to 5 do

wilsonsarah
Télécharger la présentation

Computer Science 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 2 3/8/2018 Dry run Declarations Fix it Continue with Life, Magic and Catch -up

  2. program Sample2; type rectype = record of a:integer; b:real; end; arraytype = array[1..5] of rectype; var data: arraytype; count:integer; begin for count := 1 to 5 do begin data[count].a:= 2* count; data[count].b:= count -2; end; for count:= 1 to 5 do data[count].b:= data[count].b +data[count].a; for count:= 5 downto 1 do writeln(data[count].a:5, data[count].b:5:2); for count:= 1 to 4 do begin with data[count] do begin a := a + b; b := a*b; end; end; for count:= 1 to 5 do with data[count] do writeln(a,b:5:2) end. Dry Run!!

  3. Write the declarations for.. • Storing 25 names, addresses, and ages. • Storing 50 x-coordinates, y-coordinates, colors (numerical value), and file names (strings) for graphics. • Creating a board for tic-tac-toe

  4. Fix the following program wreckt; type record = record begin name:string; phone:number; end PhoneBook = array[1..10] of phones; var count:integer; PhoneBook:Arry of records; begin for count:= 1 to 10 do begin writeln('Please enter the name'); readln(Phoneboook[count]); writeln('Please enter the phone number'); readln(Phonebook[number]); end; for count:= 1 to 10 do writeln(Phonebook[count]); end. This file is on the website as wreckt.pas

  5. Program: Life • The universe is a two-dimensional grid of square cells, each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated". • Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur: • Any live cell with fewer than two live neighbors dies, as if caused by under population. • Any live cell with two or three live neighbors lives on to the next generation. • Any live cell with more than three live neighbors dies, as if by overpopulation. • Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

  6. Patterns - Any live cell with fewer than two live neighbors dies, as if caused by under population. - Any live cell with two or three live neighbors lives on to the next generation. - Any live cell with more than three live neighbors dies, as if by overpopulation. - Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

  7. Hint: include a boundary around your world. Your application of Life • You determine the size of the universe • Fill your universe: Examples • Each cell has a 1 in N chance of being alive for the first generation. You select the value for N or have the user enter the value for N. • Look up potential life patterns. • Run the game for several generations. Show the universe after each generation • Push: Break the program into procedures. • neighbors(), showUniverse(), populate() • Push: Determine a way to use records in your solution. • Push: Have your universe ‘wrap’

  8. Magic Square • A magic square[1] is a n by n square grid (where n is the number of cells on each side) filled with distinct positive integers in the range {1,2,...,n2} such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal

  9. Magic Square Program • Write a program that will take as input the values for each cell of a 3x3 potential magic square and determine if the square is magic. • Push: Write a program to generate 3x3 magic squares. Using an algorithm rather than just hard coding a found solution. • Push: Modify this to handle n x n magic squares.

More Related