Program, Hardware, CPU - Introduction to Computer Science | CS 1400, Study notes of Computer Science

Material Type: Notes; Professor: Duhadway; Class: Introduction to Computer Science--CS 1; Subject: Computer Science; University: Utah State University; Term: Summer 2009;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-gl1
koofers-user-gl1 🇺🇸

10 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
6/8/2009
1
cs1400
Introduction to
Computer Science
Chapter 1
Computers and
Programming
Why Program?
The ultimate multi-purpose tool
Hardware
Hardware – the stuff you can touch
“The easiest way to tell the difference between
hardware and software is to kick it. If it hurts
your toe, it’s hardware.”
Anonymous
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Program, Hardware, CPU - Introduction to Computer Science | CS 1400 and more Study notes Computer Science in PDF only on Docsity!

cs

Introduction to

Computer Science

Chapter 1

Computers and

Programming

Why Program?

 The ultimate multi-purpose tool

Hardware

Hardware – the stuff you can touch

“The easiest way to tell the difference between

hardware and software is to kick it. If it hurts

your toe, it’s hardware.”

Anonymous

The CPU

CPU – Central Processing Unit

 The "brains" of the computer

 Responsible for controlling its inner workings

CPU

 made of circuitry – electronic components wired together to

control the flow of electrical signals

 the circuitry is embedded in a small silicon chip, 1-2 inches

square

 despite its small size, the CPU is the most complex part of a

computer

(CPU circuitry can have 100's of millions of individual components)

CPU

 Control Unit

 Arithmetic Logic Unit (ALU)

 Registers

CPU Organization

Main Memory

 Addresses – Each byte in memory is identified

by a unique number known as an address.

 The number 149 is stored in the byte with the

address 16, and the number 72 is stored at

address 23.

60 Bytes

2975482 W e l c

o m e t o C

S \0 $ % 0

G O O D B Y E!

Secondary Storage

 Non-volatile

 Comes in a variety of media:

 magnetic: floppy disk, hard drive

 optical: CD-ROM, DVD

 Flash drives, connected to the USB port

 Slower

 Less expensive

Input Devices

 Devices that send information to the

computer from the outside world

 Keyboard

 Mouse

 Scanner

 Digital camera

 Microphone

Output Devices

 Output is information sent from a computer

program to the outside world

 Monitor

 Printer

 Speakers

Input/output devices

??

?

?

Input/Output Devices

 Translate between computer representation

and real world representation

Software

The instructions that make it all work

Software

 software refers to the programs that execute

on the hardware

 a software program is a sequence of

instructions for the computer (more

specifically, for the CPU) to carry out in order

to complete some task

The OS

 manages the CPU time

 multitasking

 organizes the I/O devices

 manages memory

 files

 directory

Programs and

Programming Languages

 Types of languages:

 Low-level: used for

communication with computer

hardware directly.

 High-level: closer to human

language

Machine Language

Assembly Language

Hardware

Machine Language

High-Level

Programming Language

Algorithm

From human to computer

 We can use the computer to do much of the

translation

 We think in algorithms

 We translate to a high-level programming

language – Source Code

 Software can translate from high-level

programming language to machine language

  • Executable Code

Algorithm – Simple Definition

 a set of step-by-step instructions to

accomplish a task

Algorithm Algorithm

1. Print "How many hours did you work?"

2. Get hoursWorked

3. Print "How much do you get paid per hour?"

4. Get payRate

5. compute wages: wages = hoursWorked*payRate

6. Print "You have earned $", wages

Some Well-Known Programming

Languages

BASIC

FORTRAN

COBOL

C

C++

C#

Java

JavaScript

Python

Ruby

Visual Basic
Preprocessor
Source Code
Modified
Source Code
Object Code
Executable Code
Compiler
Linker

Integrated Development

Environments (IDEs)

 An integrated development environment, or

IDE, combine all the tools needed to write,

compile, and debug a program into a single

software application.

 plain text editor

 compiler

 debugger

 syntax highlighting

 etc.

Integrated Development

Environments (IDEs)

Key Words

// This program calculates the user's pay. #include using namespace std;

int main() { double hoursWorked, payRate, grossPay;

// Get the number of hours worked. cout << "How many hours did you work? "; cin >> hoursWorked;

// Get the hourly pay rate. cout << "How much do you get paid per hour? "; cin >> payRate;

// Calculate the pay. grossPay = hoursWorked * payRate;

// Display the pay. cout << "You have earned $" << grossPay << endl; return 0; }

Programmer-Defined Identifiers

 Names made up by the programmer

 Not part of the C++ language

 Used to represent various things: variables

(memory locations), functions, etc.

 In Program 1-1: hoursWorked, payRate,

and grossPay.

Programmer-Defined Identifiers

// This program calculates the user's pay. #include using namespace std;

int main() { double hoursWorked, payRate, grossPay;

// Get the number of hours worked. cout << "How many hours did you work? "; cin >> hoursWorked;

// Get the hourly pay rate. cout << "How much do you get paid per hour? "; cin >> payRate;

// Calculate the pay. grossPay = hoursWorked * payRate;

// Display the pay. cout << "You have earned $" << grossPay << endl; return 0; }

Operators

 Used to perform operations on data

 Many types of operators:

 Arithmetic - ex: +,-,*,/

 Assignment – ex: =

 Some operators in Program1-1:

Operators

// This program calculates the user's pay. #include using namespace std;

int main() { double hoursWorked, payRate, grossPay;

// Get the number of hours worked. cout << "How many hours did you work? "; cin >> hoursWorked;

// Get the hourly pay rate. cout << "How much do you get paid per hour? "; cin >> payRate;

// Calculate the pay. grossPay = hoursWorked * payRate;

// Display the pay. cout << "You have earned $" << grossPay << endl; return 0; }

Punctuation

 Characters that mark the end of a statement,

or that separate items in a list

 In Program 1-1: , and ;

Punctuation

// This program calculates the user's pay. #include using namespace std;

int main() { double hoursWorked, payRate, grossPay;

// Get the number of hours worked. cout << "How many hours did you work? "; cin >> hoursWorked;

// Get the hourly pay rate. cout << "How much do you get paid per hour? "; cin >> payRate;

// Calculate the pay. grossPay = hoursWorked * payRate;

// Display the pay. cout << "You have earned $" << grossPay << endl; return 0; }

IDE text highlighting

// This program calculates the user's pay. #include using namespace std;

int main() { double hoursWorked, payRate, grossPay;

// Get the number of hours worked. cout << "How many hours did you work? "; cin >> hoursWorked;

// Get the hourly pay rate. cout << "How much do you get paid per hour? "; cin >> payRate;

// Calculate the pay. grossPay = hoursWorked * payRate;

// Display the pay. cout << "You have earned $" << grossPay << endl; return 0; }

Syntax

 The rules of grammar that must be followed

when writing a program

 Controls the use of key words, operators,

programmer-defined symbols, and

punctuation

Variables

 A variable is a named storage location in the

computer’s memory for holding a piece of

data.

length width

Variables

 In Program 1-1 we used three variables:

 The hoursWorked variable was used to hold the

hours worked

 The payRate variable was used to hold the pay

rate

 The grossPay variable was used to hold the

gross pay

Variable Definitions

 To create a variable in a program you must write

a variable definition (also called a variable

declaration)

 Here is the statement from Program 1-1 that

defines the variables:

double hoursWorked, payRate, grossPay;