Transcript Lecture1

Fundamentals of
Computer Science I
Lecture 1
1
This Lecture…

Chapter 1: Introduction to computer
science





Computer components
Computer hardware
Computer software
Programming languages
Software development method
2
Figure 1.2
Computer components
3
Computer Hardware
Secondary Mem: Stores data
and programs (hard/floppy disk, CD)
Modem: for network connections
Main Mem: Stores information
processed by CPU,
e.g., operating system,
applications
Input Devices: Supply information to
computers
CPU: Making decisions
Performing computations
Delegating input/output requests
Output Devices:
Allow people to
receive information
from computers
4
Computer Software

Operating system


E.g. Windows®, Unix®
Controls the interaction of system with the user


Receiving user commands, collecting input,
conveying output
Managing allocation of memory, processor
time, file system, and other resources

Controls hardware interactions
5
Computer Software (Continue)

Applications Software


Does the “real” work
Common application software





Word processors
Desktop publishing programs
Spreadsheets
Presentation managers
Drawing programs
6
Programming Languages

Machine Language




Most fundamental language of the computer
Unique for each processor type
Binary 0s and 1s that specify what to do
Assembly language


Computer operations represented by
mnemonic codes
Variables have names instead of binary
memory address
7
Table 1.2
A Program in Machine and Assembly Language
8
High - Level Languages

Resemble human language

C++, C, Pascal, FORTRAN, Ada
a = a + b;


More compact and human understandable
than machine language
Must be translated into machine language
9
Processing a High-Level Language
Program


Set of programs used to develop software
A key component is a translator


Examples


Compiler
g++, Borland C++®, Microsoft Visual C++®
Other programs needed



Editor
Linker
Loader
10
Processing a Program

Editor used to enter the program




Compiler translates the source program




Like minimal word processor
Creates source program file
Such as “emacs peas1.cpp”
Displays syntax errors
Creates (usually) temporary object code file
Such as “g++ -Wall -ansi -pedantic -o peas1 peas1.cpp”
Linker/Loader to combine object file with other
object files and execute program

Such as “./peas1”
11
Executing a Program

CPU



Special instructions used to



examines each program instruction in memory
sends out command signals required to carry
out the instruction
input data into memory for the program to use
output data to display or printer (or other
device)
Creates final executable program
12
Software Development Method


Problem solving activity
Phases:





Problem analysis
Design
Implementation
Testing
Maintenance
13
Software Development Method

Problem Analysis




Identify data objects
Determine Input / Output data
Constraints on the problem
Design



Decompose into smaller problems
Top-down design (divide and conquer)
Develop Algorithm (Desk check)

Algorithm refinement
14
Software Development Method

Implementation


Testing



Converting the algorithm into programming
language
Verify the program meets requirements
System and Unit test
Maintenance

All programs undergo change over time
15
Applying the Software Development
Method

Case Study: Converting Miles to
Kilometers

Problem Your summer surveying job requires
you to study some maps that give distances in
kilometers and some that use miles. You and
your coworkers prefer to deal in metric
measurements. Write a program that performs
the necessary conversion.
16
Case Study

Analysis The first step in solving this problem is
to determine what you are asked to do. You
must convert from one system of measurement to
another, but are you supposed to convert from
kilometers to miles, or vice versa? The problem
states that you prefer to deal in metric
measurements, so you must convert distance
measurements in miles to kilometers.
17
Data Requirements



Problem Input
miles
distance in miles
Problem Output
kms
the distance in kilometers
Relevant Formula
1 mile = 1.609 kilometers
18
Design


Formulate the algorithm that solves the
problem.
Algorithm
1. Get the distance in miles.
2. Convert the distance to kilometers.
3. Display the distance in kilometers.

Algorithm Refinement
2.1 The distance in kilometers is 1.609 the
distance in miles

Desk check!
19
Implementation
#include <iostream>
using namespace std;
int main( )
{
const float KM_PER_MILE = 1.609;
float miles, kms;
cout << “Enter the distance in miles: “;
cin >> miles;
kms = KM_PER_MILE * miles;
cout << “The distance in kilometers is “ << kms << endl;
return 0;
}
20
Testing


Test with input data for which you can easily
determine the expected results
E.g.
10 miles should convert to 16.09 kilometers
21
Object Oriented Programming


C++ derived from C by Bjarne Stroustrup
Popular because of reuse




Classes
Objects
Methods
Organized in a Hierarchy


Super Classes
Sub Classes
22
23
Object Oriented Design

Abstraction


Extract the relevant properties of an object
while ignoring inessential details
Encapsulation

Breaking down an object into parts, hiding and
protecting its essential information, and
supplying an interface to modify the
information in a controlled and useful manner
24