Fundamentals of a Program
Basics
- Computers are very dumb machines
- they only do what they are told to do
- The basic operations of a computer will form what is know as the computer’s instruction set
- To solve a problem using a computer, you must
provide a solution to the problem by sending instructions to the instruction
set
- a computer program sends the instructions necessary to solve a specific problem
- The approach or method that is used to solve the
problem is known as an algorithm
- So, if we were to create a program that tests if
a number is odd or even
- The statements that solve the problem becomes the program
- The method that is used to test if the number is even or odd is the algorithm
- So, if we were to create a program that tests if
a number is odd or even
- To write a program, you need to write the
instructions necessary to implement the algorithm
- these instructions would be expressed in the statements of a particular computer language, such as Java, C++, Objective-C, or C
Terminology
- CPU (central processing unit)
- does most of the computing work
- Instructions are executed here
- RAM (random access memory)
- Stores the data of a program while it is running
- hard drive (permanent storage)
- Stores files that contain program source code, even while the computer is turned off
- Operating System
- developed to help make it more convenient to use computers
- a program that controls the entire operation of
a computer
- All input and output
- manage the computer’s resources and handles the execution of programs
- Windows, Unix, Android, etc.
- fetch / Execute Cycle (life of a CPU)
- fetches an instruction from memory (using registers) and executes it (loop)
- A gigahertz CPU can do this about a billion times a second

Higher level programming languages
- High-level programming languages make it easier
to write programs
- Opposite of assembly language
- C is a higher level programming language that describe actions in a more abstract form
- the instructions (statements) of a program look more like problem solving steps
- do not have to worry about the precise steps a
particular CPU would have to take to accomplish a particular task
- total = x + vs. mv as, 5, mv cx 4, etc……
- Compilers
- a program that translates the high-level language source code into the detailed set of machine language instructions the computer requires
- the program does the high-level thinking and the compiler generates the tedious instructions to the CPU
- Compilers will also check that your program has
valid syntax for the programming language that you are compiling
- finds errors and it reports them to you and doesn’t produce an executable until you fix them
- high-level languages are easier to learn and much easier to program in than are machine languages
Writing a program
- the act of writing a C program can be broken down into multiple steps

Steps in writing a program
- Define the program objectives
- Understand the requirements of the program
- Get a clear idea of what you want the program to accomplish
- Design
- Decide how the program will meet the above requirements
- What should the user interface be like?
- How should the program be organized?
- Write the code
- Start implementation, translate the design in the syntax of C
- you need to use a text editor to create what is called a source code file
- Compile
- translate the source code into machine code (executable code)
- consists of detailed instructions to the CPU expressed in a numeric code
- Run the program
- the executable file is a program you can run
- Test and Debug
- Just because a program is running, does not mean it works as intended
- Need to test, to see that your program does what
it is supposed to do (may find bugs)
- Debugging is the process of finding and fixing program errors
- Making mistakes is a natural part of learning
- Maintain and modify the program
- programs are released and used by many people
- have to continue to fix new bugs or add new features
- Many new programmers ignore steps 1 and 2 and go
directly to writing code
- A big mistake for larger programs, may be ok for very simple programs
- the larger and more complex the program is, the more planning it requires
- should develop the habit of planning before coding
- Also, while you are coding, you always want to work in small steps and constantly test (divide and conquer)