0% found this document useful (0 votes)
25 views

Lab Manual CSC103 Programming Fundamentals (Lab 1 and 2)

Uploaded by

talhakhxn732
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Lab Manual CSC103 Programming Fundamentals (Lab 1 and 2)

Uploaded by

talhakhxn732
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

COMSATS University Islamabad (CUI)

Department of Computer Science

Laboratory Manual

Course: CSC103 Programming Fundamentals


COMSATS University Islamabad (CUI)

Document Version History

Version Date Prepared By Reviewed By Approved


By

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.

5. DISKETTE DRIVE INDICATOR -- Turns green when the computer is accessing


your floppy disk drive, either retrieving or storing information. If this light is green,
you should NEVER attempt to eject the floppy disk.

6. FLOPPY DISK DRIVE -- Storage device that holds, reads and writes to floppy
disks, usually called Drive A.

7. CD-DRIVE -- Player or reader that reads data from a CD ROM disk.

Page 5 of 16
4.3. Internal Components Of A Computer

Figure 1.3

4.3.1. Back Panel And Cables


The ports that connect the peripherals to the computer are located on the back panel of the
computer. Newer computers have ports that are color-coded with their appropriate
cables. Speaker cables plug into headphone jacks on the back panel and are also color-
coded. The back panel may have small icons on the ports showing the correct cables
(example --monitor for monitor cable). It is important that all cables are inserted
completely and securely in their port (pins screwed in all the way) or the peripheral will
not function properly. Once all peripherals have been connected to the computer, it may
be useful to label each cable and it's appropriate port. When the computer is stored for
the summer it will be very easy to reconnect cables in the fall. Two successful methods
used to code cables and ports include

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.

4.3.2. Storage Devices


When working on the computer, all work is entered into the computer's memory. In order
to store your work for future retrieval, you must “save” your work to a storage device
before turning the computer off. When your work is saved it creates a computer “file”.
The most common storage devices are hard

4.3.3. USB/Flash Drive (Jump/Thumb Drive)


It is a plug-and-play portable storage device that uses flash memory and is lightweight
enough to attach to a key chain. A keychain drive can be used in place of a floppy disk,
Zip drive disk, or CD. When the user plugs the device into their USB port, the computer's
operating system recognizes the device as a removable drive. Unlike most removable
drives, a keychain drive does not require rebooting after it's attached, does not require
batteries or an external power supply, and is not platform dependent. Several keychain
drive manufacturers offer additional features such as password protection, and
downloadable drivers that allow the keychain drive to be compatible with older systems
that do not have USB ports. Keychain drives are available in capacities ranging from 8
MB to 2 gigabytes, depending on manufacturer, in a corresponding range of prices.

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.

RETURN KEY -- Another name for the Enter key.

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.

4.5. Output Devices


Output devices are computer devices that display or output information. The
monitor is a common example of an output device. Other output devices are:
 Printers—take information from the CPU and transfer it to paper, provides a hard
copy. There are a number of different printer technologies available: Dot Matrix,
Ink Jet, Laser.
 Plotters—produces high-quality line drawing graphic output (used for blueprints).
 Video projector, Scan Converter or LCD overhead projector—projects the image
onto a wall screen for greater view by large groups.
 Speaker(s)—provides output of sound or speech.

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.

5.2. Make yourself familiar with Windows and its Components


Page 9 of 16
The main components of Windows when you start your computer are the Desktop,
My Computer, Recycle Bin, Start Button, Taskbar, and shortcuts to applications.
After opening an application, you will also have a window with an active application
which will appear in your desktop and taskbar.
5.3. Use Windows Explorer to understand the directory structure of different drives
present.
5.4. Practice making new folders, copy/ cut pasting of files.
5.5. Learn how to set new password for Login.
5.6. Try to change the wallpaper and screen saver.
5.7. Explore various applications installed in the Accessories tab present in the start
menu/ button.

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

3.2.1. Decisions (Switching logic)


A step in an algorithm that leads to more than one possible continuation is called a
decision.
The computer can determine the truth value of a statement involving one of six
mathematical relations symbolized in the table below:

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

In flowcharting, the diamond-shaped symbol is used to indicate a decision. The question


is placed inside the symbol, and each alternative answer to the question is used to label
the exit arrow which leads to the appropriate next step of the algorithm. The decision
symbol is the only symbol that may have more than one exit.

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.1. Construct flow chart for the following scenario.


 Turn on the hot and cold taps.
 Is it too hot or cold? If it is, go to step 3, otherwise go to step 4.
 Adjust the hot and cold taps and go back to step 2.
 Wait for 2 minutes.
 Is the bath full? If it is, go to step 7, otherwise go to step 6.
 Go back to step 4.
 Turn off the hot and cold taps.

5.2. The length & breadth of a rectangle and radius of a circle are input through the
keyboard. Draw a flow chart to calculate the area & perimeter of the rectangle, and
the area & circumference of the circle.

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

5.4. Draw a flowchart to add first 20 even numbers.

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

You might also like