Computer Programming 1
Course Description
This course covers the use of general purpose programming language to
solve problems. The emphasis is to train students to design, implement, test, and
debug programs intended to solve computing problems using fundamental
programming constructs.
Course Learning Outcomes
By the end of this course, students are expected to:
1. Design, implement, test, and debug a program, based on a given
specification, that uses each of the following fundamental programming
components: (1) primitive data types, (2) basic computation, (3) simple
I/O, (4) conditional and iterative structures, and (5) definition of
functions and parameter passing, and (6) recursion;
2. Analyze and simulate results of algorithms that may be implemented as a
solution to a given problem.
Module 1| Chapter 1: Introduction to Computer Programming 1
Course Outline Module Assessment
Contents Time Frame
Number Period
Module Assessment Chapter 5: Loop Control Structures
Contents Time Frame Lesson 1: Loops
Number Period
Oct. 11-Nov.
Chapter 1: Introduction to Computer Module 3 Lesson 2: while Loops Semi-Final
5, 2021
Programming Lesson 3: do while Loops
Lesson 1: Overview Lesson 4: for Loops
Lesson 2: Basics Semi-Final Examination: November 8-9, 2021
Lesson 3: Environment Chapter 6: Functions
Chapter 2: Overview of C Language Lesson 1: Functions
Lesson 1: Introduction Lesson 2: Function Arguments Nov. 15-
Lesson 2: Limitation of C Module 4 Lesson 3: Library Functions Final Dec. 17,
Programming Language Lesson 4: Variable Scope 2021
Lesson 3: History of C Lesson 5: Recursion
Programming Language Lesson 6: Storage Classes
Lesson 4: Installation Final Examination: December 20-22, 2021
Chapter 3: C Language Fundamentals Aug. 9-Sept.
Module 1 Prelim
Lesson 1: Tokens 3, 2021 Grading System
Lesson 2: Identifiers
Lesson 3: Keywords The grading system is as follows:
Lesson 4: Constants
Lesson 5: Operators Assessment Period Self-Assessments/Activities Major Exams Total
Lesson 6: Data Types
Lesson 7: Variables
Prelim & Midterm 60% 40% 100%
Lesson 8: Type Casting
Module 1 50 points
Chapter 4: Data Input and Output
Module 2 50 points
Lesson 1: Program Structure
Lesson 2: Input and Output
(I/O) Semi-Final & Final 60% 40% 100%
Lesson 3: Format Specifiers Module 3 50 points
Prelim Examination: September 6-8, 2021 Module 4 50 points
Chapter 4: Decision Control
Structures (Midterm Grade + Final Grade) / 2 = Final Rating
Lesson 1: Decision Making
Lesson 2: if Statements
Lesson 3: if-else statements Sept. 13-
Module 2 Midterm
Lesson 4: Nested if-else Oct. 4, 2021
Statements
Lesson 5: else-if Statements
Lesson 6: goto Statement
Lesson 7: switch Statements
Midterm Examination: October 7-9, 2021
Module 1| Chapter 1: Introduction to Computer Programming 2
How Do You Use This Module? Table of Contents
This module is written in a very user-friendly manner. Definitions, Title Page
processes and samples are included as an input knowledge or as a guide.
Instructions are made clear and straight to the point. Your resourcefulness and How Do You Use This Module…………………………………………………………………… 3
creativity are needed to be able to answer or do the task well. Just follow the Module 1
directions and you will be guided as you move on page after page. Chapter 1: Introduction to Computer Programming
Lesson 1: Overview………………………………………………………………….. 4
In this module, you are required to go through a series of activities in Lesson 2: Basics..……………………………………………………………………… 5
order to complete each learning outcome. Each chapter has lessons with Specific Lesson 3: Environment…………………………………………………………….. 6
Learning Outcomes, Discussions, Self-Assessments, and Activities. Follow and Chapter 2: Overview of C Language
perform the activities on your own. If you have questions, do not hesitate to ask Lesson 1: Introduction……………………………………………………………… 8
for assistance from your instructor. Lesson 2: Limitation of C Programming Language…………………….. 8
Lesson 3: History of C Programming Language…………………………. 9
Remember to: Lesson 4: Installation………………………………………………………………… 9
Chapter 3: C Language Fundamentals
Read and understand the Specific Learning Outcome(s). These tell you Lesson 1: Tokens………………………………………………………………………. 11
what you should know and be able to do at the end of this module. Lesson 2: Identifiers…………………………………………………………………. 11
Lesson 3: Keywords………………………………………………………………….. 11
Work through all the information and complete the activities in each Lesson 4: Constants…………………………………………………………………. 12
section. Lesson 5: Operators…………………………………………………………………. 13
Lesson 6: Data Types………………………………………………………………… 16
Read the discussions very well. Suggested references are included to Lesson 7: Variables…………………………………………………………………… 17
supplement the materials provided in this module. Lesson 8: Type Casting……………………………………………………………… 18
Chapter 4: Data Input and Output
After reading every discussion, test yourself on how much you learned by Lesson 1: Program Structure……………………………………………………. 20
means of the Self-Assessments. Lesson 2: Input and Output (I/O)……………………………………………… 21
Lesson 3: Format Specifiers……………………………………………………… 24
Demonstrate what you learned by doing the Activities. You must be able References………………………………………………………………………………………………… 26
to apply what you have learned in another activity or in real life
situation.
Keep all the outputs in your portfolio as a record of your
accomplishments and submit on the designated period.
Note: You need to complete this module before you can perform the next
module.
Module 1| Chapter 1: Introduction to Computer Programming 3
CHAPTER 1 1. Go straight
2. Drive half kilometer
INTRODUCTION TO COMPUTER PROGRAMMING 3. Take left
4. Drive around one kilometer
Lesson 1: Overview 5. Search for KFC at your right side
Computer programming is the act of writing computer programs, which Now, try to map the situation with a computer program. The above
are a sequence of instructions written using a Computer Programming Language sequence of instructions is actually a Human Program written in English
to perform a specified task by the computer. Language, which instructs on how to reach KFC from a given starting point. This
same sequence could have been given in Spanish, Hindi, Arabic, or any other
Computer Programming is fun and easy to learn provided you adopt a human language, provided the person seeking direction knows any of these
proper approach. This course attempts to cover the basics of computer languages.
programming using a simple and practical approach for the benefit of novice
learners. Now, let's go back and try to understand a computer program, which is a
sequence of instructions written in a Computer Language to perform a specified
Computer Program task by the computer. Following is a simple program written in C programming
Language:
A computer program is a sequence of instructions written using a
Computer Programming Language to perform a specified task by the computer. printf(“Hello, World!”);
The two important terms that we have used in the above definition are: The above computer program instructs the computer to print "Hello,
World!" on the computer screen.
Sequence of instructions
Computer Programming Language A computer program is also called a computer software, which can range
from two lines to millions of lines of instructions.
To understand these terms, consider a situation when someone asks you Computer program instructions are also called program source code
about how to go to a nearby KFC. What exactly do you do to tell him the way to and computer programming is also called program coding.
go to KFC? A computer without a computer program is just a dump box; it is
programs that make computers active.
You will use Human Language to tell the way to go to KFC, something as
follows: As we have developed so many languages to communicate among
ourselves, computer scientists have developed several computer-programming
First go straight, after half kilometer, take left from languages to provide instructions to the computer (i.e., to write computer
the red light and then drive around one kilometer and you programs).
will find KFC at the right.
Computer Programming
Here, you have used English Language to give several steps to be taken
to reach KFC. If they are followed in the following sequence, then you will reach If you understood what a computer program is, then we will say: the act
KFC. of writing computer programs is called computer programming.
Module 1| Chapter 1: Introduction to Computer Programming 4
As we mentioned earlier, there are hundreds of programming languages, Algorithm
which can be used to write computer programs and following are a few of them:
From programming point of view, an algorithm is a step-by-step
Java procedure to resolve any problem. An algorithm is an effective method expressed
C as a finite set of well-defined instructions.
C++
Python Thus, a computer programmer lists down all the steps required to resolve
PHP a problem before writing the actual code. Following is a simple example of an
Perl algorithm to find out the largest number from a given list of numbers:
Ruby
1. Get a list of numbers L1, L2, L3…LN
Uses of Computer Programs 2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the following
Today computer programs are being used in almost every field, 4. If Largest is less than Li
household, agriculture, medical, entertainment, defense, communication, etc. 5. Largest = Li
Listed below are a few applications of computer programs: 6. If Li is last number from the list then
7. Print value stored in Largest and come out
MS Word, MS Excel, Adobe Photoshop, Internet Explorer, Chrome, etc., 8. Else repeat same process starting from step 3
are examples of computer programs.
Computer programs are being used to develop graphics and special The above algorithm has been written in a crude way to help beginners
effects in movie making. understand the concept. You will come across more standardized ways of writing
Computer programs are being used to perform Ultrasounds, X-Rays, and computer algorithms as you move on to advanced levels of computer
other medical examinations. programming.
Computer programs are being used in our mobile phones for SMS, Chat,
and voice communication. Lesson 2: Basics
Computer Programmer We assume you are well aware of English Language, which is a well-
known Human Interface Language. English has a predefined grammar, which
Someone who can write computer programs or in other words, someone needs to be followed to write English statements in a correct way. Likewise, most
who can do computer programming is called a Computer Programmer. of the Human Interface Languages (Hindi, English, Spanish, French, etc.) are made
of several elements like verbs, nouns, adjectives, adverbs, propositions, and
Based on computer programming language expertise, we can name a conjunctions, etc.
computer programmer as follows:
Similar to Human Interface Languages, Computer Programming
C Programmer Languages are also made of several elements. We will take you through the basics
C++ Programmer of those elements and make you comfortable to use them in various programming
Java Programmer languages. These basic elements include:
Python Programmer
PHP Programmer Programming Environment
Perl Programmer Basic Syntax
Ruby Programmer Data Types
Module 1| Chapter 1: Introduction to Computer Programming 5
Variables Text Editor
Keywords
Basic Operators A text editor is a software that is used to write computer programs. Your
Decision Making Windows machine must have a Notepad, which can be used to type programs.
Loops You can launch it by following these steps:
Numbers
Characters Start Icon → All Programs → Accessories → Notepad → Mouse Click on Notepad
Arrays
Strings It will launch Notepad with the following window:
Functions
File I/O
Lesson 3: Environment
Though Environment Setup is not an element of any Programming
Language, it is the first step to be followed before setting on to write a program.
When we say Environment Setup, it simply implies a base on top of which
we can do our programming. Thus, we need to have the required software setup,
i.e., installation on our PC which will be used to write computer programs,
compile, and execute them. For example, if you need to browse Internet, then you
need the following setup on your machine:
A working Internet connection to connect to the Internet
A Web browser such as Internet Explorer, Chrome, Safari, etc.
Similarly, you will need the following setup to start with programming
using any programming language.
A text editor to create computer programs.
A compiler to compile the programs into binary format. You can use this software to type your computer program and save it in a
An interpreter to execute the programs directly. file at any location. You can download and install other good editors
like Notepad++, which is freely available.
In case you don’t have sufficient exposure to computers, you will not be able to
set up either of these software. So, we suggest you take the help from any If you are a Mac user, then you will have TextEdit or you can install some
technical person around you to set up the programming environment on your other commercial editor like BBEdit to start with.
machine from where you can start. But for you, it is important to understand what
these items are.
Module 1| Chapter 1: Introduction to Computer Programming 6
Compiler So, if you are going to write your program in any such language, which
needs compilation like C, C++, Java and Pascal, etc., then you will need to install
You write your computer program using your favorite programming their compilers before you start programming.
language and save it in a text file called the program file.
Interpreter
Now let us try to get a little more detail on how the computer
understands a program written by you using a programming language. Actually, We just discussed about compilers and the compilation process.
the computer cannot understand your program directly given in the text format, Compilers are required in case you are going to write your program in a
so we need to convert this program in a binary format, which can be understood programming language that needs to be compiled into binary format before its
by the computer. execution.
The conversion from text program to binary file is done by another There are other programming languages such as Python, PHP, and Perl,
software called Compiler and this process of conversion from text formatted which do not need any compilation into binary format, rather an interpreter can
program to binary format file is called program compilation. Finally, you can be used to read such programs line by line and execute them directly without any
execute binary file to perform the programmed task. further conversion.
We are not going into the details of a compiler and the different phases
of compilation.
The following flow diagram gives an illustration of the process:
So, if you are going to write your programs in PHP, Python, Perl, Ruby,
etc., then you will need to install their interpreters before you start programming.
Online Compilation
If you are not able to set up any editor, compiler, or interpreter on your
machine, there are facilities to compile and run almost all the programs online
with an ease of a single click.
Module 1| Chapter 1: Introduction to Computer Programming 7