0% found this document useful (0 votes)
91 views18 pages

Fundamentals of C

This document discusses the fundamentals of computer languages and program development. It begins by explaining how machine language works at the lowest level using binary codes, and how assembly language and high-level languages make programming easier for humans. It then describes the six key steps to program development: 1) analyzing the problem, 2) developing an algorithm, 3) documenting the program, 4) writing the code, 5) running the program, and 6) testing the results. Following these steps helps ensure good programming habits and the creation of effective programs.

Uploaded by

Julius Dolloso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views18 pages

Fundamentals of C

This document discusses the fundamentals of computer languages and program development. It begins by explaining how machine language works at the lowest level using binary codes, and how assembly language and high-level languages make programming easier for humans. It then describes the six key steps to program development: 1) analyzing the problem, 2) developing an algorithm, 3) documenting the program, 4) writing the code, 5) running the program, and 6) testing the results. Following these steps helps ensure good programming habits and the creation of effective programs.

Uploaded by

Julius Dolloso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

FUNDAMENTALS OF C++

What is a computer language?


All data transmission, manipulation, storage, and retrieval is
done by the machine using electrical pulses representing
sequences of binary digits. If eight-digit binary codes are
used, there are 256 numbered instructions from 00000000
to 11111111. Instruction for adding two numbers would
consist of a sequence of these eight-digit codes.

Computer Languages
Instruction written in this form are referred to machine
language. It is possible to write an entire program in
machine language. However, this is very time consuming
and difficult for computer programmers to read and
understand.
Therefore, the next level of computer language allows
words and symbols to be used in an unsophisticated
manner to accomplish simple task.

Cont. Computer Languages


For example, the machine code for adding two integers
might be.

010000110011101000111101010000010010101101000010

This is replaced by

LOAD A
ADD B
STORE C

This causes the number A to be added to the number B, and the


result is stored for the later used in C.

Cont. Computer Languages


This computer language is an assembly language, which
is generally referred to as a low-level language. What
actually happen is that words and symbols are translated
into appropriate binary digits and the machine uses the
translated form.
Although assembly language is an improvement on
machine language for readability and program
development, it is still a bit cumbersome. Consequently,
many high-level languages have been developed; these
include Pascal, PL/I, FORTRAN, BASIC, COBOL, C, Ada,
Modula-2, Logo, Java, C++ and others.

Cont. Computer Languages


These languages simplify even further the terminology and
symbolism necessary for directing the machine to perform
various manipulation of data. For example, in these
languages, the task of adding two integers would be written as

C:=A + B; (Pascal, Modula-2, Ada)


C=A + B ; (PL/I, C++)
C=A + B (FORTRAN, BASIC)
ADD A, B GIVING C (COBOL)
MAKE C :A + :B (Logo)

A high-level language makes it easier to read, write and


understand a program.

Cont. Computer Languages


Lets consider how an instruction such as

C =A + B ;

get translated into a machine code. The actual bit patterns for this code
varies according to the machine and software version, but it could be
previously indicated. For the translation to happen, a special program
called compiler reads the high-level instructions and translates them
into machine code. This compiled version id then run using some
appropriate data and the results are presented through some form of
output device. The special programs that activate the compiler, run the
machine code version, and cause output to be printed are examples of
system programs(software)

Cont. Computer Languages


The written program is a source program (also referred to as source code)
and the machine-code version generated by the compiler is an object
program(also referred to object code).
The compiler does more than just translate instruction into machine code. It
also detects certain errors in your source program and prints appropriate
messages. For example, if you write the instruction

C = (A + B;

In which parenthesis is missing, when the compiler attempts to translate


this line into machine code, it will detect that ) is needed to close the
parenthetical expression. It will then give you an error message.

Cont. Computer Languages


ERROR: ) expected

You will then need to correct the error (and


any others) and recomplete your source program
before running it with the data.

Cont. Computer Languages


Problem-Solving
Fundamentals: Data Types
and Output

Program Development Top Down Design


The key in writing a successful program is
planning. Good program do not just happen;
they are the result of careful design and
patience. A good computer programmer does not
attack a problem by immediately trying to write a
code for a program to solve the problem.

Program Development Top


Down Design
Six Steps to Good Programming Habits
In developing a program to solve a problem, six steps should be
followed: analyze the problem, develop an algorithm,
document a program, write code for the program, run the
program and test the results. These steps will help develop
good problem-solving habits and in turn solve programming
problems correctly.

Cont. Program Development Top


Down Design
Step 1 : Analyze the Problem
This is not a trivial task. Before you can do anything,
you must know exactly what it is you are to do. You must
formulate a clear and precise statement of what is to be
done. You should understand completely what data are
available and what may be assumed. You should also know
exactly what output is desired and the form it should take.
When analyzing a complex problem, it helps to divide the
problem into sub-problems whose solutions can be
developed and tested independently before they are
combined into a complete solution.

Cont. Program Development Top


Down Design
Step 2: Develop an Algorithm
An algorithm is a finite sequence of effective
statements that, when applied to the problem, will solve it.
An effective statement is clear, unambiguous instruction
that can be carried out. Each algorithm you develop should
have a specific beginning. By the completion of one step,
the next step should be uniquely determined. And it should
have an ending that is reached in reasonable amount of
time.

Cont. Program Development Top


Down Design
Step 3: Document the Program
It is very important to completely document a program. The writer knows
how the program works if others are to modify it, they must know the
logic used. Moreover users will need to know the details of how to use the
program effectively. Some documentation can come directly out of step 1
and step 2.

Step 4: Write Code for the Program


When the algorithm correctly solves the problem, you can think about
translating your algorithms into a high-level language. An effective
algorithm will significantly reduce the time you need to complete this step.

Cont. Program Development Top Down Design


Step 5: Run the Program
After writing the code, you are ready to run the program. This means
that, using an editor, you type the program code into the computer,
compile the programs and run it. At compile time, you may discover
syntax errors, which are mistakes in the way you have formed sentences
in the program. Once these errors have been corrected, you may discover
other errors at run time. Some of these mistakes may be as simple
attempts to divide by zero. Other errors, called logic errors, may be
subtler and cause the program to produce mysterious results. This may
require a reevaluation of all or part of your algorithm. The probability of
having to make some corrections or changes is quite high.

Cont. Program Development Top Down Design


Step 6: Test the Results
After your program has run, you need to be sure that the results are
correct, that they are in a form you like, and that your program produces
the correct solution in all cases. To be sure the results are correct, you
must compare them with what you expect. In the case of program that
uses arithmetic operations, this means checking some results with pencil
and paper. With complex programs, you will need to test the program
thoroughly by running it many times using data that you have carefully
selected. Often you will need to make revisions by returning to one of the
previous steps.

Cont. Program Development Top Down


Design

You might also like