Vous êtes sur la page 1sur 14

Republic of the Philippines

GORDON COLLEGE
College of Computer Studies

LABORATORY WORKBOOK
IT112/L COMPUTER PROGRAMMING 1

NAME:_______________________________________________
TIME/DAY:__________________________________
YEAR/SECTION:__________________________________
INSTRUCTOR:_______________________________
INTRODUCTION

This Laboratory Workbook for IT112/L Computer Programming 1 introduces the


basic and advance concepts in using C Programming Language. It has been selected
for the purpose of giving a better programming efficiency and faster program
development because it encompasses the characteristics of both the high and low level
languages, which have a better machine efficiency. The lessons begins with the
Introduction to the Programming Language, its history, definition and familiarization
of terminologies, basic components of a computer, types of computer programs and
categories of programming languages. Seatwork Exercises Activity and Homework
section follows.
This Workbook has been arranged as (# of Laboratory) activity first, starting with the
overview of Computer Programming Languages and Basic Syntax Structure.
Secondly, is to learn on adding variables, primitive data types and data storage
familiarization, operators, and program development life cycle. Thirdly, is to learn the
conditional control structure, the use of number system and algorithm design and
representation enhancement. Next, is to learn iterative control structure and advance
syntax memorization and lastly, is to learn array. These features enables the user to
handle not only large amount of data but also of different types like integers,
characters etc., to do so efficiently.

COURSE SYLLABUS
Course Name
Course Credits
Contact Hours
Pre-Requisite

:
:
:
:

[IT112] Computer Programming 1


3 units (2 units lecture, 1 unit laboratory)
5 hours/week (2 hours lecture, 3 hours laboratory)
N/A

Description : Students are expected to learn the Basic syntax and semantics of a
higher-level language; Variables and primitive data types; Expressions and
assignments; Simple I/O including file I/O; Conditional and iterative control
structures; Functions and parameter passing; the concept of recursion; Program
correctness; Debugging strategies; Documentation and program style.
Learning Outcomes:

By the end of the course, students should be able to:


LO1. 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, (5) definition of functions and parameter passing, and (6) recursion.
LO2. Assess and recommend revisions to another programmers code (1) regarding
documentation and program style standards that contribute to readability and
maintainability of software, (2) regarding appropriateness of chosen conditional and
iterative constructs given a programming task, and (3) regarding thoroughness in
applying procedural abstraction.
Course Outline:
1. Overview of Computer Programming Languages and Basic Syntax Structure
2. Adding Variables, Primitive Data Types and Data Storage Familiarization,
Operators, and Program Development Life Cycle
3. Conditional Control Structure, Use of Number System and Algorithm Design
and Representation enhancement
4. Iterative Control Structure and Advance Syntax Memorization
5. Introduction to Array

Major Course Outputs:


As evidence of attaining the above learning outcomes, students are required to do and
submit the following during the indicated dates of the term. The rubrics for these
outputs are provided.
Learning
Outcome
LO1

LO2

Required Output

Due Date

CSO1: An accurate and detailed program that executes


according to the prescribed specification with the
implementation of fundamental programming components.
CSO2: From simple static program to advanced interactive
system that incorporates the body of knowledge in
fundamental programming.
CSO3: Apply the generally based instructions to the program
and develop a high logical thinking skills to understand the
different nature of programming capabilities of each
individual.

Other Requirements and Assessments:


Aside from the major course output above, major exams are required and final project.

Grading System:
Assignment / Seatwork:
Quiz / Project:
Recitation:
Attendance:
Major Exam:

10%
30%
10%
10%
40%
100%

To pass this course, one must accumulate at least ____ points through the course
requirements discussed above. The maximum points that a students can obtain
through each requirement are shown below.
Requirement/Assessment Task
Major Exams
Accurate and Functional Program for each term
Final Project and Presentation
TOTAL

Maximum Points
50
50
100
200

Rubrics [for every Course Outcome]:


Note: The instructor may modify the rubrics shown depending on the course
outcome presented.
Criteria

Solution

Program
Design

User Interface

Unacceptable
0
An incomplete
solution is
implemented on
the required
platform. It does
not compile
and/or run.

Few of the
selected
structures are
appropriate.
Program
elements are not
well designed.
User interaction
is incomplete and
does not meet

Poor
2
A completed
solution is
implemented on
the required
platform, and
uses the
compiler
specified. It
runs, but has
logical errors.
Not all of the
selected
structures are
appropriate.
Some of the
program
elements are
appropriately
designed
User interaction
minimally meets
the

Good
Excellent
3
5
A completed
A completed
solution is tested
solution runs
and runs but
without errors. It
does not meet all
meets all the
the specifications
specifications
and/or work for and works for all
all test data.
test data.

The program
design generally
uses appropriate
structures.
Program
elements exhibit
good design.

The program
design uses
appropriate
structures. The
overall program
design is
appropriate.

User interaction
generally meets
the specifications

User interaction
is as specified
and is natural to

specifications

Code
Readability

Insufficient
program
documentation,
incorrect
indentation,
and/or poor
identifier
selection

specifications,
but does not
increase the
usability of the
program.
Program is
minimally
documented,
some identifiers
are inappropriate
or inconsistent
indentation.

TABLE OF CONTENTS

and is acceptable
to the user.

the user.

Some required
documentation is
missing, or
identifiers are
inappropriate, or
statements are
not indented
correctly.

All required
documentation is
present, the
program is
correctly
indented, and
appropriate
identifiers are
selected.

I.

II.

III.

IV.

V.

VI.

VII.
VIII.

IX.

X.

Introduction to Programming Language


a. Brief History of C Language
b. Definition of Terms
c. Familiarization of Terminologies
d. Basic Components of a Computer
e. Types of Computer Programs
1. Definition of Programming Language
2. Categories of Programming Languages
Introduction to C Environment
a. Turbo C Exploration
b. Basic Syntax Identification
c. Coding 1st C Program
Program Development Life Cycle
a. Procedure in developing a program
b. Pseudocode and Flowchart
c. Coding and Debugging
C Programming Enhancement
a. Teaching different syntax used in C programming
b. Input and Output process of C Programming
c. Exercises for understanding the flow of the program
d. Adding Variables, Primitive data types and Data storage
familiarization, and Operators to the program
Algorithm Design and Representation
a. Definition of Algorithm
b. Definition of Flowchart
c. Flowcharting symbols and meanings
Conditional Control Structures Part 1
a. Definition and Examples
b. Applying different operators in C Program
c. Hierarchy of Operations
Use of Number System in the Logic of the Program
Logical Operators
a. Logical OR || Operator
b. Logical AND && Operator
c. Logical NOT ! Operator
d. Boolean Logical OR ^ Operator
Conditional Control Structures Part 2
a. Definition and Syntax of IF structures
b. Familiarization of IF structure statement
c. IF structure
d. IF ELSE structure
e. IF, ELSE IF,ELSE structure
f. Nested IF structure
Logical Operators Enhancement
a. Logical OR || Operator
b. Logical AND && Operator
c. Logical NOT ! Operator
d. Boolean Logical OR ^ Operator

XI.
XII.
XIII.

XIV.

Conditional Control Structure Part 3


a. Definition and Syntax of Switch Case Statement
Flowcharting Enhancement
a. Flowchart for control structure
b. Flowchart for system structure
Iterative Control Structure (Looping Statement)
a. Definition and Syntax of FOR Loop Statement
b. Program Execution using FOR loop Statement
c. Definition and Syntax of WHILE Loop Statement
d. Program Execution using WHILE Loop Statement
e. Definition and Syntax of DO WHILE Loop Statement
f. Program Execution using DO WHILE Loop Statement
Introduction to Array
a. Elements in Array

CHAPTER 1
INTRODUCTION TO PROGRAMMING LANGUAGE
BRIEF HISTORY OF C LANGUAGE
The C Programming language is a general purpose high level language that
was originally developed by Dennis M. Ritchie to develop the Unix operating system
at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in
1972.
In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly
available description of C, now known as the K&R standard.
The UNIX operating system, the C compiler, and essentially all UNIX
application programs have been written in C. The C has now become widely used
professional language for various reasons.

Easy to learn
Structured language
It produces efficient programs
It can handle low-level activities
It can be compiled on a variety of computer platforms

FACTS ABOUT C

C was invented to write an operating system called UNIX


C is a successor of B language which was introduced around 1970
The language was formalized in 1988 by the American National Standard

Institute (ANSI)
The UNIX OS was totally written in C in 1973
Today C is the most widely used and popular System Programming Language
Most of the state of the art software have been implementing using C
Todays most popular Linux OS and RBDMS MySQL have been written in C.

WHY
LABORATORY SESSION 1
OBJECTIVE: To familiarize programming environment using Turbo C and the
Fundamentals of Programming Language.
Before you start doing programming using C programming language, you need the
following two software's available on your computer, (a) Text Editor and (b) The
Compiler.
Text Editor
This will be used to type your program. Examples of few editors include Windows
Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi
Name and version of text editor can vary on different operating systems. For example
Notepad will be used on Windows and vim or vi can be used on windows as well as
Linux, or Unix.
The files you create with your editor are called source files and contain program
source code. The source files for C programs are typically named with the
extension .c.
Before starting your programming, make sure you have one text editor in place and
you have enough experience to write a computer program, save it in a file, compile it
and finally execute it.
The C Compiler
The source code written in source file is the human readable source for your program.
It needs to be "compiled", to turn into machine language so that your CPU can
actually execute the program as per instructions given.
This C programming language compiler will be used to compile your source code into
final executable program. I assume you have basic knowledge about a programming
language compiler.

The Development Environment - Integrated Development Environment (IDE):


The C compiler has its own built-in text editor. You may also use a commercial text
editor or word processor that can produce text files. The important thing is that
whatever you write your program in, it must save simple, plain-text files, with no
word processing commands embedded in the text. The files you create with your
editor are called source files, and for C++ they typically are named with the extension
.CPP, .CP, or .C.
The C Developing Environment, also called as Programmers Platform, is a screen
display with windows and pull-down menus. Code of the program, error messages
and other information are displayed in separate windows. The menus may be used to
invoke the operations necessary to develop the program, debug and execute the
program.
Invoking the IDE
To invoke the IDE from the windows you need to double click the TC icon.
To do so from the command prompt go in the specific directory and type tc. This
makes you enter the IDE interface, which initially displays only a menu bar at the top
of the screen and a status line below will appear. The menu bar displays the menu
names and the status line tells what various function keys will do.
Using Menus
If the menu bar is inactive, it may be invoked by pressing the [F10] function key. To
select different menu, move the highlight left or right with cursor (arrow) keys. You
can also revoke the selection by pressing the key combination for the specific menu.
Opening New Window
To type a program, you need to open an Edit Window. For this, open file menu and
click new. A window will appear on the screen where the program may be typed.
Writing a Program
When the Edit window is active, the program may be typed. Use the certain key
combinations to perform specific edit functions.
Saving a Program
To save the program, select save command from the file menu. This function can also
be performed by pressing the [F2] button. A dialog box will appear asking for the path
and name of the file. Provide an appropriate and unique file name. You can save the
program after compiling too but saving it before compilation is more appropriate.
Making an Executable File

The source file is required to be turned into an executable file. This is called
Making of the .exe file. The steps required to create an executable file are:
1. Create a source file, with a .cpp extension.
2. Compile the source code into a file with the .obj extension.
3. Link your .obj file with any needed libraries to produce an executable program.
Compiling the Source Code
Although the source code in your file is somewhat cryptic, and anyone who doesn't
know C will struggle to understand what it is for, it is still in what we call humanreadable form. But, for the computer to understand this source code, it must be
converted into machine-readable form. This is done by using a compiler. Hence,
compiling is the process in which source code is translated into machine
understandable language.
Creating an Executable File with the Linker
After your source code is compiled, an object file is produced. This file is often
named with the extension .OBJ. This is still not an executable program, however. To
turn this into an executable program, you must run your linker. C programs are
typically created by linking together one or more OBJ files with one or more libraries.
A library is a collection of linkable files that were supplied with your compiler.
Project/Make
Before compiling and linking a file, a part of the IDE called Project/Make checks the
time and date on the file you are going to compile.
Compiling and linking in the IDE
In the Turbo C IDE, compiling and linking can be performed together in one step.
There are two ways to do this: you can select Make EXE from the compile menu, or
you can press the [F9] key.
Executing a Program
If the program is compiled and linked without errors, the program is executed by
selecting Run from the Run Menu or by pressing the [Ctrl+F9] key combination.
The Development Cycle
If every program worked the first time you tried it, that would be the complete
development cycle: Write the program, compile the source code, link the program,
and run it. Unfortunately, almost every program, no matter how trivial, can and will
have errors, or bugs, in the program. Some bugs will cause the compile to fail, some
will cause the link to fail, and some will only show up when you run the program.
Whatever type of bug you find, you must fix it, and that involves editing your source
code, recompiling and relinking, and then rerunning the program.

Correcting Errors
If the compiler recognizes some error, it will let you know through the Compiler
window. Youll see that the number of errors is not listed as 0, and the word Error
appears instead of the word Success at the bottom of the window. The errors are to
be removed by returning to the edit window. Usually these errors are a result of a
typing mistake. The compiler will not only tell you what you did wrong; theyll point
you to the exact place in your code where you made the mistake.
Exiting IDE
An Edit window may be closed in a number of different ways. You can click on the
small square in the upper left corner, you can select close from the window menu, or
you can press the [Alt][F3] combination. To exit from the IDE select Exit from the
File menu or press [Alt][X] combination.
Building Blocks of Programming Language:
In any language there are certain building blocks:
Constants
Variables
Operators
Methods to get input from user (scanf( ), getch( ) etc.)
Methods to display output (Format Specifier, Escape Sequences etc.) and so on.
Variables and Constants
If the value of an item can be changed in the program then it is a variable. If it will not
change then that item is a constant. The various variable types (also called data type)
in C are: int, float, char, long etc. For constants, the keyword const is added before
declaration.
Operators
There are various types of operators that may be placed in three categories:
Basic: + - * / %
Assignment: = += = *= /= %=
(++, may also be considered as assignment operators)
Relational: < > <= >= == !=
Format Specifiers
Format Specifiers tell the printf statement where to put the text and how to display the
text.
The various format specifiers are:
%d => integer
%c => character
%f => floating point etc.
Field Width Specifiers

They are used with % to limit precision in floating point number. The number
showing limit
follows the radix point.
Escape Sequences
Escape Sequence causes the program to escape from the normal interpretation of a
string, so
that the next character is recognized as having a special meaning. The back slash \
character is called the Escape Character. The escape sequence includes the
following:
\n => new line
\b => back space
\r => carriage return
\ => double quotations
\\ => back slash etc.
Getting Input From the User
The input from the user can be taken by the following techniques: scanf( ), getch( ),
getche( ), getchar( ) etc.
Examples
1. Implementing a Simple C Program
#include<conio.h>
#include<stdio.h>
void main(void)
{
clrscr();
printf(\n Hello World);
getch();
}
2. Demonstrating the fundamentals of C Language
#include<conio.h>
#include<stdio.h>
void main(void)
{
clrscr();
int num1,num2,sum,product;
printf(\tThe program takes two numbers as input and
prints their sum and product);
printf(\n Enter first number:);
scanf(%d,&num1);
printf(\n Enter second number:);
scanf(%d,&num2);
sum=num1+num2;
product=num1*num2;
printf(\n%d+%d=%d,num1,num2,sum);

printf(\n%d*%d=%d,num1,num2,product);
getch();
}

EXERCISES
1. Type the following program in C Editor and execute it. Mention the Error (if
any).
void main(void)
{
printf(This is my first program in C);
}
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
2. Add the following line at the beginning of the above program. Recompile the
program. What is the output?
#include<stdio.h>
_____________________________________________________________________
______
_____________________________________________________________________
______
3. Make the following changes to the program. Mention the Errors observed, in your
own words:
i. Write Void instead of void.
_____________________________________________________________________
______
_____________________________________________________________________
______
ii. Remove the semi colon ;.
_____________________________________________________________________
______
_____________________________________________________________________
______
iii. Erase any one of brace { or } .
_____________________________________________________________________
______
_____________________________________________________________________
______
4. Write a program to calculate the Area (A= r2) and circumference of a circle
(C=2r),
where r = radius is taken as input and is declared as a constant. The precision of
should be the number of characters in your name. Display the result to 4 decimal
places.

_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
_____
5. Write a single C statement to output the following on the screen:
My name is Your Name
And my roll number is 00Your_roll_no
I am a student of Computer and Information System Department
_____________________________________________________________________
______
_____________________________________________________________________
______
_____________________________________________________________________
______
Programming Languages Lab Session 02

Vous aimerez peut-être aussi