Intro to Programs and C - csns - California State University, Los

Download Report

Transcript Intro to Programs and C - csns - California State University, Los

Tarik Booker
CS 242
California State University, Los Angeles

Introduction to Programming

Performing Well in Computer Science


The Integrated Development Environment
(IDE)
Intro to C

Welcome to Programming!!!
◦ Programming – the act of writing instructions in a
way that a computer can understand
◦ Why?
 Computer can process information very quickly
 Very helpful for engineering processes
 Can make games

Both hardware and software
◦ Hardware
 Actual physical device
 Electronics
◦ Software
 Invisible Instructions
 “Electricity”

Hardware – Major components:
◦
◦
◦
◦
◦
◦

Central Processing Unit (CPU)
Memory (Main Memory)
Storage Devices
Input devices
Output devices
Communication Devices
All connected with a bus – connection
between all components
◦ Think of a highway

Central Processing Unit
◦ “Brain” of the Computer
◦ Two different internal components
 Control Unit
 Arithmetic Logic Unit (ALU)
◦ Based on semiconductor chips
 All have tiny switches (transistors)
◦ Contains a clock
 Keeps synchronization (and control)
 MHz, GHz
◦ Cores
(Hz = 1/s)
 Part that reads instructions
 Multi-core

Bit – result of one switch
◦ Switch off – 0 (zero/ low)
◦ Switch on – 1 (one / high)

How many switches do you know of?
◦ (L)
◦ What else?

Computer – many (millions/billions of) switches
◦ Digital / Analog
◦ Analog (natural) info is converted to switches (digital)

Byte – 8 bits ( 8 switches)
◦ Bit – binary digit
◦ Byte is minimum storage unit in a computer
◦ Can store a number (ex: 3) in a byte
 How?

Many things can be encoded into bytes (digitally
encoded)
◦
◦
◦
◦
◦
Numbers
Text
Audio
Video
Data (biometrical, biological)

DNA Computing
◦ Use DNA to execute
◦ instructions

Encoding Scheme
◦ Set of rules that govern how a computer translates info
into data
 Standardized
◦ Music
 MP3
 Wav
◦ Text
 ASCII
 UNICODE
◦ Im
 Jpg
 GIF
ages
◦ Many, many, many more

Memory Storage Capacity
◦ In bytes:




1
1
1
1
Kilobyte (KB) = 1,000 bytes
Megabyte (MB) = 1,000,000 bytes (million)
Gigabyte (GB) = 1,000,000,000 bytes (billion)
Terabyte (TB) = 1,000,000,000,000 bytes (trillion)
◦ Typically:
 Word doc: 20KB
 1MB = ~50p of documents
 2 Hour High-Def Movie = 8GB
 20 Movies: 160GB
◦ What are (look up)?
 1 Petabyte?
 1 Exabyte?

An ordered sequence of bytes for storing
programs and data
◦ Work area for CPU
◦ Program and data must be moved here before execution
(running the instructions)

Every byte has a (unique) address
◦ Locate the byte for storage and retrieval
◦ Can be accessed in any order




Called Random Access Memory (RAM)
Most PC’s have ~4gigabytes of RAM
Typically, the more RAM, the faster the computer
Note, memory can contain garbage
 Deletion doesn’t remove the info
 Removes address

Internal memory (RAM) is volatile!
◦ When power is removed, saved information is lost
◦ Programs should be permanently stored on the
computer
 How? (Secondary) Storage devices
 When power is removed, information stays
 Called persistent
◦ Note: Storage devices are notably slower than
(internal) memory
 Three main types
 Magnetic disk drives
 Optical Disk Drives (CD, DVD)
 USB Flash Drives

Disks
◦ Computer typically contains a hard disk drive
◦ Hard disk permanently stores programs (and data)
◦ Typically encased within computer

CD
◦ Compact Disc
◦ Two different types
 CD-R (Read only)
 CR-RW (Read-Write)
 Can be used like a
hard disk
◦ CD can hold up to
700MB
 (Second movement of
Beethoven’s Ninth
Symphony)

DVD
◦ Holds much more info
◦ 4.7 GB
◦ DVD-R, DVD-RW

USB Flash Drives
◦ Universal Serial Bus (USB)
 Allows you to “hot swap” different devices to the
computer
◦ Flash Drive
 Flash Memory
 Currently up to 256 GB

Interesting
example:
http://www.extr
emetech.com/e
xtreme/134672
-harvardcracks-dnastorage-crams700-terabytesof-data-into-asingle-gram

Lets the user communicate with the computer
◦ Most common
 Keyboard
 Mouse
 Monitor
◦ Other




Trackball
Joystick
Eye Scanner
What else?

Devices that allow computers to communicate
with other computers (or devices)
◦
◦
◦
◦
◦
Dial up modem
Digital Subscriber Line (DSL)
Cable Modem
Network Interface Card (NIC)
Wireless networking
 Bluetooth

Biometric Devices
◦ Scan information

What else can you think of?

The computer is a machine, and therefore must
communicate in a way that is preferrable to the
machine
◦ Machine Language




The computer’s “native” language
Directly in binary code (1’s and 0’s)
Typically the instruction, then the operands
Ex:
1101101010011010
◦ Assembly (Language)
 The previous alternative to machine code (language)
 Used a word (mnemonic) to describe each machine instruction
 Computer can’t execute, so must be converted to machine
language
 Uses an “assembler”
 Ex:
add 2, 3, result

High Level Language
◦ Platform independent
 Can run on different CPUs
◦ Easier to use
 Like English – easier to learn
 Instructions in this language are called statements
 Ex:
area = 5 * 5 * 3.14159;
◦ Many different types of High level Languages
 Ada, BASIC, C, C++, C#, Ruby, Pascal, Python, etc.
 C

Main program that runs on a computer
◦ Manages and controls a computer’s activities
◦ Every computer you use has an operating system
◦ Controls:
 Controlling and monitoring system activities
 Allocating and assigning system resources
 Scheduling operations
◦ Different types of Operating Systems
 Windows
 Jaguar (Mac)
 Linux

Controlling and Monitoring System Activities
◦ Performing basic tasks




Recognizing input (keyboard, mouse, etc.)
Sending output (monitor, printer, etc.)
Keeping track of files and folders on storage devices
Controlling “peripheral” devices
 Disk drives
 Printers
 Making sure programs (and users) do not interfere
with each other
 Security

Allocating and Assigning System Resources
◦ Responsible for system resources




CPU time
Memory Space
Disk allocation
I/O device allocation

Scheduling
◦ Multiprogramming
◦ Multithreading
◦ Multiprocessing
 Parallel Processing
 Oscar.calstatela.edu

Operating System (OS) does much much more!

Created by Dennis M. Richie
◦ Bell Labs
◦ 1972
◦ Started with the “B” language

IDE – Integrated Development (Desktop)
Environment
◦ All in one way to write, compile, and run programs
◦ Different IDEs for different languages
 Some work for multiple languages
 (Preferred languages)
◦ Windows
 Code::Blocks
 Good for C and C++
 Will use C in class

Download Code::Blocks
◦ Already installed on Lab Computers
 If no computer use lab

Install
◦ Comes with compiler
◦ Installs everything

Run


Once Code::Blocks is running, you should
see:
Select New -> Project


Select Console Application
Click GO

Complete the Wizard
◦ Select C
(Do NOT Select C++)


Add a title
Keep the GNU GCC Compiler
◦ Works for both C and C++

Finish

Select Sources
◦ Double Click main.c
 (My project name here, was demo)

Hit F9 to Compile and Run

Congratulations!!!!!!!
Your environment is now set up!!!!

Macintosh

◦ Use Xcode

(p14 in book)
Linux
◦ Use g++ (p27)
◦ Command line interface

See me after class for help with Mac/Linux
◦ Not guaranteed!!!

Lets look at that main.c program.