Programming 1

advertisement
Programming
1
Algorithm
• A computer program is a solution to a
problem.
• An algorithm is the logical design used to
accomplish a specific objective.
–
–
–
–
–
Algorithms are well-ordered.
Algorithms have unambiguous operations.
Algorithms have effectively computable operations.
Algorithms produce a result.
Algorithms halt in a finite amount of time.
2
Syntax / Information System
• Syntax refers to the specific rules of a
programming language.
• An information system is a combination
of people and technology that collect,
organize, and process data to produce
information.
3
Information System Cont.
• An information system must do at least three
things:
– input data into the system
– process data within the system
– output resulting information from the system
4
Variable
• Memory location that can be accessed and
changed by developer code
• Can store only one piece of data at any time
• Variables have a data type
–For now they will be either for strings
or numbers
5
Rules for Naming Variables
• Name must begin with a letter.
• Name can contain only letters, numbers, and
the underscore. No punctuation characters or
spaces are allowed.
• Name cannot exceed 255 characters.
• Name cannot be a reserved word.
– public, int, private
6
Rules for Naming Variables cont.
• Should be meaningful and descriptive
representing the variable’s purpose
• Short names are bad
• Capitalize words for readability
(Pascal case)
– InterestRate
• Many programmers use a prefix to show the
variables data type
– decInterestRate
7
Input Statements
• An input statement accepts data from the user
and stores that data into a variable
• In Visual Logic a Prompt can be added to request
input by clicking on More>>
8
Simple Programming Formats
9
Assignment Statements (data into memory)
• The assignment statement can be used to
perform a calculation and store the result.
• An expression is a value-returning code
element, such as a variable or mathematical
formula.
• The expression on the right hand side is
evaluated and stored in the variable on the
left hand side.
10
How to Write
Arithmetic Expressions
• Don’t forget the rules of precedence when
writing expressions.
11
Output Statements
• Types of output include
– Screen output
– Printed output
– Sound output
– Saving to storage devices
• Your output should be appealing to the user.
Use & and multi-line when appropriate.
• Your output should provide the answer to the
problem.
12
Pseudocode/Flow Charts
•
•
•
•
•
Human readable
Not written towards one language
Well defined
Little to no syntax
Use of keywords
–
–
–
–
–
–
START
WHILE
FOR
IF
NOT
TRUE
13
Develop a solution to a problem
• Jake has a car with an 8-gallon fuel tank. Jake
fills his tank with gas and then drives 60 miles
to a friend's house. When he gets to his
friend's house, he has 6 gallons left in his fuel
tank. Write a program that uses three input
elements to enter values for tank size, miles
traveled and gallons left. The program should
calculate and display how many miles Jake can
drive on a full tank of gas.
14
Jakes Problem
• Identify the Inputs, processing and outputs.
– Inputs (variables)
– Processing (assignment statements)
– Output (provide answer)
15
Intrinsic Functions
• Intrinsic functions are predefined commands
that provide developers with common, helpful
functionality.
• A function takes one or more
arguments/parameters.
• A function returns a result which can be
assigned to a variable, output, or used in an
expression.
16
Intrinsic Functions (cont.)
Length(strVariable)
The number of characters in the string.
17
Download