Computer Science 1 Week 14. CSc 1, Sacramento State This Week... QBasic Arrays QBasic Arrays Computer History Computer History Computer revolution

Post on 29-Dec-2015

217 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

Transcript

Computer Science 1Week 14

CSc 1, Sacramento State

This Week ...This Week ...

• QBasic ArraysQBasic Arrays• Computer HistoryComputer History

Computer revolution Computer revolution Video gamesVideo games

CSc 1, Sacramento State

QBasicQBasicArraysArrays

Storing data in a listStoring data in a list

CSc 1, Sacramento State

QBasic Variables QBasic Variables ReviewReview

• a a variablevariable is a location in memory is a location in memory it can store a single piece of datait can store a single piece of data e.g. string or a numbere.g. string or a number

• Think of it as a boxThink of it as a box information can be placed in itinformation can be placed in it ... and removed when necessary... and removed when necessary

CSc 1, Sacramento State

95

b

a

Variable ReviewVariable Review

a = 100

b = 95

100

CSc 1, Sacramento State

b

Variable ReviewVariable Review

a = 100

b = 9595

100

a

CSc 1, Sacramento State

Variable ReviewVariable Review

a = 100

b = 9595

b

100

a

CSc 1, Sacramento State

What is an Array?What is an Array?

• An An arrayarray is a group of variables that has is a group of variables that has multiple locationsmultiple locations

• Each array Each array element element has a location in has a location in memorymemory contain a different piece of datacontain a different piece of data referenced with a unique numberreferenced with a unique number ... this is called a ... this is called a subscript (a.k.a. index)subscript (a.k.a. index)

CSc 1, Sacramento State

What is an Array?What is an Array?

• Think of an array as a Think of an array as a set of mailboxes set of mailboxes (CSCMailBoxes)(CSCMailBoxes)

• Each mailbox belongs to Each mailbox belongs to the same the same arrayarray (CSCMailBoxes)(CSCMailBoxes)

• Each mailbox has a Each mailbox has a unique location unique location (index)(index)

CSc 1, Sacramento State

What is an Array?What is an Array?

• ... or think of an array as ... or think of an array as a a group of boxesgroup of boxes

• Each box belongs to the Each box belongs to the same same arrayarray

• Each box has a unique Each box has a unique locationlocation ( (indexindex))

CSc 1, Sacramento State

Example ArrayExample Array

• Name is "Project"Name is "Project"• There are 3 elementsThere are 3 elements

subscripts are subscripts are 11, , 22, and , and 33 each belongs to the same each belongs to the same

array array

1

2

Project

3

CSc 1, Sacramento State

DimDim Statement Statement

• Used to Used to dimdimensionalize a variableensionalize a variable can can also create multiple elements for an array create multiple elements for an array you will use it to create arraysyou will use it to create arrays

• Must be done Must be done beforebefore using the array using the array QBasic needs to create the array elements before QBasic needs to create the array elements before

you attempt to use themyou attempt to use them

CSc 1, Sacramento State

DIM Name (First TO Last)

Dim Dim Statement SyntaxStatement Syntax

Variable Name

First Subscript Last Subscript

CSc 1, Sacramento State

DIM Name (First TO Last) AS STRING

Dim Dim Statement SyntaxStatement Syntax

Variable Name

index Type of Data

CSc 1, Sacramento State

Array DeclarationsArray Declarations

DIM a(1 TO 3)1

2

a

3

Array Name

Array Index

CSc 1, Sacramento State

Array declaration for CSCMailBoxesArray declaration for CSCMailBoxes

DIM CSCMB(1 TO 5, 1 TO 4)

Array Name

Array Index

CSc 1, Sacramento State

Array declaration for stack of boxes Array declaration for stack of boxes

DIM Boxes(1 TO 5)

Array Name

Array Index

CSc 1, Sacramento State

Name (subscript)

How You Access an Array How You Access an Array ElementElement

Variable Name

The "box" number

CSc 1, Sacramento State

CSCMB(2,3)

How You Access a Mailbox in How You Access a Mailbox in CSCMBCSCMB

Array Name

The “mailbox" number

CSc 1, Sacramento State

Boxes(4)

How You Access a Box in DollyHow You Access a Box in Dolly

Array Name

The “box" number

CSc 1, Sacramento State

SacState

Total_Cost

Test(4)

Name(2)

Example VariablesExample Variables

Normal variables

Array variables

CSc 1, Sacramento State

DIM Test(1 TO 2)

LET Test(1) = 75

LET Test(2) = 95

PRINT Test(1); Test(2)

Array ExampleArray Example

CSc 1, Sacramento State

Array Example – Array Example – What Happens?What Happens?

DIM Test(1 TO 2)

Test(1) = 75

Test(2) = 95

1

2

Test

CSc 1, Sacramento State

1

2

Test

75

Array Example – Array Example – What Happens?What Happens?

DIM Test(1 TO 2)

Test(1) = 75

Test(2) = 95

CSc 1, Sacramento State

751

2

Test

95

Array Example – Array Example – What Happens?What Happens?

DIM Test(1 TO 2)

Test(1) = 75

Test(2) = 95

CSc 1, Sacramento State

Array Example – Array Example – What Happens?What Happens?

DIM Test(1 TO 2)

Test(1) = 75

Test(2) = 95

751

952

Test

CSc 1, Sacramento State

DIM Test(1 TO 2)

Test(1) = 75

Test(2) = 95

PRINT Test(1); Test(2)

Array ExampleArray Example

CSc 1, Sacramento State

75 95

Array Example 1Array Example 1OutputOutput

CSc 1, Sacramento State

DIM Score(1 TO 3)

FOR n = 1 TO 3

INPUT "Test: "; Score(n)

NEXT

PRINT "Second test is"; Score(2)

Array Example 2 Array Example 2

Subscript can be a variable

CSc 1, Sacramento State

Test: 74

Test: 65

Test: 49

Second test is 65

Array Example 2Array Example 2OutputOutput

CSc 1, Sacramento State

DIM Greek(1 TO 4) AS STRING

LET Greek(1) = "Tappa Kegga Bru"

LET Greek(2) = "Cuppa Kappa Chino"

LET Greek(3) = "Hu Delta Phart"

LET Greek(4) = "Eta Lotta Pi"

FOR n = 1 TO 4

PRINT n, Greek(n)

NEXT

Variable

CSc 1, Sacramento State

1 Tappa Kegga Bru

2 Cuppa Kappa Chino

3 Hu Delta Phart

4 Eta Lotta Pi

Array Example 3Array Example 3OutputOutput

CSc 1, Sacramento State

LET Score(1) = 85

LET Score(2) = 98

LET Score(3) = 61

FOR n = 1 TO 3

IF Score(n) >= 70 THEN

PRINT Score(n) ; "passes"

ELSE

PRINT Score(n) ; "fails"

END IF

NEXT

CSc 1, Sacramento State

85 passes

98 passes

61 fails

Array Example 4Array Example 4OutputOutput

QBasic LabQBasic Lab

Arrays – Arrays – Hokey Pokey Dance-a-ramaHokey Pokey Dance-a-rama

CSc 1, Sacramento State

Lab: Hokey-Pokey Lab: Hokey-Pokey Dance-a-ramaDance-a-rama

• Overview:Overview: you are involved with a dance contestyou are involved with a dance contest sadly, it is the Hokey Pokey sadly, it is the Hokey Pokey your program processes input scoresyour program processes input scores determine who qualifiesdetermine who qualifies

• Objectives:Objectives: use QBasic arraysuse QBasic arrays

CSc 1, Sacramento State

Remember ...Remember ...

• Turn your program Turn your program && your output your output to Lab12 in SacCTto Lab12 in SacCT

• You must do your own workYou must do your own work• If you do not turn in your program, If you do not turn in your program,

you will you will notnot get credit! get credit!

CSc 1, Sacramento State

Video GameVideo GameHistoryHistory

The History of FunThe History of Fun

CSc 1, Sacramento State

Tennis for TwoTennis for Two

• First computer game ever!First computer game ever!• Created in 1958Created in 1958

invented by William Higinbotham invented by William Higinbotham show visitors to the Brookhaven National Laboratoryshow visitors to the Brookhaven National Laboratory not well known publicly until 1981not well known publicly until 1981

• TechnologyTechnology used an used an analoganalog oscilloscope oscilloscope players used controllers which used transistorsplayers used controllers which used transistors

CSc 1, Sacramento State

CSc 1, Sacramento State

SpaceWar!SpaceWar!

• First digital computer gameFirst digital computer game• Finished in 1962Finished in 1962

invented by Steve Russell at MITinvented by Steve Russell at MIT space battle simulation between two shipsspace battle simulation between two ships

• TechnologyTechnology used an PDP-1 mainframeused an PDP-1 mainframe ships controlled using switches on the mainframeships controlled using switches on the mainframe

• Revolutionary new idea: Revolutionary new idea: computers can be fun!computers can be fun!

CSc 1, Sacramento State

SpaceWar!SpaceWar!

• Game playGame play ships can fire missiles, turn, thrust, and randomly ships can fire missiles, turn, thrust, and randomly

warp to a new locationwarp to a new location center screen has a star with large gravity wellcenter screen has a star with large gravity well die if hit with a missile or collide with the stardie if hit with a missile or collide with the star

• Other featuresOther features the background stars are accurate!the background stars are accurate! specialized controllers were builtspecialized controllers were built

CSc 1, Sacramento State

Spacewar!

CSc 1, Sacramento State

Magnavox OdysseyMagnavox Odyssey

• Released 1972Released 1972• First video game consoleFirst video game console• Though, it is Though, it is notnot a computer a computer

analog with some digital componentsanalog with some digital components does does notnot contain a processor contain a processor

CSc 1, Sacramento State

Magnavox OdysseyMagnavox Odyssey

• FeaturesFeatures had "overlays" for your T.V. screenhad "overlays" for your T.V. screen had a light gun had a light gun

• Used "cards" for gamesUsed "cards" for games these turned features on/offthese turned features on/off but, these were variations of the same gamebut, these were variations of the same game as a result, limited to original architectureas a result, limited to original architecture

CSc 1, Sacramento State

Controllers

Cards

CSc 1, Sacramento State

CSc 1, Sacramento State

PongPong

• Created in 1972Created in 1972• Based on ping-pong (table tennis)Based on ping-pong (table tennis)• First used in a tavern in Sunnyvale, CAFirst used in a tavern in Sunnyvale, CA

next day, there was a line to play the gamenext day, there was a line to play the game the game had broken the night before – too the game had broken the night before – too

many quarters jammed the machine!many quarters jammed the machine!

CSc 1, Sacramento State

CSc 1, Sacramento State

CSc 1, Sacramento State

PongPong

• Runaway successRunaway success new form of entertainmentnew form of entertainment T.V. versions sold incredibly wellT.V. versions sold incredibly well beginning of the arcade game erabeginning of the arcade game era

• Hundreds of "pong" games appearedHundreds of "pong" games appeared

CSc 1, Sacramento State

CSc 1, Sacramento State

CSc 1, Sacramento State

CSc 1, Sacramento State

Pac-ManPac-Man

• Released in 1980Released in 1980• Originally called "Puck-Man"Originally called "Puck-Man"

name change to avoid obvious vandalismname change to avoid obvious vandalism still called by its original name in Japanstill called by its original name in Japan

• FeaturesFeatures had vibrant colors – quite new thenhad vibrant colors – quite new then it was something different than pong!it was something different than pong!

CSc 1, Sacramento State

Pac-ManPac-Man

• Huge Huge culturalcultural hit hit music, cartoons, furniture, clothing, food, etc...music, cartoons, furniture, clothing, food, etc... the phenomena was called the phenomena was called PacmaniaPacmania video games were now part of U.S. culturevideo games were now part of U.S. culture

• Result:Result: game consoles sales jumpedgame consoles sales jumped tons of video games were createdtons of video games were created

CSc 1, Sacramento State

Pac-Man

CSc 1, Sacramento State

CSc 1, Sacramento State

Atari 2600Atari 2600

• Released in 1977Released in 1977• Designed to be a Designed to be a universaluniversal game system game system

over 100 million spent in development!over 100 million spent in development! used the 6502 microprocessor from MOS technologyused the 6502 microprocessor from MOS technology games were put on cartridgesgames were put on cartridges several input devices – joystick, paddleseveral input devices – joystick, paddle

CSc 1, Sacramento State

Atari 2600Atari 2600

• FeaturesFeatures 128 bytes of RAM 128 bytes of RAM no video memory - too expensiveno video memory - too expensive

• Huge successHuge success over 900 games createdover 900 games created produced until 1992 – produced until 1992 – 15 years!15 years! "Atari" became synonymous with games"Atari" became synonymous with games

CSc 1, Sacramento State

CSc 1, Sacramento State

CombatCombat

CSc 1, Sacramento State

Pac-ManPac-Man

CSc 1, Sacramento State

Break-OutBreak-Out

CSc 1, Sacramento State

FreewayFreeway

CSc 1, Sacramento State

River RaidRiver Raid

CSc 1, Sacramento State

AtlantisAtlantis

CSc 1, Sacramento State

Windows vs. Windows vs. MacintoshMacintosh

A Tale of Two Operating SystemsA Tale of Two Operating Systems

CSc 1, Sacramento State

The Apple CoupThe Apple Coup

• Power struggle within ApplePower struggle within Apple Jobs was known as hot-tempered and erraticJobs was known as hot-tempered and erratic executives strip Jobs of all powerexecutives strip Jobs of all power same time the Macintosh is releasedsame time the Macintosh is released

• Jobs forced out of AppleJobs forced out of Apple he founds NeXT computershe founds NeXT computers Apple is now without its major visionaryApple is now without its major visionary

CSc 1, Sacramento State

The 1990’s and The 1990’s and the Decline of Applethe Decline of Apple

• AppleApple continued to create better Macscontinued to create better Macs but, continued to lose market sharebut, continued to lose market share

• MicrosoftMicrosoft continued to enhance the PC's OScontinued to enhance the PC's OS developing better version of Windowsdeveloping better version of Windows released released Windows 95Windows 95 in in 19951995

CSc 1, Sacramento State

Rebirth of AppleRebirth of Apple

• Steve Jobs returned to Apple in Steve Jobs returned to Apple in 19971997 began work on saving the companybegan work on saving the company stopped doomed projectsstopped doomed projects

• Apple develops the Apple develops the iMaciMac embraces the USB portembraces the USB port embraces the PC hard driveembraces the PC hard drive

CSc 1, Sacramento State

Doomed Project:Doomed Project:Apple eMateApple eMate

• Laptop designed for kidsLaptop designed for kids• It was basically a PDAIt was basically a PDA

black and white displayblack and white display used a penused a pen used handheld softwareused handheld software … … but had a full keyboardbut had a full keyboard

• Cost Cost $$599599

CSc 1, Sacramento State

A Shift in AppleA Shift in Apple

• The The Intel MacintoshIntel Macintosh this Macintosh uses the Intel processorthis Macintosh uses the Intel processor prior Macs used the PowerPCprior Macs used the PowerPC it is, basically, a "PC-compatible"it is, basically, a "PC-compatible"

• You You cancan now run Windows on it now run Windows on it

CSc 1, Sacramento State

The Future of AppleThe Future of Apple

• What Apple offers now What Apple offers now iPadiPad iPhoneiPhone iPod iPod iMaciMac MacBookMacBook Mac ProMac Pro iTunesiTunes

• You You cancan count on innovation from count on innovation from Apple Apple

CSc 1, Sacramento State

Modern TimesModern Times

Computer HistoryComputer History

CSc 1, Sacramento State

Measuring Platform Measuring Platform PopularityPopularity

• Market ShareMarket Share number of computers sold each yearnumber of computers sold each year measures the popularity at a momentmeasures the popularity at a moment

• Installed BaseInstalled Base number of computers in usenumber of computers in use difficult to measuredifficult to measure

CSc 1, Sacramento State

Measuring Platform Measuring Platform PopularityPopularity

• Internet Market ShareInternet Market Share measures the computers on the Internetmeasures the computers on the Internet assumes that all computer users use the assumes that all computer users use the

Internet about the sameInternet about the same gives a gives a somewhatsomewhat accurate picture of the accurate picture of the

Installed BaseInstalled Base

CSc 1, Sacramento State

Internet Market ShareInternet Market ShareMarch 2009 March 2009

4.0%4.0%2.2%2.2%LinuxLinux

5.9%5.9%1.8%1.8%MacintoshMacintosh

89.7%89.7%93.2%93.2%WindowsWindows

March '08March '08March '03March '03

OtherOther 2.8%2.8% 0.4%0.4%

CSc 1, Sacramento State

CSc 1, Sacramento State

Internet Market ShareInternet Market ShareMarch 2011 March 2011

5.1%5.1%4.0%4.0%LinuxLinux

8.0%8.0%5.9%5.9%MacintoshMacintosh

85.8%85.8%89.7%89.7%WindowsWindows

March ‘11March ‘11March '08March '08

OtherOther 0.4%0.4% 1.1%1.1%

Platform Market Share Platform Market Share March 2011 March 2011

http://www.w3schools.com/browsers/browsers_os.asphttp://www.w3schools.com/browsers/browsers_os.asp

CSc 1, Sacramento State

Platform Wars:Platform Wars:UNIX vs. WindowsUNIX vs. Windows

• Windows family Windows family • UNIX familyUNIX family

Redhat LinuxRedhat Linux Mac-OS XMac-OS X etc ....etc ....

top related