computer programs
Download
Report
Transcript computer programs
What is Computer Science?
• What it is not
– Game Play or Game Development
– Animated Film Making
– Web Site Development
• Definition
– Computer science is the study and application of ways
to represent problems in such a manner to make those
problems amenable to being solved partially or
completely with computer programs (i.e., software).
Algorithms + Data Structures = Computer Programming. Donald Knuth
What is Computer Science?
• What do computer scientists do?
– Development
• Programming or web development in a multitude of industries:
business, retail, communications, entertainment, government, or
defense.
– Operations and Maintenance
• Installing, configuring, monitoring or repairing computer equipment
• Customer service
– Networks and Security
• Installing, configuring, monitoring or repairing computer networks
• Network security: network protection, intrusion detection.
– Management
• Supervision of developers, operations, or networks
– Teaching and/or Research
CS Fundamentals
Computer science is the study and application of ways to represent problems in such a
manner to make those problems amenable to being solved partially or completely with
computer programs (i.e., software).
•
“Represent Problems”: The “stuff” on which you make decisions needs to be
encoded in a manner which the computer can understand.
– Information Representation
– Data Structures
– Data Design
•
“Computer Programs”: The instructions which the computer follows to
accomplish the task at hand.
– Software
– Programs
– Algorithms
So then, fundamentally, we need to know how to encode data (information
representation) and write instructions (algorithms).
CS Fundamentals
Information Representation
• What basic kinds of information does the world contain?
–
–
–
–
–
–
Numbers
Characters (i.e. Letters or Symbols)
Logicals
Instructions or Commands
Colors or Sounds
References (think house address or citation)
• How can we organize it?
– Arrays: a collection of the same thing
– Records (or Structures): a collection of different things
• How does the computer store the data?
– All information on the computer is stored as a number
– So a number is a number, but characters, instructions, etc. are also
numbers – so how does the computer tell the different kinds of info apart?
CS Fundamentals
Information Representation
• Data Typing: The kind (or type) of information is determined by the
programmer telling the computer (via the program) what kind of
information the number represents. (data typing example)
• Encoding 101
–
–
–
–
–
–
Logical: ‘1’ means yes and ‘0’ means no
Instruction or Command
Color or Sound (paint, paint-by-number example, digital sound)
Character or Symbol (ASCII Table)
Number (intro to binary, programming example)
Reference (think house address or citation)
• Information Representation Challenges
– Fundamental types above tend to be too simple and static
– So we need flexibility in specifying types
– Modern languages permit new type definitions for various problems
CS Fundamentals
Algorithms
•
•
Algorithm Definition: A specific, well defined procedure which has an end for
accomplishing some task
Three Algorithmic Constructs
– Sequence
– Decision (or Selection)
– Looping
•
Examples
– Rock, paper, scissors
•
Exercises
– Pass the Potatoes, Please
– Computation Exercise
•
Algorithmic Challenges
– Fundamental programming operations tend to be “mathy”
– Need flexibility for specifying new non-mathy operations
– Programming languages commonly provide capabilities for new operations
An Example of Data Typing
In the example below which computes the average of a set of test scores we
have four pieces of information:
• The number of test scores
• The actual test scores
• The sum (or total) of all the scores
• The average of the scores (i.e., the total divided by the number of scores
The word “int” or “double” (in bold) in front of the variable name indicates how
the number is to be interpreted when the program executes.
int
num
double scores[num]
double total
double average
= 3;
= {94, 96, 99};
= 0.0;
= 0.0;
total
= scores[0] + scores[1] + scores[2];
average = total / num;
Go Back
Algorithm Example
Rock, Paper, Scissors
•
•
•
•
Each player thinks of either a rock, paper or scissors
One player says, “Rock, paper, scissors, shoot!!”
Each player shows object he/she was thinking of (an R, P, or S)
If P1 is R & P2 is S OR P1 is P & P2 is R OR P1 is S & P2 is P
•
•
Player 1 wins and gloats
Otherwise
•
Player 2 wins and gloats
Think
Speak
Show Choice
P1 Wins?
N
P2 Gloats
P1 Gloats
go back
Algorithm Example (cont.)
Rock, Paper, Scissors
•
•
•
•
Each player thinks of either a rock, paper or scissors
One player says, “Rock, paper, scissors, shoot!!”
Each player shows the object he/she was thinking of (i.e., R, P, or S)
If (P1 is R & P2 is S) OR (P1 is P & P2 is R) OR (P1 is S & P2 is P)
•
•
Player 1 wins and gloats
If (P2 is R & P1 is S) OR (P2 is P & P1 is R) OR (P2 is S & P1 is P)
•
•
Player 2 wins and gloats
Otherwise
•
Play game again
Think
Speak
Show Choice
P1 Wins?
N
P2 Wins?
Y
P2 Gloats
P1 Gloats
Y
go back
Algorithm Exercise
Pass the Potato
Develop an algorithm to solve the objective below, given certain
restrictions:
•
Objective: Be the first team to move the potato from the first person
in your row to the last.
Restrictions:
•
–
–
All team players must remain in their seats, and the seats in their area,
at all times.
If you are handling the potato for the first time, then you may
1.
2.
–
If you are handling the potato the 2nd, 3rd, 4th, .... time, then you may
1.
•
Hand the potato to the person on your left or right
Toss the potato to a person in your row to the left, but not past more than
one person
Toss the potato to any person in your row
GO!!
go back
Algorithm Exercise
Computation
Exercise the following algorithm:
1.
2.
3.
4.
5.
6.
7.
Get numbers A and B from the instructor
If B equals 0, then go to step 7
Set C equal to the remainder of A / B
Set A equal to B
Set B equal to C
Repeat at step 2
Stand up and, when asked, announce the final value of A
go back