Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 1 Week 3. CSc 1, Sacramento State This Week... QBasic Programming QBasic Programming  Variables  DIM  LET Computer Concepts Computer.

Similar presentations


Presentation on theme: "Computer Science 1 Week 3. CSc 1, Sacramento State This Week... QBasic Programming QBasic Programming  Variables  DIM  LET Computer Concepts Computer."— Presentation transcript:

1 Computer Science 1 Week 3

2 CSc 1, Sacramento State This Week... QBasic Programming QBasic Programming  Variables  DIM  LET Computer Concepts Computer Concepts  Storage of numbers and strings  Inside your computer  Magnetic, solid state and optical storage devices

3 CSc 1, Sacramento State

4 QBasic Variables Using Memory for Data

5 CSc 1, Sacramento State Review of Data in QBasic Numeric Data Numeric Data  Integers  e.g. 1846 Text Data Text Data  String  e.g. “Sac State"

6 CSc 1, Sacramento State Functions of a Computer Output Data Store Data

7 CSc 1, Sacramento State Variables Are names used to store data in memory Are names used to store data in memory Found in practically all programming languages Found in practically all programming languages Specified either: Specified either:  Explicitly – declared before they are used  Implicitly – created as they are "seen"

8 CSc 1, Sacramento State Variables in QBasic There are several types in QBasic There are several types in QBasic  String variables hold strings  Integer variables hold whole numbers  Floating point variables hold real numbers You will only need to use two types in this class You will only need to use two types in this class

9 CSc 1, Sacramento State Variables in QBasic Integer and Double data types Integer and Double data types  used to store a number  they have an initial value of 0  default data type String data type String data type  used to store a piece of text  they are initially blank – empty string

10 CSc 1, Sacramento State QBasic Variable Names Naming rules Naming rules  letter followed by a series of letters, numbers, underscores, or periods  no spaces They are not case sensitive They are not case sensitive  uppercase or lowercase letters doesn't matter  e.g. Computer is the same as computer

11 CSc 1, Sacramento State SacState Test4 TotalCost Some Valid Variable Names

12 CSc 1, Sacramento State First-Name 1040Form Test 4 Some Bad Variable Names Dash – Not Valid Starts with a number A space

13 CSc 1, Sacramento State Dim Statement Used to dimensionalize a variable Used to dimensionalize a variable  creates space for a variable  this is an older term Must be done before using the variable Must be done before using the variable Dim statement defaults to a double Dim statement defaults to a double  you can manually specify it if you wish  for strings, you must declare the type

14 CSc 1, Sacramento State DIM Name AS Type Dim Statement Syntax Variable Name Optional Integer, double, string

15 CSc 1, Sacramento State DIM Age Dim Statement Example Creates a numeric variable

16 CSc 1, Sacramento State DIM User AS String Dim Statement Example 2 Creates a String

17 CSc 1, Sacramento State Let Statement Used to change the value of a variable Used to change the value of a variable Commonly known as an "assignment" statement Commonly known as an "assignment" statement Used a lot! Used a lot!

18 CSc 1, Sacramento State LET Variable = Value Let Statement Syntax Starts with LET

19 CSc 1, Sacramento State What Happens? Memory: DIM Year LET Year = 1947

20 CSc 1, Sacramento State What Happens? Memory: DIM Year LET Year = 1947 0 Year

21 CSc 1, Sacramento State 0 Year What Happens? Memory: DIM Year LET Year = 1947 1947

22 CSc 1, Sacramento State What Happens? Memory: DIM Year LET Year = 1947 1947 Year

23 CSc 1, Sacramento State What Happens? Memory: DIM Score LET Score = 98 LET Score = 81

24 CSc 1, Sacramento State 0 Score What Happens? Memory: DIM Score LET Score = 98 LET Score = 81

25 CSc 1, Sacramento State 0 Score What Happens? Memory: DIM Score LET Score = 98 LET Score = 81 98

26 CSc 1, Sacramento State 98 Score DIM Score LET Score = 98 LET Score = 81 What Happens? Memory: 81

27 CSc 1, Sacramento State What Happens? Memory: DIM Score LET Score = 98 LET Score = 81 81 Score

28 CSc 1, Sacramento State String Example Memory: DIM User AS String LET User = "Kip"

29 CSc 1, Sacramento State User DIM User AS String LET User = "Kip" String Example Memory:

30 CSc 1, Sacramento State User String Example Memory: Kip DIM User AS String LET User = "Kip"

31 CSc 1, Sacramento State What Happens? Memory: DIM User AS String LET User = "Kip" Kip User

32 CSc 1, Sacramento State DIM User AS String LET User = "Stewie" PRINT "Hello "; User DIM User AS String LET User = "Stewie" PRINT "Hello "; User Example Program Output the variable

33 CSc 1, Sacramento State Hello Stewie Example Program Output

34 CSc 1, Sacramento State DIM Title AS String LET Title = "Sac State" PRINT Title ; " rocks!" Example Program 2

35 CSc 1, Sacramento State Sac State rocks! Example Program 2 Output

36 CSc 1, Sacramento State REM How Tall Am I? DIM Feet AS INTEGER LET Feet = 6 PRINT "My Height: "; Feet Example Program 3

37 CSc 1, Sacramento State My Height: 6 Example Program 3 Output

38 CSc 1, Sacramento State REM What happens? DIM Grade PRINT Grade LET Grade = 94 REM What happens? DIM Grade PRINT Grade LET Grade = 94 Example Program 4... tricky

39 CSc 1, Sacramento State 0 Example Program 3 Output Zero? Why?

40 CSc 1, Sacramento State REM What happens? DIM Grade PRINT Grade LET Grade = 94 REM What happens? DIM Grade PRINT Grade LET Grade = 94 Example Program 4... tricky 94 hadn't been assigned yet!

41 CSc 1, Sacramento State DIM Pledge Let Pledge = "Cuppa Kappa Chino" Example Program 5 This is a numeric variable This is text!

42 CSc 1, Sacramento State Example Program 5 Output RUNTIME ERROR: Line 3 Type Mismatch Data was not the same type as the variable

43 QBasic Lab 2 Using Variables – My Major

44 CSc 1, Sacramento State Lab 2: Major Pain Objectives Objectives  use variables  assign and output data Your Program Your Program  Store your name, major, career goal, and number of semester left into variables  print the variables to the screen

45 CSc 1, Sacramento State Lab Requirements Rules Rules  you can help other students  however, you should figure this out on your own Turn your program in to: Turn your program in to:  Submit it as an attachment to Lab 2 in SacCT   make sure your saved program file has a “.qb” extension  DUE DATE = see handout.

46 CSc 1, Sacramento State

47 Character Sets How Strings are Stored

48 CSc 1, Sacramento State Numbers vs. Strings Numbers and strings are represented differently in your computer Numbers and strings are represented differently in your computer  Numbers are represented as binary values  Strings are represented with characters It is often useful to convert them It is often useful to convert them

49 CSc 1, Sacramento State Characters Represents text Represents text  Punctuation & symbols  Numerals 0 – 9  Letters Each has a value Each has a value  computers think in numbers  characters and their matching values: a character set

50 CSc 1, Sacramento State ASCII ( American Standard Code for Information Interchange ) Character Set ASCII ASCII  7 bits – 128 characters  uses a full byte, one bit is not used  created in the 1967 Extended ASCII Extended ASCII  8 bits – 256 characters – One full byte  used in 1980's computers

51 CSc 1, Sacramento State ASCII Chart NULSOLSTXETXEOTENQACKBELBSHTLFVTFFCRSOSI DLECD1DC2DC3DC4NAKSYNETBCANEMSUBESCFSGSRSUS sp !"#$%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~ DEL Control characters

52 CSc 1, Sacramento State Unicode Character Set Created to support every spoken language Created to support every spoken language Developed in Mountain View, California Developed in Mountain View, California Originally used 16 bits Originally used 16 bits  that's over 65,000 characters!  includes every character used in the World Expanded to 21 bits Expanded to 21 bits  2 million characters!  now supports every character ever created

53 CSc 1, Sacramento State The Secret of Strings M 0100 1101 o 0110 1111 e 0110 0101 LET Name = "Moe"

54 CSc 1, Sacramento State Number vs. String Representation 2 0011 0010 1 0011 0001 5 0011 0101 215"215" Three Bytes One Byte 1101 0111

55 CSc 1, Sacramento State

56 Inside Your Computer What are Computers Made Of?

57 CSc 1, Sacramento State Hardware Categories Input devices Input devices Processor Processor Output devices Output devices Storage devices Storage devices

58 CSc 1, Sacramento State Motherboard Contains: Contains:  Processor chip (CPU)  RAM - memory chips  Circuits  Chips for basic input & output  Expansion slots Connects these together Connects these together

59 CSc 1, Sacramento State Computer Chips Perform some processing Perform some processing  integrated circuits  most components inside a computer Chips are used for: Chips are used for:  Memory  Processors  etc...

60 CSc 1, Sacramento State The Processor Performs calculations & logic Performs calculations & logic  called the "Arithmetic Logic Unit"  registers hold data Controls your computer Controls your computer  called the "Control Unit"  talks to other components  talks to ports

61 CSc 1, Sacramento State The Processor Examples Examples  Intel Pentium  IBM PowerPC  MOS 6502 ... hundreds more

62 CSc 1, Sacramento State Dual Inline Memory Module Chip Computer's main memory Computer's main memory Very small circuit board containing chips Very small circuit board containing chips Plugs into your motherboard Plugs into your motherboard

63 CSc 1, Sacramento State The Data Bus Electronic pathway Electronic pathway  transports data  connects board components Think of it as a "highway" Think of it as a "highway"  data moves on shared paths  otherwise, the computer would be very complex

64 CSc 1, Sacramento State Memory Inside: Motherboard Motherboard Processor

65 CSc 1, Sacramento State Expansion Slots Allow you to add additional features to your computer Allow you to add additional features to your computer Are used for components Are used for components  that need to transmit data very quickly  should be in the system unit  but not part of the motherboard

66 CSc 1, Sacramento State Expansion Slots Expansion slot Expansion slot  long, narrow socket on the system board  normally in the back of your computer Expansion card Expansion card  small circuit board  plugs into the slot

67 CSc 1, Sacramento State Expansion card Expansion slots Inside: Expansion

68 CSc 1, Sacramento State

69 Magnetic Storage Using Magnets as Data

70 CSc 1, Sacramento State Storage Basics Storage medium Storage medium  substance that contains data  e.g. disk, tape, CD, DVD, paper Storage device Storage device  mechanical apparatus that records and / or retrieves data  e.g. disk drive, printer

71 CSc 1, Sacramento State How Magnetic Storage Works Data Representation Data Representation  Microscopic particles on the disk or tape surface store bits Data Transfer Data Transfer  Read-write head – mechanism that magnetizes the particles Magnets cause data loss! Magnets cause data loss!

72 CSc 1, Sacramento State Hard Disks Magnetic Media Magnetic Media Hard disk platter Hard disk platter  Flat, rigid disk used to store bits  There are multiple platters in each hard drive Head crash Head crash  The read-write head hits into a dust particle or other contaminant on the disk  Head crash damages some data on disk

73 CSc 1, Sacramento State Inside a Hard Disk Read-Write Head

74 CSc 1, Sacramento State Tape Storage Magnetic Media Magnetic Media Long continuous tape Long continuous tape  Sequential Access  Finding data requires seeking Inexpensive Inexpensive  Lots of storage!  Often used for backups  Primarily used in business

75 CSc 1, Sacramento State

76

77 Solid State Storage Using Chips for Data

78 CSc 1, Sacramento State Solid State Storage Data Representation Data Representation  Stores data on a low-power chip  Data non-volatile, erasable Data Transfer Data Transfer  Information is simply read from the chip  Sometimes a card reader is needed

79 CSc 1, Sacramento State Solid State Storage Advantages Advantages  Portable  Provides faster access than magnetic or optical  Versatile – used from digital cameras to computers

80 CSc 1, Sacramento State Solid State Technology Cards Cards  Compact Flash  MMC  Secure Digital  Smart Media USB Flash Drive USB Flash Drive  Plugs into any USB port  Acts like a hard drive

81 CSc 1, Sacramento State

82 Optical Storage Using Light as Data

83 CSc 1, Sacramento State Optical Storage Data Representation Data Representation  disk surface stores bits  light spots are called lands  dark spots are called pits Data Transfer Data Transfer  read using laser refraction  written by burning pits

84 CSc 1, Sacramento State Optical Storage Safer than magnetic media Safer than magnetic media  does not lose data over time  safe from magnets  resists the other elements However However  not quite as much storage  not as fast

85 CSc 1, Sacramento State CD vs. DVD CD CD  Compact Disk  holds 700 MB of data – 80 minutes DVD DVD  Digital Versatile Disk  holds about 4.7 GB of data  double layer DVD can store 8.5 GB

86 CSc 1, Sacramento State Hard Drive Removable Media Inside: Secondary Storage

87 CSc 1, Sacramento State Secondary Storage Summary Magnets Chip Pits/Runs Magnetic Storage Magnetic Storage Flash Storage Flash Storage Optical Storage Optical Storage


Download ppt "Computer Science 1 Week 3. CSc 1, Sacramento State This Week... QBasic Programming QBasic Programming  Variables  DIM  LET Computer Concepts Computer."

Similar presentations


Ads by Google