Вы находитесь на странице: 1из 27

This Week ...

Computer Science
1
Week 2

QBasic Programming
Computer Concepts
Input & Output Devices
Binary Numbers
Computer Ports
Inside your computer

CSc 1, Sacramento State

Overview of QBasic

QBasic
Introduction

A simple
language

designed to teach programming


evolved over time

Eventually evolved into Visual


Basic
.NET

The Basics of QBasic

programming

one of the most sophisticated languages in use


your skills may be useful later
CSc 1, Sacramento State

How
You
Will
Program

QBasic Lite
Main
Window

QBasic programs are simply text documents.


You program by writing out instructions in a
sequence,
the computer then runs them.
After you write your program you will need to test
it.
When your program works as specified, save it as
lab1.qb, and turn in the program in SacCT.
The assignments will gradually get more
challenging.

Run

Print

Help

CSc 1, Sacramento State

CSc 1, Sacramento State

1 | Page

2 | Page

QBasic Lite
Program Output Window

Types of Data in QBasic

Numeric
Integer, floating point

Strings

Print

Used

for text

Save Output

String

order

Examples of
Numbers

5
1.5
100
3.14
1850

QBasic
Statements
A program consists
of
a
series
of statements
Statements can be
in
upper
case or lower case
in QBasic
Statements are
executed in

values are in "doublequotes"

From the first listed to the last


QBasic follows your instructions exactly
as they appear in your program

CSc 1, Sacramento State


CSc 1, Sacramento State

"Hornet"
"1850"
CSc 1, Sacramento State

CSc 1, Sacramento State

Exam
ples
of
String
s

"Sac
State

"Comp
uter
Scienc
e 1"

QBasic Statements

Each tells
QBasic to:
Input data, or

Output (display)
data, or Process
data, or
Store / Retrieve Data

CSc 1, Sacramento State

CSc 1, Sacramento State

Function
s of a
Comput
er

Print Statement

Used to output
data
to
the screen
Can be used
to
output
numbers and
text
Not to the printer

Output Data
CSc 1, Sacramento State

CSc 1,
Sacrame
nto
State

Print Statement
having one
Syntax
statement

Example 1: Program
PRINT

Starts with PRINT

PRINT Stuf

PRINT "Go

Hornets!"
Numbers and Strings
String
CSc 1, Sacramento State

CSc 1, Sacramento State

Its Output

Print Example 2

Go Hornets!
PRINT 1947
Num
ber
CSc 1, Sacramento State

CSc 1, Sacramento State

Print
Example
2 Output

Print
Statemen
t:
The
Semicolo
n

1947

Used in the Print Statement

CSc 1,
Sacramento
State

Tells QBasic to append several


items
so
that
they will be displayed right
next to each
other

CSc 1,
Sacra
mento
State

Semicolon Example

PRINT "Sac" ; "State"


PRINT
PRINT "... rocks!"
CSc 1,
Sacramento
State

Semicolon
Example
Output

SacState
No space?

... rocks!

Semicolon Example

CSc 1,
Sacra
mento
State

PRINT "Sac" ; "State"


PRINT

There

is

no

The Comma

space

PRINT "... rocks!"


CSc 1,
Sacramento
State

Used to align data


into
desirable

format

The
Print
Statement
will
display
information
in
different columns
This is quite useful for

creating
nice formatted output!
CSc 1,
Sacra
mento
State

Comma Example 1

Comma Example 1
Output
Team 1
Sac State

PRINT Team 1",Team 2"


PRINT Sac State",Idaho"

Team 2
Idaho

CSc 1,
Sacramento
State

Comma Example 2

CSc 1,
Sacra
mento
State

Comma
Example
Output

PRINT "Cherry", "Red"


PRINT "Lemon", "Yellow"
PRINT "Chocolate", "Brown"

Cherry
Lemon
Chocolate

Red
Yellow
Brown

CSc 1,
Sacramento
State

CSc 1,
Sacra
mento
State

Comma Example 3

PRINT "University:",

"Sac State"

Comma
Example
Output

PRINT "Mascot:", "Hornet"


PRINT "Colors:", "Green & Gold"
PRINT "Founded:", "1947"
CSc 1,
Sacramento
State

University: Sac State


Mascot:
Hornet
Colors:
Green &
Gold
Founded:
1947

CSc
1,
Sacr
ame
nto
State

Print
Statement
Summary

Cls Statement

Used to
clear the
screen
Any
information
on
the output
screen will
disappear

Commas:
columns
excellent for formatted
output
put items into

Semicolons:
put items next to each other
excellent for combining
information

CSc 1, Sacramento State

CSc 1, Sacramento State

Cls Statement Syntax

Cls Example

PRINT "You wont see

this."

CLS

CLS
PRINT Really?!"

Pretty simple!
CSc 1, Sacramento State

CSc 1, Sacramento State

Really?!

CSc 1,
Sacra
ment
o
State

Cls Example

Poof!
The
output before
CLS
was
cleared

(remarks) to
your program
They don't do anything
Makes programs easier to
read
They start with either REM or
a
single quote

Rem Statement

CSc 1,
Sacrame
nto
State

Used to add comments

Submit your program to:


Submit it as an attachment to Lab 1 in SacCT make
sure your saved program file has a .qb extension DUE
DATE: indicated in the lab handout

Rem Example

CSc 1, Sacramento State

REM Computer Science


1 REM Joe Gunchy
REM Lab 1
PRINT Hello, World
CSc 1,
Sacramento
State

How to create your first


program
1. Install (if necessary) and run QBasic.
2. The information box at the start is
optional.
3. Type your program into the main
window.
4. Test your program by clicking the run
button.
5. If it works, you should save it to a file.
>> make sure you are saving the program
window, not the output!

6. If it doesnt work quite right, fix it and


try again!
7. If you prefer, you can type your
program using another
editor, and load it into QBasic by
choosing open.
CSc 1,
Sacramento
State

Lab: Hello World


Objectives
get to know the QBasic Lite
application
output data using the Print
Statement

Rem Example 2
Your First Program Hello
World!

' I am a remark
'
Computer
Science 1 ' Sac
State
' Lab #1
CSc
1,
Sacr
ame
nto
State

CSc 1,
Sacra
mento
State

QBasi
c Lab

Func
tions
of a
Com
pute
r

Input
&
Output

LCD
Liquid Crystal Display
Clearer, low radiation emission, portable,
and
compact

LED

Devices

Light Emitting Diode


Efficient, color, size, long lifetime
CSc 1, Sacramento State

Bridging the Digital and


Analog World

Function
s of a
Compute
r
Analog

Digital

CSc 1,
Sacramento
State

Monitors
CRT

Cathode Ray Tube


is the classic TV screen

This

Trackball
ocess
nput Data

Pr
Data

tore Data
Data

similar to a mouse
CSc 1,
Sacra
mento
State

S
Output

Ink Jet Printers

CSc
1,
Sacr
ame
nto
State

Nozzle-like print
head
Sprays ink onto paper
to form
characters and graphics

Basic Input Devices

Most use CMYK color

Keyboard
Mouse
Touchpad
used primarily
laptops

replacement
for the mouse

Cyan-Magenta-Yellow & Black


CSc 1,
Sacra
mento
State

on

Laser Printers

Dot Matrix Printers

Use a laser to
paint
dots

Uses a grid of wires


to print

Particles fly on the

impact the paper through a


ribbon
same principle as a typewriter

laser

"Ink" is dry called dry toner

Higher quality than ink jet


More expensive to buy
Less expensive to operate
CSc 1, Sacramento State

Used rarely
nowadays
for low-quality
output
to print multipart carbon forms
CSc 1,
Sacrame
nto
State

Dot Matrix Printers

Write Head

Binary Encoding
CSc 1, Sacramento State

How do
computers
store
numbers

CSc 1, Sacramento State

The
Numeric
System we use
positional

grouping system
each position represents a power of 10

Binary numbers

What is a Number?

but

use powers of 2 rather than 10

CSc 1,
Sacrame
nto
State

Base 10 Numbers
(decimal numbers)

Binary Numbers
Example

The number 1783 is ...


is ...

The number 0110 1001

104

103
21

10000 1000
2
1
0
0

102
20

101

100

100
1
7
1

10

27

24

23

22

128 64 32 16

1000 + 700 + 80 + 3 = 1783

26

25

64 + 32 + 8 + 1 = 105

CSc 1, Sacramento State

CSc 1, Sacramento State

Binary Numbers
Example 2
The number 1100 1011 is ...
27

26

25

24

23

22

21

20

12
81

64 32 16
1
0
0

8
1

4
0

2
1

1
1

128 + 64 + 8 + 2 + 1 = 203
CSc 1, Sacramento State

data
Binary Encoding
again

How do
computers
store
other
types of

10

CSc 1, Sacramento State

Data representation
how letters,

sounds, images, etc are stored

A digital device

works with the symbolic world, say, in a computer

An analog device

How Data is
Represented

works with the physical


world the world we live
in

CSc 1,
Sacrame
nto
State

Digital Representation

Bits & Bytes

Computers
are digital

A bit is one
binary digit
Either 1 or 0
The most basic symbol used in
computers Shorthand for a bit is b

Work with 1's


and 0's
Binary system

A byte is 8
bits

Just as a standard
light ...

e.g. 0010
0100
The basic group of symbols used in
computers Shorthand for a byte is B

Switch two symbols


on and off
Dimmer not digital the
value
is
depends on the physical
universe

CSc 1,
Sacrame
nto State

CSc 1, Sacramento State

Quantities of
Bits & Bytes

Bits & Bytes

Bits

Kilobit (Kb) is 1,024 bits

Bytes

Are used to
represent
everything
Examples:

Kilobyte (KB) is 1,024 bytes


Megabyte (MB) is 1,048,576
bytes
Gigabyte (GB) is 1,073,741,824
bytes

Numbers

Letters,
punctuation, etc...
Pictures
Sounds

CSc 1,
Sacrame
nto State

CSc 1, Sacramento State

Co
m
pu

ter
Po
rts
Connecting Devices to
Your Computer
CSc 1, Sacramento State

11

Expansion Ports

s
e
n
d
s

Used to
connect a

a
n
a
l
o
g

peripheral
device
Expansion port
any
connector that
passes data
in and out of a
computer
or
peripheral
device

d
a
t
a

looks like a serial port, but 15 pin

DVI

CSc 1, Sacramento State

D
ig
it
al
V
is
u
al
In
te
rf
a
c
e

Original Ports

Serial
was
the
first
microcomputer port
been around since the
70's
slow 56 Kbps

Parallel
faster 12 Mbps
(12,000 Kbps) was
primarily
used
for
printers not used
anymore

CSc 1, Sacramento State

s
e
n
d
s
di
gi
ta
l
d
at
a

Monitor Ports

VGA
Video
Graphics Array

used with LCD monitors


CSc 1,
Sacra
mento
State

Keyboards

How Fast is a Port?

Mouse sometimes

Limitations
keyboard & mouse ports are
dedicated do not remove cables
while running

Different ports have different


speeds

CSc 1,
Sacrame
nto State

different ports use different technology


generally have become faster over time

How speed is measured


number of bits transferred over time
kilobits per second (Kbps) : 1,024
megabits per seconds (Mbps) : 1,048,576

The FireWire Port

CSc 1, Sacramento State

The PS/2 Port

Also called IEEE 1394


Created by Apple
Designed to transfer
multimedia data
Versions

Released in 1987 by IBM


Still used today

Firewire 400 400 Mbps


Firewire 800 new 800 Mbps
CSc 1,
Sacrame
nto State

12

The USB Port

USB Version 1.1

Universal Serial Bus


USB Implementers Forum

Main developers:
Apple

Computer

hundreds of companies

Hewlett-Packard

in charge of standards

Intel

plug and play

NEC

ports are interchangeable


can be "daisy chained"

Microsoft

Major Features:

Released in 1996
Speed: 12 Mbps not that

fast
CSc 1, Sacramento State

CSc 1, Sacramento State

USB Version 2.0

USB Version 2.0

Designed to be hi-speed
Developers:

Released in 2001
Speed: 480 Mbps

HewlettPackard
Intel

40 times faster than


USB 1.1 80 Mbps faster
than
FireWire!

backwards and forward


compatible!

Luc
ent

Is becoming the only port

Mic
ros
oft

CSc 1,
Sacrame
nto
State

NE
C
Philips
CSc 1, Sacramento State

Computer Port Guide

Port
Serial
/ 2 or USB
Parallel

Need It?
Now
No
No

Notes

Computer Ports
Through Time
Port

Obsolete

Keyboard

Obsolete

Mouse

Then
PS / 2
PS / 2 or Serial

PS
PS

/ 2 or USB
PS/2
VGA
DVI
FireWire
USB

Probably
Used for keyboards
VGA or DVI
Yes
Widely used for monitors
USB
Maybe
Great for digital monitors
USB
Maybe
Useful for old hardware
USB
Yes!
The more - the better
USB

Monitor

VGA

Printer

Parallel

Scanner

Parallel

Joystick

Game

Flash Drive

CSc 1, Sacramento State

CSc 1, Sacramento State

13

Didn't exist!

CSc 1, Sacramento State

14

Вам также может понравиться