You are on page 1of 23

Pakistan Navy Engineering College

CS111-Introduction to Computers
Lab Manual

1
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

List of Practical

S.No. Description

1. Introduction and identification of components of a computer system.

2. Assembling and disassembling of computer hardware.

3. Finding details of installed devices through software.

4. Exploration of MS Office (MS-Word, MS-Excel and MS-PowerPoint).

5. Demonstration of Visual Studio 6.0 Environment. Use of program editor,


compiler, linker and debugger. Sample program run and debug.

6. Writing a program to calculate the area of a circle, rectangle and square with
respective inputs taken from the user.

7. Input/Output redirection.

8. Generating random numbers and printing the ‘#’ sign that many times using
a separate function.

9. Calculating the average of numbers.

10. Taking the number of rows from the user, printing a straight right triangle
and an inverted right triangle using ‘*’ that totals to the number of rows
entered by the user.

11. Reversing a string and storing it in an array and printing out the array using
putchar( ) function.

12. Taking the number of rows from the user, generate a star pattern first storing
it in a two-dimensional array and then printing the contents of the two-
dimensional array.

13. Writing the code for the strlen( ) and strcpy( ) functions in the standard
string library.

2
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

List of Acronyms
PC Personal Computer
RAM Random Access Memory
BIOS Basic Input Output System
MS Microsoft
POST Power on Self Test

3
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 01

Title: Introduction and identification of components of a computer system.

Objective: Familiarization with the hardware components and ports commonly found
in a real PC system

Minimum System Requirements:


 Standard PC with Pentium-III processor, RAM modules and a few PCI cards

Observations:

Component Found How many Items Manufacturer No. of


(Yes/No) Information Pins/Holes
Power button
Reset button
Floppy drive
CD/DVD drive
Port for keyboard
Port for mouse
Serial port
Parallel port
LAN port
Power socket
USB port
Modem Port
Game Port
Processor socket
Memory slots
PCI slots
ISA slots
Battery for CMOS
BIOS chip
Motherboard chipset
AGP slot
Power supply
IDE Controller
connectors

4
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 02

Title: Assembling and disassembling of computer hardware.

Objective: Familiarization with the often required operations like replacement and
addition of RAM or expansion cards.

Minimum System Requirements:


 Standard PC with Pentium-III processor, RAM modules and a few PCI cards

Description:

A multi-media movie is arranged to demonstrate the guidelines for insertion and removal
of components.

Observations:

Students practiced the insertion and removal of RAM and PCI expansion cards

5
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 03

Title: Finding details of installed devices through software.

Objective: Familiarization with the extraction of hardware resource information


through
 BIOS settings
 Windows System Information

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running Windows XP

Required Tasks:

1. Restart the PC using Windows Restart option, and when it restarts press F2 key to
enter BIOS setup.
2. Find out the details of Hard Disk, processor, available RAM from that screen.
3. Find out the menu on which you can set the Boot priorities so that you can manage
things in case of running a bootable floppy / CD-ROM.
4. There is a series of quick test performed at the boot startup that is called POST. Find
out the menu through which you can enable or disable that option.
5. When you are logged in to your PC, go to
Start  Programs  Accessories  System Tools  System Information
6. Compile the details from System Summary group and the Components group about
the hardware that is installed and recognized by your Operating System.

Observations:

This exercise is useful as a first diagnostic check by the end user for any problems with
his PC.

6
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 04

Title: Exploration of MS Office programs (MS-Word, MS-Excel and MS-PowerPoint).

Objective: Hands-on experience with the most frequently used features of MS-Office
programs so that they can be used in smooth preparation of reports, presentations and
other academic assignments.

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Office XP

Description:

Based upon the skill level of each student in MS-Word, MS-Excel, MS-PowerPoint,
students will be given exercises to find out and learn more advanced tasks using the
extensive help provided in MS-Office. Then, they will represent those features to the
whole class

Students can be categorized as follows:

Program/Level None Basic Intermediate Expert


MS-Word
MS-Excel
MS-PowerPoint

Observations:

This exercise will increase the learning at individual level as well as at the class level.

7
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 05

Title: Demonstration of Visual Studio 6.0 environment. Use of program editor, compiler,
linker and debugger. Sample program run and debug.

Objective: Hands-on experience using MS-Visual C++ compiler for development of C


programs in next coming labs.

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Description:

The Microsoft Visual C++ compiler is one of the compilers available that compiles the
language called C++. The Visual C++ compiler can be used to create Windows programs
or programs that run in a console window. Programs that run in a console window are
often called console applications.

Starting the Compiler

When you installed Visual C++, a new program group was created. It can be found in the
"Start" menu under the group "Programs." Find this new group, and click on the icon
labeled "Microsoft Visual C++" to start the compiler.

A Visual C++ splash screen will be displayed briefly before the development
environment begins. You may be overwhelmed at first by the complexity of the
development environment, but with practice you will learn your way around.

General Overview of the Interface

The top of the screen may look familiar to you. It consists of drop-down menus and
several toolbars, like many other programs designed for Windows. You will use these
menus to perform routine tasks within the development environment.

On the bottom of the screen is a dock able window called the "output" window. It is a
multipurpose window used for viewing various forms of output. Notice the tabs towards

8
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual
the bottom of the window. These can be used to switch the views between "Build,"
"Debug," "Find in Files," etc. Build displays information and errors as the compiler is
building a project, and debug is used by the programmer to display various debugging
information. The rest are self-explanatory.

The dock able window on the right of the screen is the "Workspace" window. It displays
information about the files and / or projects contained in the current workspace. The
"Workspace" window is a convenient way to switch between the files or classes
contained in a project.

The actual source code for your program will be displayed in the remaining space on the
screen. This is where you will create and edit the source code files.

The programmer can choose whether or not to display each of these windows. There are
several buttons on the toolbar that control the display. They can be toggled on or off.

Compiling and Executing a Simple C Program

Creating and running a program in Visual C++ involves five major steps:

1. Creating a New Project


2. Adding Source Code to the Project
3. Building the Project (Compiling, and Linking)
4. Debugging the Project
5. Running the Project

Begin by starting the Visual C++ development environment if you haven’t already done
so. If you already have a project open, be sure to close the current workspace by clicking
on the "File" menu, then "Close Workspace." Choose "Yes" when asked if you would like
to close all document windows.

The Visual C++ user interface follows the standard Windows conventions. There are
several pull-down menus along the top of the screen: File, Edit, View, Insert, Format,
Tools, Table, Window, and Help. These menus are how you interact with the
programming environment. Shortcut buttons to many of these menu options can be found
in the toolbar just under the menu bar. As you gain experience using the development
environment, you may prefer to use these buttons as well as keyboard shortcuts to access
the menu options more quickly.

Visual C++ organizes your source code into projects. Each project represents one full
program or executable file. To begin creating your new program, you must first create a
new project. From the "File" menu, choose "New." Type the name of your project into the
text box on the left – call this project "hello" – then choose "Win32 Console Application"
from the list of project types. Click "OK". When the dialog box appears asking you to

9
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual
select the type of project you would like to create, make sure that the option labeled "An
Empty Project" is selected. Click "Finish." Visual C++ has now created a new project.

To begin adding source code to your project, select "Add to Project" from the "Project"
menu, then choose "New …" Type a name for your source file in the appropriate box –
call this file "hello.c", then select the file type ("C++ Source File"). Click "OK." A blank
document will appear where you will enter the source code for your program. This area
of the development environment is basically a text editor with a few added features. The
editor helps you format and highlight certain key elements of your code so that it is easy
to read. Enter the program below exactly as it appears, and save the document when you
are done:

#include<stdio.h>
void main(void)
{
printf(“Welcome to ITC course\n”);
}

Now you are ready to build your project. This involves compiling and linking your
program. In Visual C++ both of these tasks can be accomplished simultaneously with the
click of one button.

To build this project, select "Build hello.exe" from the build menu, or click the equivalent
shortcut button on the toolbar. As Visual C++ builds your program, you will see
information about the build in the debug window at the bottom of the screen. If the
compiler encounters any errors in your program as it is compiling your source code, the
errors are displayed here along with a brief explanation of what might be causing them.

Once your project has been built, you are ready to run it for the first time. Choose
"Execute hello.exe" from the build menu, or click the appropriate shortcut button on the
toolbar. A DOS window will appear, and the text "Hello World!" will be displayed inside
it. When you execute a program from within the development environment, execution
will pause upon completion. Press any key to exit you program and return to Visual C++.

Understanding Errors and Warnings

Dealing with the warnings and errors that are generated by a C++ compiler can be one of
the most frustrating parts of programming in C, especially for a beginning programmer.
Because C is a very flexible language, you will not always get an error when you do
something you should not do. On the other hand, one problem in a program might
generate many error messages, making you think things are worse than they are. Here are
a few tips and things to keep in mind when dealing with warnings and errors.

10
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Why do I get so many warnings?

Warnings are just things that the compiler wants to bring to your attention to be sure that
you are aware that a certain condition exists in your program. The most common one that
our students run across is a warning that states that you might lose data because of a
double to float conversion. On the Microsoft Visual C++ compiler, you might see errors
like the following.

warning C4305: '=' : truncation from 'const double' to


'float'
warning C4244: '=' : conversion from 'double' to 'float',
possible loss of data

The first of the errors listed above occurs when you assign a literal floating point number
to a variable of type float, such as in the code below.

float x;
x = 1.23;

In some compilers, including the Visual C++ compiler, literal floating point values (such
as 1.23) are interpreted to be of type double in order to have a high degree of precision.
When the double value gets assigned to a float variable (which has less capacity than a
double), a warning is generated to let you know that there is potential for data loss. For
example, if the statement was

x = 1.23456789;

and x is of type float, there would be data loss because a float cannot hold more than
about 7 digits of precision. In this case, the warning could save you from unexpected
results. However, in a statement like

x = 1.23;

you still get the warning, even though there is no danger of losing data.

The second warning message shown above occurs when you assign the value from a
double to a variable of type float. Again, the compiler is simply warning you that if the
double variable is holding a number of high precision, digits may be lost when the data is
transferred to the float variable.

11
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual
The warnings can be avoided by changing the data type of the float to a double. The
change is not, however, necessary unless the value going into the float has extra precision
that is needed.

Is it OK to have a program with warnings?

In some cases, yes. Some warnings are providing information that should be addressed.
But in cases where you understand the warning and you make the decision that the code
is fine in this case, the warning may be ignored.

The errors I get do not tell me anything. What do I do?

Sometimes C++ error messages are not very helpful. If you get a message you do not
understand, check the line on which the error occurred. Even if you cannot decipher the
error, you may be able to find the problem by studying the code in the vicinity of the
error.

What are some tips for finding errors in my programs?

When you have a weird error that you can't seem to find, check to be sure that every
opening brace has a closing brace. Especially check within if statements and loops. You
should also check for missing semicolons. Sometimes a missing semicolon can cause an
error many lines later.

When you are tracing an error, check the line that the error was reported on, and then
check the lines previous to that one. Often, the error is actually on a line previous to the
line where the error is reported.

Make sure that all of the necessary #include statements are present. Without the proper
header files, you can encounter many errors.

Finally, when you compile a program and get multiple errors, don't automatically assume
that you actually have made that many mistakes. A program with 20 or more errors
during compilation may have only one small typo. When faced with a large number of
errors, recompile after you spot something that is an obvious error (after you have fixed
the obvious error, of course). You may find that fixing one tiny problem can cut down the
number of reported errors drastically.

Projects and Workspaces

12
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual
Visual C++ groups all the files needed to create a program together into a project, and
further groups the projects into a workspace. A workspace can be composed of one or
many projects. In order to build a program, you must create a project workspace. If you
do not begin your program by creating a new project, Visual C++ will create a default
project for you the first time you build the program.

You view your project in a workspace window, usually located on the left of the screen. If
this window is not visible, you can display it by clicking the appropriate shortcut button
on the standard toolbar. The workspace window allows you to view a project from three
different perspectives: its classes, files, and resources. You can switch between these
views by clicking on the ClassView, FileView, and ResourceView tabs, respectively.

As your programs increase in size, you will appreciate the convenience a project offers.
Many programs are composed of multiple source code files. The project offers an easy
way to organize all these source files, as well as compile them in one simple step. To edit
different source code files, simply select the appropriate file in the FileView.

Multiple Source Files in One Project

In some cases it may be necessary to have more than one source code file in a project.
This can be a common situation when working with existing user-defined classes that are
defined in one file, and implemented in another. When you include the header file for a
class of this type, you must also tell the compiler where to find the implementation file.

To add a file to a project, select Add To Project from the Project menu. Another menu
will appear. If you want to add an existing file to the project, select Files, then find the
file you wish to add and click Ok. If you wish to add a new file to the project, select New,
and proceed to create a new file as usual.

Using the Debugger

If you are like most people, your programs will not always execute correctly the first time
you build them. While some errors are easy to find and correct, others may be very
difficult to locate due to the complexities of larger programs. The debugger is a complex
tool that can help you track down and correct these errors.

To start the debugger, a project must be open in the development environment. Once you
have opened the project you wish to debug, the debugger is invoked by choosing any of
the debug commands. The debug commands are located in the "Build" menu under the
sub-heading "Start Debug." You can access several other debug commands, in addition to
those in the menu, from the debug toolbar, which is displayed by selecting "customize"
from the "Tools" menu. This toolbar is displayed automatically when you invoke the
debugger. Some of the more common commands are listed below:

13
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual
 Go The Go command executes code from the current location until it reaches
a breakpoint, the end of the program, or a point at which the program pauses
to get input from the user.
 Step Into When Step Into is chosen, the debugger executes each C++
statement one by one. Pausing to let the programmer check the values of
variables or make adjustments between statements. Step Into lets the
programmer step into every function call, loop, or other code block in the
program. In essence, no statement will be executed until the programmer is
ready to execute it.
 Step Out Step Out is used in conjunction with Step Into. It will immediately
execute the remaining code in the current function call, loop, or other code
block, then pause execution. The programmer can continue to debug the
program.
 Step Over This command is used to step through a program without stepping
into function calls. When Step Over is used on a function call, loop, or other
code block, the entire block is executed immediately.
 Run to Cursor Run to Cursor executes the program up to the point in the code
where the cursor is located. Then execution is paused.

When program execution is paused, a yellow arrow on the left of the screen points to the
statement that will be executed next.

The appearance of the development environment will change when the debugger starts.
By default, two new windows and the debug toolbar are displayed. The Variables window
is located on the bottom left of the screen. It allows the programmer to view the value of
every variable relative to the current context of the program. The Watch window is on the
bottom right. In this window, the programmer can select specific variables and
expressions to watch while the program is running. If these windows do not appear when
the debugger starts, you will have to display them manually. To display both of these
windows, as well as the other debug windows, select "Debug Windows" from the "View"
menu then choose the name of the debug window.

Watching Variables

While debugging a program, the variables windows and the watch window let you
manage variables in a program. Both windows are made up of spreadsheet fields where
information about the variables contained in a program is displayed. The "Name" column
holds the name of the variable, and the "Value" column holds its value. You can change
the value of a variable while the program is running by editing the value field in either
window.

14
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual
The variables window automatically keeps track of variables important to the program’s
current context, and provides quick access to those variables. If a variable is an array, an
object, or a structure, it will have a + or – tree control symbol beside it. By clicking on
the symbol, you can view or hide its members.

The watch window lets you choose which variables you want to "watch." It is made up of
four spreadsheet pages labeled "watch1," watch2," "watch3," and "watch4." Each page
contains a list of user-specified variables and their current values. The separate pages are
provided so that related variables can be grouped together to make them easier to watch.
Click on the tabs at the bottom of the window to switch between pages.

The watch window remains blank until you add a variable to it. You can add a variable to
the window by typing its name into a cell under the column labeled "Name," or by
dragging the variable name from the variables window to a new row in the watch
window.

Setting and Using Breakpoints

Breakpoints allow you to pause the program execution at a specific line of code while
debugging a program. If a breakpoint has been set, choosing the debug command "Go"
will cause the program to execute up to the breakpoint. To continue execution, choose
one of the commands from the debug menu.

To set a breakpoint, position the cursor on the line where you want the program to break,
then click the "Insert/Remove Breakpoints" button on the toolbar. The button contains a
picture of a hand, and is usually located on the far right side of the toolbar. You can also
set or remove breakpoints by pressing F9, the shortcut key for the "Insert/Remove
Breakpoints" button. A red dot appears in left margin of the line on which the breakpoint
is set.

To remove a breakpoint, use the same method. Clicking the "Insert/Remove Breakpoint"
toolbar button (F9) will remove a breakpoint if there is one set one the line where the
cursor is located. The red dot disappears when a breakpoint is removed.

Note: Reference was taken from different Microsoft publications.

15
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 06

Title: A program to calculate the area of a circle, rectangle and square with respective
inputs taken from the user.

Objective: Hands-on experience with

 input / output functions in C


 arithmetic and assignment operators in C

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. User will be asked to enter the radius of a circle. Program will display the area of
circle using the formula, area = π r 2
2. User will be asked to enter the length and breadth of a rectangle. Program will display
the area of rectangle using the formula area = (length) x (breadth)
3. User will be asked to enter the length of one side of a square. Program will display
the area of that square area = (side) 2

In all cases, program must be able to take floating point values and display the result with
the accuracy up to 2 decimal points.

16
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 07

Title: Input/Output redirection

Objective: Hands-on experience using input / output redirection in DOS

 to retrieve information from files instead of keyboard


 to store output into files instead of display screen.

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. The same area calculation program that was developed in previous lab is now to be
executed from the DOS command line. DOS window can be launched through
Start  Programs  Accessories  Command Prompt
2. To save the output to a file instead of showing it on the display screen, type the
program’s executable file name followed by greater than sign e.g.,
>output_file_name.txt. Find the file in the same path where the executable file is
found
3. To get the inputs from a file instead of having from the keyboard, type the program’s
executable file name followed by less than sign e.g., <input_file_name.txt. Before
that execution, place the input file with data matching with the format of scanf( )
function, in the same path where the executable file is found
4. You can use both the redirection commands simultaneously to get the data from one
file and store the output in another file. That would be helpful in processing bulk of
data. For that purpose type the program’s executable file name followed by
< input_file_name.txt >output_file_name.txt

17
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 08

Title: Generating random numbers and printing the ‘#’ sign that many times using a
separate function.

Objective: Hands-on experience using

 for loops in C
 functions in C

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. Program will first generate and store a random number using rand( ) function. This
will require the header file stdlib.h to be included in your program.
2. there will be a function that will take that number and print the symbol ‘#’ as many
times.
3. The program can be modified to ask the character input from the user and print that
character instead of ‘#’. In that case, the arguments passed to the function will
increase to take the user specified symbol as well.

18
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 09

Title: Calculating the average of numbers

Objective: Hands-on experience using

 While loops in C
 Arrays in C

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. User will be asked to enter numbers one by one till it gives a value zero (0).
2. Program will count the number of inputs given by the user and add up the values to
get the total.
3. Program will display the average value by using the simple formula average = total /
number of values
4. The program can be modified to store all the numbers in an array and display all the
numbers, their total and their average. Here, it should also check that array size is not
exceeded.

It must be kept in mind that the last value that is zero and used only for the termination
purposes, must not be used I any calculations. Accuracy of up to 2 decimal digits is
required.

19
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 10

Title: Taking the number of rows from the user, printing a straight right triangle and an
inverted right triangle using ‘*’ that totals to the number of rows entered by the user.

Objective: Hands-on experience using Nested loops in C

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. User will enter the number of rows to indicate the size of triangular pattern.
2. Program will print a character ‘*’ as many times on a row as is the number of that row
e.g., one ‘*’ on 1st row, two ‘*’ on 2nd row and so on. In that fashion, as many rows are
printed as the number entered by the user. In this case, the last row will have
maximum number of ‘*’.
3. Program will print another pattern such that now it starts with printing maximum ‘*’
on 1st row, one less ‘*’ on 2nd line and so on. In that fashion, as many rows are printed
as the number entered by the user. However, the last row will have only one ‘*’.
4. the program can be modified to take the symbol input from the user and print that
character instead of the ‘*’

20
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 11

Title: Reversing a string and storing it in an array and printing out the array using
putchar( ) function.

Objective: Hands-on experience using

 Strings in C
 Arrays of characters

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. User will enter a string. Program will store that string in a character array.
2. Program will store the same string in reverse direction in another character array.
3. Program will print the contents of the new string using putchar( ) function until end of
string is found.

21
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 12

Title: Taking the number of rows from the user, generate a star pattern first storing it in a
two-dimensional array and then printing the contents of the two-dimensional array.

Objective: Hands-on experience using multi dimensional arrays in C

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. User will enter the number of rows to indicate the size of star pattern.
2. Program will store the ‘*’ in a two dimensional array such that star pattern is
perceived. Eventually, it will require to calculate how many elements need to be filled
with blank spaces and how many with ‘*’. For example,

*
***
*****
***
*

3. Program will print the contents of two dimensional array

22
Pakistan Navy Engineering College
CS111-Introduction to Computers
Lab Manual

Lab# 13

Title: Writing the code for the strlen() and strcpy() functions in the standard string
library.

Objective: Hands-on experience implementing

 Core / library functions


 Pointer arithmetic

Minimum System Requirements:

 Standard PC with Pentium-III processor


 Installed and running MS-Visual studio 6.0

Program Requirements:

1. A function strlen( ) is used for finding the length of a string. This function can be
implemented by providing it the address of char array in which the string is stored. It
will start counting the number of characters until a null character is found. the
function will return the number of characters that is the length of string excluding null
character.
2. A function strcpy( ) is used for copying a string from one character array to another.
This function can be implemented by providing it the address of source string and the
destination string. It will read a character from source string and copy it to the relative
position in another string until a null character is found. keep in mind that the null
character should also be placed in the destination string.

These functions can be used to perform string manipulation in any sample program. This
is an internal implementation program.

23

You might also like