Lab Manual CSC103 Programming Fundamentals (Lab 1 and 2)
Lab Manual CSC103 Programming Fundamentals (Lab 1 and 2)
Laboratory Manual
1.0 Feb 08, Ms. Zara Hamid, Ms. Rafia Dr. Muzafar Khan, Dr. Amir
2013 Farooq, Ms. Amna Irum, Mr. Hayat, Ms. Sehresh Khan, Mr.
Azfar Shakeel Ubaid ur Rehman
COMSATS University Islamabad (CUI)
Table of Contents
Lab 1 – Introduction to Computers, Windows OS and its Basic Usage..................................................4
Lab 2 - Flow Charts...............................................................................................................................12
Lab 3 - Getting Started with C...............................................................................................................16
Lab 4 – The if-Statement........................................................................................................................19
Lab 5 – If-else, Switch, and goto statements.........................................................................................23
Lab 6 – For and nested-for loops...........................................................................................................30
Lab 7 – While and do-while loops, continue, and break........................................................................32
Lab 8 – Functions...................................................................................................................................36
Lab 9 – Recursive functions and pointers..............................................................................................39
Lab 10 – Arrays......................................................................................................................................42
Lab 11 – Character arrays.....................................................................................................................45
Lab 12 – Structures................................................................................................................................48
Lab 13 – Files........................................................................................................................................50
Lab 1 – Introduction to Computers, Windows OS and its Basic Usage
1. Objectives
Understanding of Computer System, Hardware and Software, basic skills required to use
a desktop computer.
2. Outcome
Students will become comfortable with the usage of computer, become aware of main
parts of a computer system.
3. Introduction
Computer Basics introduces general computer use and terminology. It describes the basic
hardware components of a PC and introduces basic skills for using software programs in
a windows environment. This course will address hardware and peripheral components of
the computer and how to use them correctly.
Figure 1.1
A computer is an electronic device that has the ability to store, retrieve, and process data,
and can be programmed with instructions that it remembers. The physical parts that
make up a computer (the central processing unit, input, output, and memory) are called
hardware. Programs that tell a computer what to do are called software. A set of
instructions that perform a particular task is called a program, software program, or
software. Peripherals are any hardware device connected to a computer, any part of the
computer outside the CPU and working memory. Some examples of peripherals are
keyboards, the mouse, monitors, printers, scanners, disk and tape drives, microphones,
speakers, joysticks, plotters, and cameras.
4. Examples
Below we will discuss some major components of the computer system.
4.1. Monitor
The computer monitor is an output device that displays input on a screen and is very
similar to a television monitor. When the computer wants to display something, it
calculates how it needs to change the color and brightness of the different pixels, and
changes the values in the video memory.
Monitor Resolution refers to the number of dots on the screen or pixels. It is expressed
as a pair of numbers that give the number of dots on a line (horizontal) and the number of
lines (vertical). Four resolutions commonly used today:
▪ 640 x 480 PIXELS (VGA) (SVGA) -- images are larger for visually impaired students.
▪ 800 x 600 PIXELS (SVGA) – most web sites are designed to be viewed at this setting.
Page 4 of 16
▪ 1024 x 768 PIXELS (SVGA)
▪ 1280 x 1024 PIXELS (SVGA)-- images are smaller, but more information can be
displayed.
The smaller the pixels, the clearer and sharper the picture appears on the monitor. Most
monitors come with a .28 dot pitch. This is the standard for monitors. Do not buy a
monitor if the dot pitch is more than .28. The smaller the dot pitch, the better the
monitor.
4.2. Computer
The computer is a machine that processes data according to a set of instructions that are
stored internally either temporarily or permanently. The computer has either external or
internal peripherals attached to it. The picture below displays two internal devices—the
floppy disk drive and CD ROM drive.
Figure 1.2
1. POWER SWITCH -- Turns the computer on and off. Whenever the computer is
turned off, always wait at least 60 seconds before turning it back on again.
2. POWER INDICATOR -- Located in the center of the power switch. A green light
indicates the computer is on.
3. RESET BUTTON -- Allows you to reboot (restart) your system without having to
power down the entire computer. Rebooting the system in this manner reduces
stress on the system components. This button is used ONLY when the computer has
“frozen” and will not accept any commands.
4. HARD DISK DRIVE ACCESS INDICATOR -- Turns green when the computer
is accessing your hard drive, either retrieving or storing information.
6. FLOPPY DISK DRIVE -- Storage device that holds, reads and writes to floppy
disks, usually called Drive A.
Page 5 of 16
4.3. Internal Components Of A Computer
Figure 1.3
Figure 1.4
Page 6 of 16
colored dots using nail polish (red mouse cable, red dot on mouse port, pink printer
cable, pink dot on printer port, etc.) and numbering cables and ports (1 & 1, 2 & 2, etc.).
When attaching or removing cables from the computer it is important to be very careful.
The cables are connected with "pins" that can easily be bent or broken. Don't try to
remove cables by "wiggling" from side to side. Pull cables directly out to avoid
damaging the pins.
Figure 1.5
Page 7 of 16
4.4. Input Devices
4.4.1. Mouse
The mouse is a pointing device attached to the computer that controls the movement of
the cursor on the screen. It allows the user to execute commands using point & click and
click & drag techniques. As the user moves the mouse across the pad, the cursor moves
across the screen. The mouse should always be used with a mouse pad to provide a
smooth surface for mouse movement and to help keep the mouse from damage. If you
"run out of room" on the pad, simply pick up the mouse and move it to the opposite edge
and continue movement.
Figure 1.6
The PC mouse has two buttons (left and right) and newer mice have a scroll wheel
between the two. Mouse commands are executed by "clicking". The term “click” refers
to the left mouse button.
4.4.2. Keyboard
The computer receives most of its input from the user via the keyboard that is very similar
to the typewriter keyboard. The keyboard is connected by a cable to the keyboard port on
the back of the computer. There are extra keys on the computer's keyboard that are not
found on a normal typewriter. Following is an explanation of the function of these keys.
The exact manner in which the keys function depends on the software program.
Figure 1.7
BACKSPACE KEY-- Deletes the character just to the left of the cursor (or insertion
point) and moves the cursor to that position.
DELETE KEY-- Sometimes labeled Del, deletes the character at the current cursor
position or to the right of the insertion point, or deletes the selected object, but does not
move the cursor.
ARROW KEYS -- four arrow keys for moving the cursor or insertion point right, left,
up, or down. Moving the arrow keys does not delete any characters on the screen.
CAPS LOCK KEY -- A toggle key that, when activated, causes all alphabetic characters
to be uppercase.
HOME -- moves the cursor to the top left corner of the screen or to the beginning of the
file, but it can have other meanings depending on which program is running.
Page 8 of 16
END -- moves the cursor to the end of the line, the end of the page, or the end of the file
depending where the cursor is located on the page and on which program is running.
ENTER -- Used to enter commands or to move the cursor to the beginning of the next
line. Sometimes labeled Return instead of Enter.
ESC -- Short for Escape, this key is used to send special codes to devices and to exit (or
escape) from programs and tasks.
FUNCTION KEYS -- Special keys labeled F1 to Fx, x being the number of function
keys on the keyboard. These keys have different meanings depending on which program
is running.
CTRL KEY -- Short for Control, this key is used in conjunction with other keys to
produce control characters. The meaning of each control character depends on which
program is running.
ALT KEY -- Short for Alternate, this key is like a second Control key
PAGE UP and PAGE DOWN -- moves the cursor up or down a set number of lines
usually one page or screen at a time. Often abbreviated PgUp and PgDn.
NUMERIC KEYPAD -- A separate set of keys on some keyboards that contain the
numbers 0 through 9 and a decimal point arranged as on an adding machine. Numeric
keypads make it easier to enter large amounts of numeric data. For the keypad to
function as numbers, the NUM LOCK must be on (Num Lock light is green).
INSERT -- Changes between insert mode and overstrike mode in word processing
programs. In insert mode, all characters typed are placed at the cursor position (or to the
right of the insertion point). With each new insertion, characters to the right of the cursor
are pushed to the right of the insertion point to make room for the new characters. If insert
mode is turned off, typing then overwrites existing characters instead of inserting the new
ones before the old ones. This is often called overwrite mode. Most PC keyboards have
an Ins or Insert key that lets you switch back and forth between insert and overwrite
modes.
5. Lab Tasks
5.1. Under the supervision of instructor have a look inside the system box, understand the
role and usage of ports present at the back panel.
Figure 1.8
6. Home Tasks
6.1. Try to search and download application of your choice from the internet.
6.2. Install the downloaded application.
6.3. Try to remove newly installed application, from add/ remove applications option
present in the control panel.
6.4. Swap the left and right mouse button, try to change the sensitivity of mouse pointer
and double click speed.
6.5. Change the picture used for Login purpose.
6.6. Place multiple copies of a file in various folders/ subfolders and then use search
option to search the file present at all locations.
6.7. Delete some file and try to restore from the recycle bin.
6.8. If you have a printer available at home, try to add the printer and make a test print.
6.9. Learn how to create another user (another Login) for the same computer. What are
the options you can set for the new user?
6.10. Practice the following Windows common shortcuts (Fig. 9).
Page 10 of 16
Figure 1.9
7. References
[i] Windows Help Manual (Installed with the OS), Press F1.
[ii] Microsoft Windows XP, A Beginner’s Guide,
http://www.reading.ac.uk/web/files/its/WindowsXP2.pdf
[iii] Online Windows tutorial, http://www.teacherclick.com/winxp/index.htm
[iv] A Complete illustrated guide to Hardware,
http://portal.aauj.edu/portal_resources/downloads/hardware/acomplete_illustrated_Gu
ide_to_the_pc_hardware.pdf
Page 11 of 16
Lab 2 - Flow Charts
1. Objectives
The objective of this lab is to make student understand the basic concepts of flowcharting.
2. Outcome
i. At the end of this lab student will know how to develop logic of a C program.
ii. Students will get clear understanding of the steps of Formal Problem Solving
which are:
Understand the Problem
Develop an Algorithm
Refine the Algorithm
Create an Action Plan
Generate a Solution
Test the Solution
3. Introduction
There are two commonly used tools to help to document program logic (the algorithm).
These are flowcharts and Pseudo code. Generally, flowcharts work well for small
problems but Pseudo code is used for larger problems. The flow of data between steps is
indicated by arrows, or flow lines.
Some of the common symbols used in flowcharts are shown below:
Figure 1
3.1. Example
Draw a flowchart for a program that reads Name, Balance and Rate of interest and
compute Interest and displays Name and its Interest.
Page 12 of 16
Figure 2
3.2. Example:
Draw a flowchart for a program that reads three numbers and compute Sum, Average and
Product displays the computations.
Figure 3
Page 13 of 16
Figure 4
In practice, the computer is presented not with a true/false statement, but with a question
having a "Yes" or "No" answer, for example if A = 10, B = 20, K = 5, and SALES =
10000, then:
Figure 5
3.3. Example:
Draw a flowchart for a program that reads two numbers and displays the numbers read in
decreasing order.
Figure 6
Page 14 of 16
4. Lab Tasks
4.1. Draw a flowchart for a program that computes Factorial of a number and displays it.
4.2. Draw a flowchart that reads two temperature and displays the message “below
Freezing” for temperature less than 32 degrees and vice versa.
4.3. Draw a flowchart for broken lamp repairing after checking possibilities of it being on
and checking of bulb being fuse or not.
4.4. Draw a flowchart for tax calculation. If income greater than 15000 and 60000 then it
displays the message pay business tax. If income is less than 15000 it displays the
message pay Student tax and if income is less than 60000 it displays the message pay
Individual tax.
5. Home Tasks
5.3. Construct flow chart for the following order processing scenario.
Receive and order by email.
Record it in company’s database.
Check for shipping.
If yes.
Print invoice
Send email to confirm shipping
Assemble package and ship
If no
End Process
6. References
[i] http://www.cprogramming.com/tutorial/c/lesson1.html
[ii] http://www.scribd.com/doc/2451377/Flowchart-Programming
[iii] http://en.wikipedia.org/wiki/User:Sdudah/python
[iv] http://www.cimt.plymouth.ac.uk/projects/mepres/book8/bk8i1/bk8_1i2.htm
[v] http://www.rff.com/order_processing.htm
[vi] http://users.evtek.fi/~jaanah/IntroC/DBeech/3gl_flow.htm
Page 15 of 16
Page 16 of 16