0% found this document useful (0 votes)
46 views6 pages

Chapter 1 and 2 (Programming 1)

Uploaded by

melanielampera17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
46 views6 pages

Chapter 1 and 2 (Programming 1)

Uploaded by

melanielampera17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

I.

Fundamentals of Programming

II. Overview
A. Introduction/Rationale

This instructional material covers eight chapters and is ideal for a one semester
period. It introduces computer programming in Turbo C language using basic control
structures in problem solving, logic building. It discusses the syntax of the most common
functions and technicalities of the language. Topics should cover problems involving simple
problems to problems involving files and some simple dynamic data structures.

B. Objectives

a. Familiarize one’s self with the C Programming Environment.


b. Learn the different syntax of the most common functions and technicalities of the
language.
c. Recognize the value of programming in solving problems.
d. Develop correctly written programs.

C. Learners

All BSIT and BSCS 1 Students

D. Time Frame

First Semester

E. Pre requisite skills


Basic Keyboarding skills and good in logic
Chapter 1
Introduction to Programming Concepts

Computer Program: The Power of Logic

 Computer Program – set of instructions that instruct computers what to do to solve the
problem.
 Programmer – is a person who understands how the computer solves the problem by defining
the problem requirement and developing methods on how problem solutions will be
communicated to the computer.
 Programming – an act of developing the program.

Programming Language – is a set of rules that tells the computer what operation to perform.

The Programming Cycle

1. Problem Analysis – is defined by the American National Standard Institute (ANSI) as the
“methodical investigation of a problem and the separation of the problems into smaller related
units for further detailed study.”
The following are guidelines when analyzing problems:
1. Define the problem.
2. Determine the input data.
3. Determine the required output.
4. Determine the operations involved.

2. Program Design

The second step in the program development process describes the algorithm or the set of
well-defined rules for the solution of a problem in a finite number of steps. Algorithms specify
what actions and operations of a program will be used. For example, to find the average value of
three numbers, the algorithm will be:

1. Add the three numbers.


2. Divide the sum by three (the number of elements).

There are several design tools to choose from in formulating an algorithm to name a few we
have flowcharting, decision table, pseudo-code.

3. Program Coding and Encoding

Computers do not understand flowchart. Each procedural step contained in a flowchart


symbol has to be converted in a line or lines of instructions using computer programming
languages such as Pascal or Turbo C. This process is called coding. After coding, the next
step is to enter the coded instructions through the keyboard of the computer directly into the
computer storage. This process is called encoding.

4. Program Desk Checking – means manually testing the solution design with a set of test data
and debugging such, if errors are present.
The coded program is manually reviewed for obvious errors( like grammar and spelling
errors) on syntax and logic. In this phase, the programmer plays the role of the computer,
reading the program line by line, going through each process seeing where the flaws are so
that they can be corrected.

5. Testing and Debugging

Testing – refers to the process of running a program in the computer for the purpose of
verifying the accuracy and workability of the solution.
Debugging – refers to the process of identifying, locating and correcting the error in the
solution.

Types of Errors:

1. Syntax Error – are misspelled words, incorrect symbols, omitted punctuation marks or
unmatched parentheses.

Syntax – rules on how to define instructions when coding.


2. Logical Error. A test for logic error is performed by assigning a trial set of data that
closely resembles the live data in all the aspects of the program and comparing the
output of the program against a predetermined output.

3. Run Time error, A software error that occurs while a program is being executed, as
detected by a complier or other supervisory programs. Mostly, run-time errors occur in
numeric calculations, such as dividing a number by zero (resulting to “divide error”); in
evaluating an expression that would result in an illegal data, such as assigning to an
integer type variable a value greater than 32 767 (which results to an “overflow”); or in
giving improper input, such as when a user entered a character data where an integer
value is expected.

6. Documentation can be divided into broad categories:

1. Program Documentation. This means documenting the program for later application.
Variables are to be defined and comments are made to be informative.

2. User Documentation. The second type of documentation is an explanation of a program for


the people who will use it.

Chapter 2
C Programming: An Introduction

C is a programming language designed by Dennis Ritchie in 1972 at AT & T Bell Laboratories. C was
designed as a language for systems programming, as a way to fully access the computer’s power
without becoming caught up in the tedious writing of assembly language. Although C was developed
as a systems programming language, today it is one of the standard “workhorse” programming
languages and is commonly used to develop commercial programs.

C emphasizes structured programming, the style of programming in which a program is written as a


sequence of steps to be executed one after the other. The steps may involve substeps, each of which
are written according to the same rules. Each step is a sequence of sub-substeps to be executed one
after the other. A structured program proceeds in modular fashion from gross detail to fine detail.
This approach to program design is often called top-down design.

In C, the program statements can refer to functions, subprograms, which perform, specialized tasks.
The programmer can write the main program that makes reference to various functions before the
functions are actually written, and then the programmer can fill in the required functions. This
approach to programming is called top-down design.

How to Execute a Program in C

 Enter each line of the source code into the memory, and save it on disk as source file, using
an editor, or a word-processor.
 Compile the source code. The compiler will read the entire source code and convert it to an
object code.
***Object code – is the translation of the source code of a program to machine language, which
the computer can read and execute directly. Object code is the input to the linker.
 After compiling, the compiler displays syntax errors in the monitor. Correct errors by editing
and re-saving it using editor.
 The compiler then saves its machine-language translation as an object code, when the
source program is free of syntax errors.
 The linker will combine separate complied functions together into one program. It combines
the functions in the standard C library with the code you wrote. The output of the Linker is an
executable program.
 Use the loader program to place the executable file back in the memory, ready for execution.

The C Environment

Turbo C is the most commonly used programming language and is known for its flexibility. The Turbo
C environment is shown below:

Menu Bar - can be accessed by pressing the Alt key plus the first letter of the Menu. If you want to
access the File menu, you need to press Alt + F.

All operations of Turbo C are selected from the main menu. After an operation is completed, the main menu is
redisplayed to allow you to choose another operation. The operations displayed on the main menu are:

 FILE. Load or save C source code files. This selection also allows you to display a directory, execute a
DOS command, or exit from Turbo C.
 EDIT. Start the editor. The contents of the currently specified word file are displayed.
 RUN. Run the most recently complied program. If the current file has not yet been complied, Turbo C will
automatically compile the program before it runs it.
 COMPILE. Compile the currently specified file.
 PROJECT. Allows you to make one large program from several C source-code files.
 OPTIONS. Allows you to specify technical aspects of the Turbo C compiler, linker or environment.
 DEBUG. Aids in debugging your Turbo C program.
Path and Filename indicates the filename of the current source program that is loaded on the edit
window. It also indicates the drive where it was loaded or the drive where it will be saved.

Edit Window it is where you edit the source program.

Trace Window this window is usually used to trace the value of a certain variable during program
tracing. It also serves as a message window during compiling. It displays all the error messages,
warnings and the type of error that occurred.

Status Bar indicates if the Num Lock, Caps Lock, and Scroll Lock keys are in the on or off mode.
Functions Menus pressing the function keys accesses these menus:

F1- Help
F5- Zoom
F6- Switch Window
F7- Trace Window
F8- Step
F9- Make EXE File
F10- Access the Menu Bar

Cursor Locator tells you the current location of the cursor and the line number.

General Form of C Program

preprocessor directives<header file>,constant declarations


global variable declarations;
main()
{
local variables;
statement sequence;
}
f1()
{
local variables;
statement sequence;
}
fN()
{
local variable;
statement sequence;
}

C Data Types

Before a variable name (identifier) can be used used a C program, it must be declared explicitly,
together with its corresponding data type. There are some restrictions in giving a name to a variables
and constants.

Rules for naming a variable


1. A variable name can only have letters (both uppercase and lowercase letters), digits and
underscore. Capital (uppercase) letters and small (lower case) letters are treated differently.
2. The first letter of a variable should be either a letter or an underscore.
3. There is no rule on how long a variable name (identifier) can be. However, you may run into
problems in some compilers if the variable name is longer than 31 characters.
4. Keywords or commands such as case, int, float, if, do, for, etc., cannot be used as variable or
constant names, because they are considered as a reserved words.

Note: C programming language is a case –sensitive. This means that all keywords, commands and
standard functions of C language must be written in lowercase letters.

Basic Data Types in C

Each variable in C has an associated data type. Each data type requires different amounts of memory
and has some specific operations which can be performed over it. Let us briefly describe them one by
one:

Type Format Meaning Example(s)


int %d or %i -a whole number (2,-4,6,1000)
float %f -a number with decimal point (5.8,3.89, -123.90)
char %c -a single letter, symbol, or
number enclosed within two single
quotes ‘S’, ’r’, ’*’, ’5’
char %s -a string in C is considered as a
series of characters “Ms.”, “Hi!”, “143”
“ I love”
double %f -for a bigger or larger numbers
with decimal point (1234.12, 234.5)
Variable Declaration in C Programming

In C programming, variables which are to be used later in different parts of the functions have to be
declared. Variable declaration tells the compiler two things:
 The name of the variable
 The type of data the variable will hold

A variable can store any data type in C programming. The name of the variable has nothing to do with
its type.

The general syntax of declaring a variable primarily is

 data_type var1,var2,...varn;
 Here, var1, var2,...varn are the names of valid variables.
 Variables can also be defined in multiple lines instead of on the same line.
 data_type var1;
 data_type var2;
 data_type varn;
When the variables are declared in single line, then the variables must be separated by commas.
Note: All declaration statements must end with a semi-colon(;).

For example:
 int age;
 float weight;
 char gender;

In these examples, age, weight and gender are variables which are declared as integer data type,
floating data type and character data type respectively.

You might also like