Sunteți pe pagina 1din 71

LABORATORY MANUAL

Introduction To Computer Science


And
Programming

Name : ________________________________
Reg # : ________________________________
Degree : ________________________________
Semester : ________________________________

_______________
Faculty Signature
Index
S.no Objective of Experiment Remarks Date Signature

1. Introduction to Computer Hardware

Students Feedback :

(a) Every student should individually install MS windows XP on the personal


computer.
2. (b) Every student should individually Formatting of hard disk of the personal
computer.
Students Feedback :

Introduction to MS Word, Importance of MS office 2007/10, overview of


3. toolbars, saving files, rulers, format painter, tables , Charts.
Students Feedback :

Creating project abstract Features to be covered:-Formatting Styles, Inserting


table, Bullets and Numbering, Changing Text Direction, Cell alignment,
4. Footnote, Hyperlink, Symbols, Spell Check, Track Changes.
Students Feedback :

Introduction MS Excel working Environment, Modifying an spread sheet,


working with Formulas and designing chart
5. Creating a Scheduler - Features to be covered:- Formulas, SUM, Percentage,
IF, Nested IF, AND, OR (Marks Sheet).
Students Feedback :

Creating a Scheduler - Features to be covered:- Gridlines, Format Cells,


Summation, auto fill, Formatting Text.
6. Calculating GPA - .Features to be covered:- Cell Referencing, Formulae in excel
– average, std. deviation, Charts, Renaming and Inserting worksheets, Count
function, Sorting, Conditional formatting ..
Students Feedback :

Introduction to MS Access, What Is a Database, Creating a Table, Creating a


7.
Form.
Students Feedback :

To demonstrate the ability to create a database with multiple tables, execute


8.
different queries, and produce reports.
Students Feedback :

Getting familiar with the IDE and working with Turbo C &Microsoft Visual
9. Studio. Installing and copying the compiler, changing directory settings.
Making first program in C. Saving / copying files to USB or other storage
devices.
Students Feedback :

10. Understanding and Using format specifier and escape sequences with printf.
Students Feedback :

Studying different data types, variables, variable names, variable declaration,


11.
variable definitionand variable initialization.
Students Feedback :

Taking Input from the user at console screen using scanf and getche
12.
commands.
Students Feedback :

Arithmetic operators, conditional operators, assignment operators,


13.
Increment/decrement operators. Studying Math functions.
Students Feedback :

Studying loops. For loops, nested for loops, while loops, nested while loops,
14.
do while loops, nested do while loops. Studying loops with cross combination.
Students Feedback :

15. Semester Project

Note: Students are advised to write their comments about whether the objective of the lab was achieved or not in
Student Feedback section.
Experiment 1
Objective: Introduction to Computer Hardware

Assembling the components into a working computer

The following pictures have some slight differences from the instructions. The instructions are for
the standard workstation. The pictures are for a computer that Tanja Lange and I assembled on
2006.01.11, with the following differences from the standard workstation:

There are two disk drives instead of one.


The video card is an Asus V9400-X/TD/128 instead of an Asus V9400-X/TD/64.
The DVD drive is a LiteOn SHM-165P6S-09C, which we found easier to obtain
than the BenQ DQ60BLACK. There's no extra fan. (All the other components
showed up before the extra fan did.)
Assembly was in a slightly different order.

Opening the case. Unpack the computer case. Discard its plastic wrap. Put on an antistatic wrist
strap, and attach it to ground (for example, to the screw on a typical light-switch plate).

http://cr.yp.to/hardware/build-20060107.html

Remove the side of the case by pulling the two side latches towards the front of the
case and then away from the case:
Look for power supply and the proper power cord latches:
Look for processor and Ram Slots. Ram is placed vertically in thin straight slots shown in
above image on left. Whereas processor is a square shaped chip.
Processor
Fan

Heat
Sink

Heat sink is first placed over processor then a fan is placed above it:

Then place the mother board inside the casing with a plastic sheet coating at the
back fixed using screw drivers
Look for proper power cables to power up the motherboard which in turn will provide
power to RAM and Processor (Power Cable used above is suitable for motherboard):
Plug the reset-switch, power-switch, HDD-LED (also known as IDE-LED) and PC
Speaker connectors into the motherboard, all labels facing upwards:

Plug the front Panel USB Port cable into the motherboard:
Plug the video card into the motherboard:
Slide the DVD drive into the case from the front until the drive rails snap into
place. Plug the UATA cable into the blue connector on the motherboard:
Plug a 4-pin power cable into the DVD drive
Experiment 2-a
Objective : Every student should individually install MS windows XP on the personal computer.

PROCEDURE:

1. Keep on press the delete button and go to advanced BIOS feature. [ BIOS- Basic Input
Output System ].
2. And go to boot sequence. Select first boot drivers. CD ROM and press F10 to save the
bios feature. Yes and then enter. Press any key to boot from CD. Press enter to setup
windows XP. F8 = To agree the license.
3. Press ESC to don’t repair the windows XP setup.
4. Press ‘p’ to delete the previous partitions. Then press enter.
5. Press ‘L’ to delete the partition.
6. Press ‘C’ to create the partition in the un partition space.
7. Press enter to setup windows XP on the selected items.
BASIC FILE SYSTEMS:
FAT: File Allocation Table.
NTFS: New Technology File System.
Format the create using NTFS partition

BASIC STEPS IN INSTALLATION:-

 Collecting information.

 Dynamic update.

 Preparing installation

 Installing windows.

 Tracking installation.
Select the language as English (united states), then ok.

Enter your name and organization.


Enter the product key
Enter the computer name and give password (if necessary) then ok.
Then select the date and time.
Then select the typical setting.
Windows XP Installation

Installation process

Installing Windows XP can take up to two hours. To make the process more manageable, it has been
broken up into several sections. When you are ready, install Windows XP:

Part 1: Begin the installation


Part 2: Continue the installation
Part 3: Complete the installation

Part 1: Begin the installation

Insert the Windows XP CD into your computer and restart your computer.
If prompted to start from the CD, press SPACEBAR. If you miss the prompt (it only appears
for a few seconds), restart your computer to try again.

Windows XP Setup begins. During this portion of setup, your mouse will not work, so you must use
the keyboard. On the Welcome to Setup page, press ENTER.

Windows XP Setup begins. During this portion of setup, your mouse will not work, so you must use
the

Keyboard. On the Welcome to Setup page, press ENTER.



On the Windows XP Licensing Agreement page, read the licensing agreement. Press the PAGE
DOWN key to scroll to the bottom of the agreement. Then press F8.

This page enables you to select the hard disk drive on which Windows XP will be installed. Once you
complete this step, all data on your hard disk drive will be removed and cannot be recovered. It is
extremely important that you have a recent backup copy of your files before continuing. When you have
a backup copy, press D, and then press L when prompted. This deletes your existing data.

Windows XP erases your hard disk drive using a process called formatting and then copies the setup
files. You can leave your computer and return in 20 to 30 minutes.

2: Continue the installation

Windows XP restarts and then continues with the installation process. From this point forward, you can
use your mouse. Eventually, the Regional and Language Options page appears. Click Next to accept the
default settings. If you are multilingual or prefer a language other than English, you can change language
settings after setup is complete.
Part 2: Continue the installation

Windows XP restarts and then continues with the installation process. From this point forward, you can
use your mouse. Eventually, the Regional and Language Options page appears. Click Next to accept the
default settings. If you are multilingual or prefer a language other than English, you can change
language settings after setup is complete.


On the Personalize Your Software page, type your name and your organization name. Some
programs use this information to automatically fill in your name when required. Then, click
Next.

On the Your Product Key page, type your product key as it appears on your Windows XP CD case.
The product key is unique for every Windows XP installation. Then, click nex
Part 3: Complete the installation

Windows XP will spend 20 or 30 minutes configuring your computer and will


automatically restart when finished. When the Display Settings dialog appears, click OK.

On the Thank you! Page, click Finish.


Experiment 2-b
Objective : Every student should individually Formatting of hard disk of the personal
computer.

Formatting of hard disk

1. This is the Command Prompt window.

2. From the command prompt, type diskpart and press Enter.

3. The diskpart prompt will open.


4. From the diskpart prompt, type list disk and press Enter.

A list of disks will appear in a text format. You will return to the diskpart prompt. Step
one verified that Disk 1 is the 3TB drive. Warning: Diskpart Erase/Clean will
permanently erase/destroy all data on the selected drive. Please be certain that you
are erasing the correct disk.

5. From the diskpart prompt you will need to select a disk disk number (for instance,
if the 3TB+ drive is Disk 1, you would type select disk 1) and press Enter.Warning:
Diskpart Erase/Clean will permanently erase/destroy all data on the selected drive.
Please be certain that you are erasing the correct disk.
6. A message appears saying that the disk is selected. You will return to the diskpart
prompt. Warning: Diskpart Erase/Clean will permanently erase/destroy all data on
the selected drive. Please be certain that you are erasing the correct disk.

7. From the diskpart prompt, type clean and press Enter. The drive's partition, data,
and signature is now removed. You will return to the diskpart prompt. Warning: Once
you type clean and hit enter the drive will be erased. No warning will be provided.

8. The Command Prompt window will display the message "DiskPart succeeded in
cleaning the disk". Close out of the Command Prompt window by clicking thered X in
the upper right hand corner.

Now the 3TB+ drive can be re-initialized, partitioned, and formatted


Experiment 3
Objective : Word Orientation: an overview of Microsoft (MS) office 2007/ 10: Importance of MS office
2007/10, overview of toolbars, saving files, Using help and resources, rulers, format painter.

INTRODUCTION TO MS-OFFICE

Microsoft office is a set of inter related desk top applications ,servers and services, collectively refers to
as an office suit for the micro soft windows and MAC OSX operating systems .

MS WORD:
Microsoft Word is a word processing software package. we can use it to type letters, reports, and other
documents. In Word 2007, how a window displays depends on the size of your window, the size of Your
monitor and the resolution to which your monitor is set. Resolution determines how much information
your computer monitor can display.

STARTING MS WORD:-

Two ways of starting MSWORD:-

Double click on Microsoft word icon on the desk top.

Click on start ->programs->ms office ->ms word.


The Microsoft Office Button
In the upper-left corner of the Word 2007 window is the Microsoft Office button. When you click the
button, a menu appears. You can use the menu to create a new file, open an existing file, save a file,
and perform many other tasks.

The Quick Access Toolbar


The Quick Access toolbar provides you with access to commands you frequently use. By default
Save,Undo, and Redo appear on the Quick Access toolbar. You can use Save syour file, Undo to
rollback an action you have taken, and Redo to reapply an action you have rolled back.

The Ribbon
We use the Ribbon to issue commands. The Ribbon is located near the top of the screen, below the
Quick Access toolbar. At the top of the Ribbon are several tabs; clicking a tab displays several related
command groups. Within each group are related command buttons. You click buttons to issue
commands or to access menus and dialog boxes
The Ruler
We can use the ruler to change the format of your document quickly

The Text Area


You type your document in the text area. The blinking vertical line in the upper-left corner of the text
area is the cursor.

The Status Bar


The Status bar appears at the very bottom of your window and provides such information as the
current page and the number of words in your document.

Assignment :

Make your Curriculum Vitae using MS Word which includes objective, academic qualification, skills,
field of interest, projects and two references and also insert a picture in it.
Experiment 4
Objective : Creating project abstract Features to be covered:-Formatting Styles, Inserting table,
Bullets and Numbering, Changing Text Direction, Cell alignment, Footnote, Hyperlink, Symbols,
Spell Check, Track Changes.

To create a document applying the above mentioned techniques.

THEORY:

Table: A table consists of rows and columns.

Cell Alignment:
Aligns contents written in a table in the top left corner or top right corner or in the center etc.

Foot Note:
Foot notes are used to comments on, or provide references for text in a document.

Hyperlink:

It is a colored and underlined text or a graphic that you click to go to a file, a location in a file , an
HTML page on the world wide web, or an HTML page in an intranet.
Symbols:
You may not be able to enter certain symbols into your word document, as there is a limitation on
the keys on the key board. Creating these new symbols especially when working with mathematical
terms it becomes very difficult .For example we can insert symbols such as,,,

Spell check:
It automatically checks for spelling and grammatical errors

Bullets and Numbering:


In Microsoft word we can easily create bulleted or numbered list of items.

Formatting Style:
A style is a set of rules to be followed for the effective document. Style can be applied to text,
paragraph, table or a list.

Changing text direction:


You can change the text orientation in drawing objects, such as text boxes, shapes, and callouts, or
in table cells so that the text is displayed vertically or horizontally.

Track changes:
Track changes is a an excellent feature of Microsoft word as it enables a user or reviewer to keep
track of the changes that have taken a period. Changes like insertion, deletion or formatting changes
can be kept track of.
Procedure:

Changing Text direction:

Click the drawing object or table cell that contains the text you want to change.
On the Format menu, click Text Direction.
Click the orientation you want.

Table:
Click where you want to create a table.
On the Table menu, point to Insert, and then click Table.
Under Table size, select the number of columns and rows.
Under AutoFit behavior, choose options to adjust table size.
To use a built-in table format, click AutoFormat.

Select the options you want

Cell Alignment:

Click the cell that contains text you want to align.


On the Tables and Borders toolbar, select the option for the horizontal and vertical alignment
you want— for example, Align Bottom Center or Align Top Right.

Foot Note:

1. In print layout view, click where you want to insert the note reference mark.
2. On the Insert menu, point to Reference, and then click Footnote.
3. Click Footnotes or Endnotes.

By default, Word places footnotes at the end of each page and endnotes at the end of the
document. You can change the placement of footnotes and endnotes by making a selection in the
Footnotes or Endnotes box.

4. In the Number format box, click the format you want.


5. Click Insert.

Word inserts the note number and places the insertion point next to the note number.

6. Type the note text.


7. Scroll to your place in the document and continue typing.
8. As you insert additional footnotes or endnotes in the document, Word automatically applies
the correct number format.

Hyper link:
Select the text or picture you want to display as the hyperlink, and then click Insert Hyperlink on the
Standard toolbar

Do one of the following:


1. Link to an existing file or web page:
1. Under Link to, click Existing File or Web Page.
2. In the Address box, type the address you want to link to or, in the Look in box, click
the down arrow, and navigate to and select the file
2. Link to a file you haven’t created yet
Under Link to, click Create New Document.

An e-mail address:
1. Select the text or picture you want to display as the hyperlink, and then click Insert Hyperlink
on the Standard toolbar
2. Under Link to, click E-mail Address.
3. Either type the e-mail address you want in the E-mail address box, or select an e-mail address
in the recently used e-mail addresses box.
4. In the Subject box, type the subject of the e-mail message
A specific location in another document

1. Insert a bookmark in the destination file or Web page.


2. Open the file that you want to link from, and select the text or object you want to display as
the hyperlink.
3. On the Standard toolbar, click Insert Hyperlink .
4. Under Link to, click Existing File or Web Page.
5. In the Look in box, click the down arrow, and navigate to and select the file that you want to
link to.
6. Click Bookmark, select the bookmark you want, and then click OK.

Symbol:

1. Click where you want to insert the symbol.


2. On the Insert menu, click Symbol, and then click the Symbols tab.
3. In the Font box, click the font that you want.
4. Double-click the symbol that you want to insert.
5. Click Close

Spell check: On the Standard toolbar, click Spelling and Grammar .

1. When Word finds a possible spelling or grammatical problem, make your changes in the
Spelling and Grammar dialog box.

Bullets and Numbering:

1. Type 1.to start a numbered list or * (asterisk) to start a bulleted list, and then press
SPACEBAR or TAB.
2. Type any text you want.
3. Press ENTER to add the next list item. Word automatically inserts the next number or bullet.
4. To finish the list, press ENTER twice, or press BACKSPACE to delete the last bullet or number
in the list

Formatting Styles:

1. Select the words, paragraph, list, or table you want to change.


2. If the Styles and Formatting task pane is not open, click Styles and Formatting on the
Formatting toolbar
3. Click the style you want in the Styles and Formatting task pane.
If the style you want is not listed, click All Styles in the Show box

Track Changes:

1. Open the document you want to revise.


2. On the Tools menu, click Track Changes.

Assignment :

Make a Student’s Schedule using tables and text box in MS Word. Mention the student’s ID, name,
semester, degree, name of registered courses, Faculty name, class timing, days and location.
Experiment 5
Objective : Introduction MS Excel working Environment, Modifying an spread sheet, working with
Formulas and designing chart

Step 1. Preparing to enter an equation You are


ready to build your own function (an
equation). There is a single keystroke that
informs Excel of your intention. Press the
equal key (=). If you can write the
equation, Excel can perform the
calculation. This module will deal with
four simple functions; add, subtract,
multiply and divide.

Step 2. Writing an addition equation If you were to state the process for
adding the numbers in column B it would be "six plus three." The
equation could be written exactly like that (=6+3) and Excel would
display the expected answer, 9. However that equation would be
useless if the numbers in either B2 or B3 were changed. When
writing your own equation, use cell addresses.
=B2+B3
When writing the equation, clicking in cell B2 displays B2 in the equation. If you have written the
equation correctly you may accept it by pressing the Enter/Return key or by clicking on the green
check mark. If you change your mind, click on the red X to cancel the operation.

Step 3. Writing other simple functions


Symbols for the four basic mathematical functions are:
addition +
subtraction -
multiplication *
division /

Step 4. Task Prepare a worksheet with the data displayed under Step 1. Enter the proper equation
under each set of two numbers. Do not look at step 5.

Step 5. Compare Compare your results to those shown below:


Step 6. Combining functions If you can write the equation, Excel can perform the math. To
illustrate this we will write an equation which will add several numbers, divide to get an
average, and then take a percentage of that number to provide a weighted component of
an equation used to average grades.

Scenario: Bill took three tests scoring 88, 76, and 58. The average of his tests counts as half of Bill's
grade. What number value has Bill achieved toward his term grade?

Assignment
Make a Sheet on excel as given below and fill the empty cells by using given information .

Salary Sheet of ABC Industries


House Rent = 20% of the basic salary Gross Salary = Basic + House rent + Transport Allownce
Transport Allownce = 14% of the basic salary Net Salary = Gross Salary - PF Contribution - Income Tax
PF contribution = 10 % of the basic salary
Income Tax = 17% of the basic salary

Name Basic salary House Rent Transport Allownce Gross salary PF Contribution Income Tax Net Salary
Ali 34100
Sami 33205
Eshal 78428
Farhan 48004
Faiza 64452
Salman 60977

Average Net Salary of Employee =


Experiment 6
Objective :
Creating a Scheduler - Features to be covered:- Gridlines, Format Cells, Summation, auto fill,
Formatting Text.
Creating a Scheduler - Features to be covered:- Formulas, SUM, Percentage, IF, Nested IF, AND, OR
(Marks Sheet).Using an Excel worksheet - Using Equations.

Step 1. Review percent Before showing how to calculate percent with Excel, let's review how to
calculate percent.
A number divided by a second number and multiplied by 100 expresses what percent the first
number is of the second number. If you do not multiply by 100 you have the decimal
equivalent of percent.
Step 2. Writing a percent equation for only two numbers
Solve the following: 2 is what percent of 8?

Now that you are sure you remember the process for calculating percent, use an Excel worksheet to
perform the calculations.

Step 3. Writing a percent equation for a column of numbers


accompanied by a sum. Data from the ice cream survey will be
used to illustrate how to calculate percentage.

Task: Determine what percent 6 is of 24 by putting the equation into cell


C2 of a worksheet similar to the one above.

Step 4. Auto Fill and problems associated with it


You probably remember a discussion of Auto Fill on a previous
module. That is a convenient way to place information in several cells at
the same time. That might sound like a very good way to fill the
equation into cells C3 through C9. For instructive purposes we will do
that now to see the problem it causes.
Oops! Something wrong there. The problem was caused by the way the equation was written. The
equation B2/B10 says, "take the first cell in this equation and divide it by the cell 8 spaces below."
The reason that none of the other equations work is that there is nothing in the cell 8 spaces below
any of the cells from B3 to B10. We must find a way of telling Excel to use call B10 to divide by for
each of the other 8 equations.

Step 5. Absolute Cell Reference You tell Excel to use one specific cell,
and never move to another relative location in the
calculations by using "absolute cell reference." To specify the
cell, place a dollar sign before the column letter and before
the row number. Thus, $B$10 says always use cell B10. Lets
go back to the worksheet and re-write the equation in C2.
Notice the answer has not changed. If we were writing only this one
equation, we wasted time using absolute cell reference. The real
benefit of this equation will be seen when you fill down into cells C3
through C10.

Step 6. Fill the equation down into the cells below As soon as you fill this equation with an absolute
cell reference down into cells C3 through C10, the percentages are instantly calculated. Only
one more task remains.

Step 7. Format the cells Unless you need five decimal places, I suggest formatting cells C2 through
C10, the highlighted range above, so that one decimal place is displayed.
Right-click on the highlighted range of cells, and select Format Cells...

In the category list select Number, and in the Decimal places: box
use the down arrow to choose 1.

Click OK, your column of data has a nice uniform appearance.


Creating a Chart or Graph If Excel is already open on your workstation open a new Excel workbook, There
are three ways to do that.

Step 1. Launch Excel


1. Go to the Standard toolbar and click on the New Workbook button.

2. Go to the File menu and select New.

3. Use a keyboard combination: on a Macintosh use Command + N and on a Windows computer


use Ctrl + N

Step 2. Enter the data to be graphed.


For the purpose of this lesson you will use data from a Favorite Fruit
Survey. Enter it as you see below:

Step 3. Highlight data to be graphed. Do not include the row with heading titles, only the
names of fruit and the numbers. If your worksheet looks like the one above; put
your cursor in call A2, click hold the mouse button down and drag to cell B7.
Highlighted data should look like the image below:

Note: Cell A2 is selected, the select color extends around the cell
Step 4. Select the Chart Wizard. That is done by going to the Insert menu and selecting Chart. You

can also click on the Chart Wizard button on the Standard toolbar.

Step 5. From the Chart Wizard box that opens select Chart type. For this activity, I selected pie.

After you have selected the Chart type, click and hold your mouse pointer down on the Press and Hold...
button to see what your data looks like in the chart type you selected. If you do not like the look, select
another chart type. After you have selected the chart type you will have two options:
Select Next and let Chart Wizard show you a series of options to make changes to your chart.
The second step taken by Chart Wizard is to verify the range of data being used for this chart. The
Data range displayed below is read "all cells from A2 to B7."

Notice where the cursor is located in the dialog box above. It is pointing to the small box at the end of
the line where the Data range is displayed. If the data range should be changed, click on the box the
cursor is pointing to.
Select Next to go to the dialog box below. This box allows you to add a title to the chart, make
changes on the legend, or make changes on the data labels.
Select Finish and Chart Wizard puts your completed chart on the spreadsheet.

Select Next to move to the final dialog box which allows you to see the chart as a new sheet or place it
on one of the sheets in your workbook.

If you let the Chart Wizard finish your chart after the first dialog box, or work through each of the four
steps, your chart will look something like the one Below
Assignment :
Course Credit Hrs. Total Marks Obtained Marks Percentage Grade GPA
ICS Theory 3 100
ICS lab 1 100
App. Physics 3 100
Calculus 3 100
English 2 100

(a) Find GPA and Grade in each course if the following grading system will be followed.

(b) Find the CGPA.

(c) By using conditional formatting, If student got below 60% marks then the grade and GPA cell
should turn red otherwise green.

Criteria of grading system shown below

Percentage GPA Grade

88% – 100% 4.0 A

81% – 87% 3.5 B+

74% – 80% 3.0 B

67% – 73% 2.5 C+

60% – 66% 2.0 C

Below 60% 0.0 F


Experiment 7
Objective
MS Access : Introduction to MS Access, What Is a Database, Creating a Table, Creating a Form

Starting Microsoft Access


Two Ways
Double click on the Microsoft Access icon on the desktop.
Click on Start --> Programs --> Microsoft Access

Creating New, and Opening Existing Databases


The picture on right gives you the option to:
Create a New Database from scratch
Use the wizard to create a New Database Open
an existing database, The white box gives you
the most recent databases you have used. If
you do not see the one you had created,
choose the More Files option and hit OK.
Otherwise choose the database you had
previously used and click OK.
Create a database using the Database Wizard
1. When Microsoft Access first starts up, a dialog box is automatically displayed with options to
create a new database or open an existing one. If this dialog box is displayed, click Access
Database Wizards, pages, and projects and then click OK.
2. If you have already opened a database or closed the dialog box that displays when Microsoft
Access starts up, click New Database on the toolbar.
3. On the Databases tab, double-click the icon for the kind of database you want to create.
4. Specify a name and location for the database.
5. Click Create to start defining your new database
Create a database without using the Database Wizard
1. When Microsoft Access first starts up, a dialog box is automatically displayed with options to
create a new database or open an existing one. If this dialog box is displayed, click Blank
Access Database, and then click OK.
If you have already opened a database or closed the dialog box that displays when Microsoft
Access starts up, click New Database on the toolbar, and then double-click the Blank Database
icon on the General tab.
2. Specify a name and location for the database and click Create. (Below is the screen that shows up
following this step)

Tables
A table is a collection of data about a specific topic, such as students or contacts. Using a separate
table for each topic means that you store that data only once, which makes your database more
efficient, and reduces data-entry errors.
Tables organize data into columns (called fields) and rows (called records).
Create a Table from scratch in Design view
1. If you haven't already done so, switch to the Database Window You can press F11 to switch to the
Database window from any other window.

2. Double-Click on "Create table in Design view".


(DESIGN VIEW)

3. Define each of the fields in your table.


a. Under the Field Name column, enter the categories of your table.
b. Under Data Type column, enter the type you want for you categories.
i. The attribute of a variable or field that determines what kind of data it can hold. For
example, in a Microsoft Access database, the Text and Memo field data types allow the
field to store either text or numbers, but the Number data type will allow the field to store
numbers only. Number data type fields store numerical data that will be used in
mathematical calculations. Use the Currency data type to display or calculate currency
values. Other data types are Date/Time, Yes/No, Auto Number, and OLE object (Picture).
c. Under the Description column, enter the text that describes what you field is. (This field is
optional).
4. For our tutorial enter the following items:

Primary Key
One or more fields (columns) whose value or values uniquely identify each record in a table.
A primary key does not allow Null values and must always have a unique value. A primary key
is used to relate a table to foreign keys in other tables.
NOTE: You do not have to define a primary key, but it's usually a good idea. If you don't define
a primary key, Microsoft Access asks you if you would like to create one when you save the
table.
o For our tutorial, make the Soc Sec # field the primary key, meaning that every student has a
social security number and no 2 are the same.
o To do this, simply select the Soc Sec # field and select the primary key button

o After you do this, Save the table

Entering Data
Click on the Datasheet View and simply start "chugging" away by entering the data into each field.
NOTE: Before starting a new record, the Soc Sec # field must have something in it, because it is the
Primary Key. If you did not set a Primary Key then it is OK.
Experiment 8
Objectives : To demonstrate the ability to create a database with multiple tables, execute different queries,
and produce reports.

Problem
An auto repair shop needs to maintain information on its jobs and customers. The shop specialises in repair
jobs for local car dealers. The database it uses consists of two tables. The Jobs table contains data on jobs the
repair shop either has started or has completed for each customer. The Customers table contains pertinent
data about the auto repair shop’s customers.

Instructions:
1. Create a new database to store the two tables related to the auto repair shop. Call the database Repair
Shop.

2. Import the Jobs data from the excel spreadsheet provided on eLearn. Make the Job ID the primary key, no
duplicates. Call the table Jobs. Configure the table using the structure shown in Table 1.1.

3. Import the Customers data from the excel spreadsheet provided on eLearn. Make the Customer ID the
primary key, no duplicates. Call the table Customers. Configure the table using the structure shown in Table
2.1.

4. Create a report using the Jobs table that consists of the Job ID, Job Description, Completion Date, and
Quote. Title the report Job Summary Report. The beginning of your report should be similar to the on shown
in Figure 4.1.

Figure 4.1: Beginning of your Job Summary Report.

5. Using query, generate the list of incomplete and complete jobs using the Jobs table. The results should be
similar to those shown in Figure 5.1 and 5.2.
Figure 5.1: List of complete jobs.

Figure 5.2: List of incomplete jobs.

6. Using query, generate the list of customers who owe the company money (assuming that they will only pay
you after the jobs have completed). The results should be similar to the one shown in Figure 6.1.

Figure 6.1: The amount each customer owes the company.

7. Using query, generate the list of customers (with their contact details) whose their jobs have completed.
The results should be similar to the one shown in Figure 7.1.

Figure 7.1: The list of customers (with their contact details) whose their jobs have completed.

8. Using query, generate the list of customers (with their contact details) whose their jobs are incomplete, and
show the expected completion date. The results should be similar to the one shown in Figure 8.1.

Figure 8.1: The list of customers (with their contact details) whose their jobs are incomplete.
9. Generate invoice for each completed job for each customer. The invoice (report) should be similar to those
shown in Figure 9.1 and 9.2. [Hint: You will have to modify the report template to achieve this. If you have
done it correctly, you should be able to observe in Print Preview that the invoice for each customer is
separated.]

Figure 9.1: Invoice for Jack’s Timeless Classics.

Figure 9.2: Invoice for Keith’s Sports Cars, Inc.


Table 1.1: Structure of the Jobs table.

Field Name Data Type Field Size Primary Key? Description

Job ID Short Text 4 Yes Job number (primary key)


Customer ID Short Text 3 Customer ID number
Job Description Short Text 25 General job description
Job Status Short Text 1 Status of complete (C) or incomplete (I)
Completion Date Date/Time Date job is to be completed
Quote Currency Customer’s cost for job
Table 1.2: Data for the Jobs table.

Job ID Customer ID Job Description Job Status Completion Data Quote


M345 JMS Grill Work - 67 Chevy I 6/30/05 2200
M653 KSI Rebuild Tran - 73 Merc C 5/12/05 2685
B423 KSI Bumper Repair - 55 Nash I 9/21/05 400
B746 ROM Valve Job - 68 Falcon C 4/15/05 700
M236 TRW Brake Drums - 69 Linc I 6/15/05 2400
M965 JTC Re-paint - 39 Ford C 3/1/05 1057
B474 ROM Door Panels - 71 Falcon C 3/27/05 300
B559 JMS Heater Repair - 63 Ford I 5/6/05 460
B365 JTC Windshield Repair - 66 PU I 7/22/05 400
M547 NQR Floor Boards - 71 Chevy I 9/30/05 2500
B147 NQR Muffler - 75 LTD I 6/26/05 250
B338 JMS Tie-rods - 78 GTO C 4/17/05 10
M482 KSI Shockes - 78 Pontiac C 7/21/05 660
B628 JTC Gas Tank - 75 Pinto I 8/16/05 420
B553 ROM Trunk Deck - 65 Galaxy C 9/4/05 1080
M182 JTC Overhaul - 83 LTD C 8/12/05 990
B527 JMS Brake Cyl. - 80 Fairlane I 9/21/05 890
M982 NQR Muffler - 72 Corvette I 10/12/05 580
M522 JTC Tune-up - 71 Lincoln C 4/30/05 490
B932 JMS Manifold - 37 P-Arrow I 10/16/05 385

Table 2.1: Structure of the Customers table.

Field Name Data Type Field Size Primary Key? Description

Customer ID Short Text 3 Yes Customer number (primary key)


Customer Name Short Text 25 Customer name or dealer name
Contact Person Short Text 20 Contact person
Telephone Short Text 8 Contact telephone number

Table 2.2: Data for the Customers table.

Customer ID Job Description Job Status Completion Data


JMS Jacob's Motor Sales Jacob Daniels 555-3451
KSI Keith’s Sports Cars, Inc. Keith Moorehouse 555-6639
ROM Randy's Od Makes Randy Petersen 555-7877
TRW Trevor's Rolling Wheels Trevor Craig 555-2258
JTC Jack's Timeless Classics Jack Johnson 555-9111
NQR Nick's Quick Rides Nick Stone 555-8890

Assignment :

You have been asked to create a small information system to administer the records of a small educational
institution using MS Access. The following details need to be stored: students' surname, first name, date of
birth, the date they enrolled in the institution, papers available for study, including the paper code and paper
title, the enrolments of students in particular papers, including date of enrolment, mark gained, and fee
charged.

Create a database with the appropriate number of tables to store the above data and establish appropriate
relationships between them.
Experiment 9
Objective
Getting familiar with the IDE and working with Turbo C &Microsoft Visual Studio. Installing and copying the compiler,
changing directory settings. Making first program in C. Saving / copying files to USB or other storage devices.

Theory

IDE
An integrated development environment (IDE) is a software suite that consolidates the basic tools developers need
to write and test software. Typically, an IDE contains a code editor, a compiler or interpreter and a debugger that the
developer accesses through a single graphical user interface (GUI). An IDE may be a standalone application, or it
may be included as part of one or more existing and compatible applications.

There are different IDE‟s to write C program. Following are the two most common;
1. Turbo C
2. Microsoft Visual Studio

1. Turbo C
Turbo C is a discontinued Integrated Development Environment and compiler for the C programming language from
Borland. First introduced in 1987, it was noted for its integrated development environment, small size, fast compile
speed, comprehensive manuals and low price.In May 1990, Borland replaced Turbo C with Turbo C++.
The use of this IDE on latest OS has become very difficult as a lot of libraries are not supported any more. The use of
this IDE is depreciated.

Working with Turbo C


Click on Start Run
and type the path
\\fileserver\Softwares\Programing Languages Section

A new window will open. From there right click on the folder named as TC3 and select copy. Now Paste in it in your C
or D partition or your USB drive. As a good approach C drive is normally not recommended for C compiler as C drive is a
windows system partition.
Assuming that the folder has been copied in the root of D drive, open D: p artition - TC3 folde r - BIN –
Double click and open any one of the two TC.exe icons (as shown on right).
The window that opens is the known as the IDE of Turbo C (as shown bel

Figure 1.1: Turbo C

Figure 1.2: Turbo C IDE


This IDE window further contains two more windows and a standard tool bar. The blue window is known as the text editor
which is used to write the programs. And the Light bluish green window at the bottom is the message box which will
display the error or other messages.
Before using the IDE there are few parameters and checks which need to be reviewed every time the IDE of windows is
used. Make sure that the folder of TC3 (also known as compiler) has been copied in the root drive i.e. in the first
window of any partition and not in sub folders. e.g.

D:\TC3 is correct but D:\TC3\CP\C language\Class work\TC3 is incorrect.

Opening a new File


Close all windows in the Turbo C IDE (if there are any) by clicking in the small green box on the right top corner of each
window .
On the standard tool bar click file, select new. A new Blue window appears.

Saving a New File


Press F2 key to save this file. Make sure the path where you save this file is same as of compiler
e.g. D:\TC3\BIN
this path is visible at the bottom of save window. The name of the file will always be followed by .cpp extension (dot cpp).

Opening an existing file


To open any previously saved file, click File, select open, in the path option type D:\TC3\BIN\*.*
Asteric means all. The asteric before the dot means all file names and the asteric after the dot means all file types.
*.cppmeans all files with dot cpp extension.

Setting Directory Paths (to be checked each time the Turbo IDE is opened)
Once you have opened and saved a new file some directories need to be changed according to the location of your
compiler in your computer otherwise the compiler make not work properly.
On the standard toolbar click on options then directories. Set the first letter of the first two paths (i.e. Include Directories
and Library Directories) according to the location of the compiler or say the letter of the directory where you copied your
compiler. The other two paths (i.e. Output Directories and Source Directories) will remain blank. e.g.

Figure 1.3: Turbo C - Directory Paths

Compilation and Output


After you have written the program press Ctrl+f9 to compile and check the output.
Alt+F5 key is used to display the output for last compilation.
Technical Exits
To minimize the screen of Turbo C editor press Alt+Enter.
If some where the program hangs up compiler at output or gets busy without passing control to programmer press
Ctrl+Pause\Break.
2. Microsoft Visual Studio
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer
programs for Microsoft Windows, as well as web sites, web applications and web services. Visual Studio uses Microsoft
software development platforms.

Visual Studio includes a code editor supporting IntelliSense as well as code refactoring. The integrated debugger works
both as a source-level debugger and a machine-level debugger. Visual Studio supports different programming
languages and allows the code editor and debugger to support nearly any programming language. Built-in languages
include C, C++, VB.NET, C# and F#.

Working withMicrosoft Visual Studio

Open Microsoft Visual Studio by double clicking on the Icon. The icon similar to the following (depending upon the version)
should be available on your desktop.

Figure 1.4: Visual Studio 2013

The application will run and following window will appear.

Figure 1.5: Visual Studio Start Page

We first have to create a project. To create a new project, click on “New Project” option present on the left side. A
Window similar to the one shown below will appear. Expand the template option present on left side of the window.
Select “Visual C++” and under this, select “General” option. Select first option “Empty Project” from the middle
section. Provide name for the project as “Lab1” and press OK.
Figure 1.6: Create new project

After you click OK, following screen will be displayed which has a Solution Explorer on the right hand side. This panel will be used to
access all the files of the project.

Figure 1.7: Solution Explorer

Now right click on your project “Lab1, and go to Add and then select New item, refer to the screenshot below.
Figure 1.8: Add new item

A window similar to one given below will appear. Select Visual C++ and code from the left panel. Select C++ f ile from
the middle panel. Give a name to your source file. This will by default create a file with .cpp extension which
represents(C++) but we have to create a C file. Change the extension to .c and click Add.

Figure 1.9: Create a C file


Your file will appear in solution explorer under folder Source Files.

Figure 1.10: File created under Source Files

Now you can simply add a C program and execute the file.

First C Program

Figure 1.11: Basic C Program

#include<stdio.h>
#include<conio.h>
The first line of this program is #include<stdio.h> . Here #include tells the compiler to include something and stdio means
Standard Input/Output where as .h means that it is a header file or in short we are including standard input/output header
file. In the same way the next line is similar to the first one but it has conio.h in it where conio means the black colour
console screen where we see our output and .h tells us that this is a header file. In other words we tell the compiler that
we are including two files and the code we will write will be of c language as the compiler also supports C++ code.

void main(void)
This is third line. The first word in this is void which means any thing that has no value or is useless. The next word is
main which is the brain function and is the only function readable in most programming languages. All the other functions
are called within the main function. The third word within brackets is also void. The first void means that the main function
won‟t return any value while the second void means that the main function is not going to accept any value. This complete
line means that we have declared the main function here. For example a simple calculator takes two or more numbers
from you and returns the result like addition, subtraction, multiplication etc. It may be confusing at this time to understand
the void functionality but in experiment 11 we will discuss it in detail.
{
Following the main function line is a curly bracket which marks the starting of mains body. Always remember that if any
bracket is opened in C language it needs to be closed hence the last line of the above program marks the ending of main
function.

clrscr();
This is the first function called inside the main body. All functions will always have a round brac ket closing „)‟ and a
semicolon „;‟ at their end. In that way we easily recognize the number of functions in a program. According to this rule we
can identify 3 functions in this program. However other properties in different functions may differ but this identity will be
common in all functions. clrscr is short form of clear screen. It clears the screen of any previous output. If not used wont
create any error but output will show all previous compilation result.

printf(“My First Program”);


This line has another function known as printf which is used for printing. Within the double quotes is the main body of this
function where any character may be printed.

getch();
This is the last function of this program. Its name is short form of get character. Its purpose is to get a character. Its used
in last to stop the program until a character is entered. If not used wont show any error but the output will not stop after
compilation. In this case the output is checked manually by pressing Alt+F5 key.

The C program given above will give some compile time errors in Visual Studio. Write following code in the .c file.

#include<conio.h>
#include<stdio.h>

void main()
{
system("cls");
printf("My First Program");
_getch();
}

Save this file (Ctrl + s). Click on the green play icon present on top of the screen to compile and execute your first program.

Figure 1.12: Execute the Code


A black window will appear which is called console. The console will display the output of your program.

Figure 1.13: Program Output

Note: There are few functions of old C which is no more available in latest IDEs like clrscr(). Replace clrscr() with
system("cls") and getch() with _getch().
Example
Program
Output
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{ My First Program
system(“cls”);
printf("My First Program");
_getch();
}

Exercise
Carefully look at the following programs and write the output.
Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
void main(void)
{
printf("My First Program");
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
void main(void)
{
_getch();
printf("My First Program");
}
#include<stdio.h> Write the output for the program on left
#include<conio.>
void main(void)
{
_getch();
printf("My First Program");
_getch();
}
#include<stdio.h> Write the output for the program on left
#include<conio.h
#include<stdlib.h>
void main(void)
{
_getch();
system(“cls”);
printf("My First Program");
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
_getch();
printf("My First Program");
system(“cls”);
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
_getch();
system(“cls”
printf("My First Program");
_getch();
}
Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
_getch();
printf("My First Program");
_getch();
system(“cls”);
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
_getch();
printf("My First Program");
_getch();
}
#include<conio.h> Write the output for the program on left
#include<stdio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
printf("My First Program");
_getch();
}
#include”conio.h” Write the output for the program on left
#include”stdio.h”
#include”stdlib.h”
void main(void)
{
system(“cls”);
printf("My First Program");
_getch();
}
#include<conio.h> Write the output for the program on left
#include<stdio.h>
#include<stdlib.h>
main()
{
system(“cls”);
printf("My First Program");
_getch();
}
#include<CONIO.H> Write the output for the program on left
#include<STDIO.H>
#include<STDLIB.H>
void main(void)
{
system(“cls”);
printf("My First Program");
_getch();
}
Assignment :

Write a C program using commands described in this lab to make a resume showing your
complete details.

Assignment:

Using the program below, make a resume showing your complete details.
Program:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
printf("\n****************************RESUME****************************");
printf("\n******************************CV******************************");
printf("\n**************************************************************");
printf("\n==============================================================");
printf("\nName : Abc");
printf("\nFathers Name : Xyz");
printf("\nDate of Birth : dd-mm-yyyy");
printf("\nAddress : Engineering Department, Main Campus, Iqra University,");
printf("\n Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCNIC : XXXXX-XXXXXXX-X");
printf("\nGender : Male");
printf("\nHSC (College\\Board) : Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : August 2005 ");
printf("\nSSC (School\\Board) : Science, Iqra School, Karachi Board");
printf("\nSSC Year : August 2003 ");
_getch();
}
Experiment 10
Objective
Understanding and Using format specifier and escape sequences with printf.

Theory
The C library function printf() sends formatted output to stdout.Following is the declaration for printf() function.
int printf(const char *format, ...)

format − This is the string that contains the text to be written to stdout. It can optionally contain embedded format tags that are
replaced by the values specified in subsequent additional arguments and formatted as requested.

Format specifiers are used to substitute and print values inside a printf or scanf statement which are further applicable on
variables. Below is a chart of format specifier examples using printf.

No. Type Syntax Value Example


1 Single Character %c One character within single quotes printf(“%c”,‟a‟);
2 String %s A sentence of an unfixed length within double quotes printf(“%s”,”Iqra Univ”);
3 Decimal Integer %d Any whole number between -32,768 to 32,767 printf(“%d”, 12345);
4 Long Integer %ld Any number between -2,147,483,648 to 2,147,483,647 printf(“%ld”,1234567);
-38 38
5 Float %f Any decimal point number between 1 0 to 1 0 printf(“%f”, 1234.567);
308
6 Double %lf Any decimal point number between 10-308 to 10 printf(“%lf”,12345678);

Escape Sequences are used to adjust spacing between lines or characters or the characters themselves.

No. Syntax Application Example


1 \n New Line printf(“\n”);
2 \t Tab eight spaces to right printf(“\t”);
3 \b Back space One space back printf(“\b”);
4 \r Carriage return Start of same line printf(“\r”);
5 \‟ Printing single quote printf(“\‟”);
6 \” Printing double quotes printf(“\””);
7 \\ Printing back space printf(“\\”);
8 \xdd Printing characters by Hexa decimal ASCII value printf(“\x45”);
9 \ddd Printing characters by decimal ASCII value printf(“\d45”);

Example
Program Output
#include<stdio.h>
#include<conio.h>
void main(void)
{ a
Iqra University
printf("\n%c",'a'); 20
printf("\n%s","Iqra University"); 35.500000
printf("\n%d",20); 1234567
printf("\n%f",35.5);
pri ntf("\n%ld", 1234567);
_getch();

}
#include<stdio.h>
#include<conio.h>
void main(void)
{

printf("\n%c %s %d %f %ld",'a',"Iqra University",20,35.5,134567);


_getch();
}
Write the output for following programs and give reasons.
Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
printf("\n%d",'a');
printf("\n%s","Iqra University");
printf("\n%c",20);
printf("\n%f",35.5);
pri ntf("\n%ld", 1234567);
_getch();
}

Assignment:
Use the program below to make your resume with format specifiers and escape sequences showing your
complete details.

Program:

#include<stdio.h>
#include<conio.h>
void main(void)
{
printf("\t\t\t\n****************************RESUME****************************");
printf("\t\t\t\n******************************CV******************************");
printf("\t\t\t\n**************************************************************");
printf("\t\t\t\n==============================================================");
printf("\nName : %s","Abc");
printf("\nFathers Name : %s","Xyz");
printf("\nDate of Birth : %d-%d-%d",11,11,1989);
printf("\nAddress : %s","Engineering Department, Main Campus, Iqra University,");
printf("\n %s","Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCell Phone : 0%d-%ld",300,1234567);
printf("\nCNIC : %d-%ld-%d",12345,1234567,1);
printf("\nGender : %s","Male");
printf("\nHSC (College\\Board) : %s","Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : %s %d","August",2005);
printf("\nSSC (School\\Board) : %s","Science, Iqra School, Karachi Board");
printf("\nSSC Year : %s %d","August",2003);
_getch();
}
Experiment 11
Objective
Studying different data types, variables, variable names, variable declaration, variable definitionand variable initia lization.

Theory
Variables are declared by first writing
data types followed by a variable name, e.g.
int a=10;

Here

int is data type,


a is variable name
and after the equals to sign (=) is the value in it 10
the value is always followed by a terminator(;)

Supported Example
No. Data Type Syntax format Specifier Value
1 Single Character char %c One character within single quotes char a=‟a‟;
2 Decimal Integer int %d Any whole number between -32,768 to 32,767 int a=10;
3 Long Integer long int %ld Any number between -2,147,483,648 to 2,147,483,647 long int a=12345;
-38 38
4 Float float %f Any decimal point number between 10 to 10 float a=1234.567;
0-308 308
5 Double double %lf Any decimal point number between 1 to 10 double a=1 23456;

Variable Names
Variable names will always start with an alphabet.
Variable names can contain numbers (1,2,45,66) and underscores (_) but no other special characters (!@#$%^&*).
Variable names cannot resemble to any predefined word e.g. include, printf, getch, scanf etc..
A variable name cannot be used for multiple declarations.

Example
Program Output
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{ a
system(“cls”); 12
char a='a'; 1234567
12.5000
int b=12; 00
float c=12.5;
double d=1234567;
printf("%c %d %f %lf",a,b,c,d);
_getch();
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
char a='a',a1=’b’;
int b=12,b1=13;
float c=12.5,c1=13.5;
double d=1234567,d1=1234568;
printf("\n%c %d %f %lf",a,b,c,d);
printf("\n%c %d %f %lf",a1 ,b1 ,c1,d1);
_getch();
}
Write the output for following programs.

Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
char a=97;
int b=’A’;
float c=12.5;
double d=1234567;
printf("%c %d %f %lf",a,b,c,d);
_getch();
}

Assignment:
Using the program below, make a resume with format variables showing your complete details.

Program
#include<stdio.h>
#include<conio.h>
void main(void)
{
int dd,mm,yyyy,cell1,cnic3;
long int cnic1,cnic2,cell2;
dd=11;
mm=11;
yyyy=1989;
cell1=300;
cell2=1234567;
cnic1=12345;
cnic2=1234567;
cnic3=1;
printf("\n****************************RESUME****************************");
printf("\n******************************CV******************************");
printf("\n**************************************************************");
printf("\n==============================================================");
printf("\nName : %s","Abc");
printf("\nFathers Name : %s","Xyz");
printf("\nDate of Birth : %d-%d-%d",dd,mm,yyyy);
printf("\nAddress : %s","Engineering Department, Main Campus, Iqra University,");
printf("\n %s","Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCell Phone : 0%d-%ld",cell1,cell2);
printf("\nCNIC : %ld-%ld-%d",cnic1,cnic2,cnic3);
printf("\nGender : %s","Male");
printf("\nHSC (College\\Board) : %s","Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : %s %d","August",2005);
printf("\nSSC (School\\Board) : %s","Science, Iqra School, Karachi Board");
printf("\nSSC Year : %s %d","August",2003);
_getch();
}

[Type text]
Experiment 12
Objective
Taking Input from the user at console screen using scanf and getche commands.

Theory
Scanf command can take input of different data types at a time.
Getche command can take only one character input.

Example
Write the output after supplying appropriate input on console screen.

Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
char a;
int b;
float c;
double d;
printf("\nEnter character ");
scanf_s("%c",&a);
printf("\nEnter integer ");
scanf_s("%d",&b);
printf("\nEnter float ");
scanf_s("%f",&c);
printf("\nEnter double ");
scanf_s("%lf",&d);
printf("\n%c %d %f %lf",a,b,c,d);
_getch();
}

Write the output for the program on left


#include<stdio.h>
#include<conio.h>
void main(void)
{
char a; int b;
float c; double d;
printf("Enter char integer float double\n");
scanf("%c %d %f %lf",&a,&b,&c,&d);
printf("\n%c %d %f %lf",a,b,c,d);
getch();
}

Write the output for the program on left


#include<stdio.h>
#include<conio.h>
void main(void)
{
pri ntf("\nWhat is your section : ");
getche();
getch();
}
Assignment:
Using the program below, make a resume with format variables showing your complete details.

Program
#include<stdio.h>
#include<conio.h>
void main(void)
{
int dd,mm,yyyy,cell1,cnic3;
long int cnic1,cnic2,cell2;
dd=11;
mm=11;
yyyy=1989;
cell1=300;
cell2=1234567;
cnic1=12345;
cnic2=1234567;
cnic3=1;
printf("\n****************************RESUME****************************");
printf("\n******************************CV******************************");
printf("\n**************************************************************");
printf("\n==============================================================");
printf("\nName : %s","Abc");
printf("\nFathers Name : %s","Xyz");
printf("\nDate of Birth : %d-%d-%d",dd,mm,yyyy);
printf("\nAddress : %s","Engineering Department, Main Campus, Iqra University,");
printf("\n %s","Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCell Phone : 0%d-%ld",cell1,cell2);
printf("\nCNIC : %ld-%ld-%d",cnic1,cnic2,cnic3);
printf("\nGender : %s","Male");
printf("\nHSC (College\\Board) : %s","Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : %s %d","August",2005);
printf("\nSSC (School\\Board) : %s","Science, Iqra School, Karachi Board");
printf("\nSSC Year : %s %d","August",2003);
_getch();
}
Experiment 13
Objective
Arithmetic operators, conditional operators, assignment operators, Increment/decrement operators.Studying Math
functions.

Theory
Math.h header file is included for the definitions of math functions listed below. It is written as #include<math.h>.

Example
The program below shows the result for math and trigonometric functions. The functions pass the values to variables
which are further used for printing in printf.
Program Output
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{

float a=45,b=1,sn,cs,tn,snh,csh,tnh;
sn=sin(a);

cs=cos(a); Trignometric Functions


tn=tan(a); sin 45 = 0.85
cos 45 = 0.53
snh=sinh(b); tan 45 = 1.62
csh=cosh(b);
tnh=tanh(b);

Hyperbolic Functions
printf("\n\n\n Trignometric Functions"); sinh 1 = 1.18
printf("\nsin 45 = %.2f",sn); cosh 1 = 1.54
printf("\ncos 45 = %.2f",cs); tanh 1 = 0.76
printf("\ntan 45 = %.2f",tn);

printf("\n\n\n Hyperbolic Functions");

printf("\nsinh 1 = %.2f",snh);
printf("\ncosh 1 = %.2f",csh);
printf("\ntanh 1 = %.2f",tnh);

_getch();
}
The program below shows the result for math and trigonometric functions. It also demonstrates that some functions may
be called within the body of another function. For example here all the trigonometric functions are called inside printf
function.

Program Output
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void) Trignometric Functions
{ sin 45 = 0.85
printf("\n\n\n Trignometric Functions"); cos 45 = 0.53
tan 45 = 1.62
printf("\nsin 45 = %.2f",sin(45));
printf("\ncos 45 = %.2f",cos(45)); Hyperbolic Functions
printf("\ntan 45 = %.2f",tan(45)); sinh 1 =1.18
cosh 1 = 1.54
printf("\n\n\n Hyperbolic Functions"); tanh 1 = 0.76
printf("\nsinh 1 = %.2f",sinh(1));
printf("\ncosh 1 = %.2f",cosh(1));
printf("\ntanh 1 = %.2f",tanh(1)); Math Functions
pow 2,3 = 8.00
printf("\n\n\n Math Functions"); sqrt 49 = 7.00
printf("\npow 2,3 = %.2f",pow(2,3));
printf("\nsqrt 49 = %.2f",sqrt(49));

_getch();
}

Operators

Arithmetic Relational Assignment Increment/decrement


operators operators operators operators
Add + Greater Than > Addition assignment += Increment ++
Subtract - Less Than < Subtraction assignment -= Decrement --
Multiplication * Greater or Equal >= Multiplication assignment *=
Division / Less or Equal <= Division assignment /=
Remainder % Equal Equal ==
Not Equal !=
Example
Explain the following program after careful study.
Program Output
#include<stdio.h>
#include<conio.h>
void main(void)
{

int a=2,b=4,c1,c2,c3,c4,d1,d2,d3,d4; 6 -2 8 0
c1=c2=c3=c4=5; 0 10 1 0 1
d1=d2=d3=d4=8; 8 2 15 1
printf("\n%d %d %d %d",a+b,a-b,a*b,a/b); 8 98 7
printf("\n%d %d %d %d %d %d",a>b,a<b,a>=b,a<=b,a==b,a!=b);
printf("\n%d %d %d %d",c1+=3,c2-=3,c3*=3,c4/3);
printf("\n%d %d %d %d",d1++,++d2,d3--,--d4);
_getch();
}

Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",- -a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %d %d",a++,++a,a,a - -);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a+5,++a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a+=5,++a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a-=5,- -a,a);
printf("\n%d ",a);
_getch();
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a+=5,a++,a);
printf("\n%d ",a);
_getch();
}

Exercise
Write output for following programs and give reasons.

Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",a++,a);
printf("\n%d ",a);
_getch();
}

Write the output for the program on left


#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",++a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",a - -,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",- -a,a);
printf("\n%d ",a);
_getch();
}
Assignment:

1. Program the following.


Implement the following equation
4 3 2 2
3x sin(180x) + 4x cos(90x) + x sin(tan(45)) + 7x + 9cos(90x )

where x may be user defined value.

2. Program the following.


 Prompt user to input distance in Kilometers and display it in meters.
 Input any number from user and generate its square e.g. square of 8 is 64
 Input any number from user and generate its cube e.g. cube of 8 is 512
 Input a 4 digit number in any integer type variable and sum all the four digits, e.g. int a =3487, result = 22
 Generate the table for a number input by the user.

4 3 2
For the following equation 3x + 4x + x + 7x + 9, substitute the user provided value of x and generate
the result.
Experiment 14
Objective
Studying loops. For loops, nested for loops, while loops, nested while loops, do while loops, nested do while loops. Studying
loops with cross combination.
Theory
for while do while
initialization; initialization;
do
for(initialization ; check range ; iteration) while(check range)
{
{ {
body
body body
iteration;
} iteration;
} while(check range)
}

Example: This table below shows nested loops. All the three programs have same output.

Loop Nested
Program Output Program Output
Loop
#include<stdio.h>
#include<conio.h>v
oid main(void)
#include<stdio.h> {
#i nclude<conio.h> for(int a=0;a<=3;a++)
void main(void)
{ {
For For for(int b=0;b<=3;b++)
for(int a=0;a<=12;a++) {
printf("%d x 2 = %d\n",a,a*2); printf("%d%d\t",a,b);
_getch(); }
printf("\n");
} }
_getch()
;}
#include<stdio.h>
#include<conio.h>v
oid main(void)
{
#include<stdio.h> int a=0,b;
#incl ude<conio. h> while(a<=3)
void main(void) 0x2=0
{ 1x2=2 {
2x2=4 b=0;
int a=0; 3x2=6
While while(a<=12) 4x2=8 While while(b<=3) 00 01 02 03
{ 5 x 2 = 10 { 10 11 12 13
printf("%d x 2 = %d\n",a,a*2); 6 x 2 = 12 printf("%d%d\t",a,b); 20 21 22 23
a++; 7 x 2 = 14 b++; 30 31 32 33
}
} 8 x 2 = 16
printf("\n");
_getch(); 9 x 2 = 18 a++;
} 10 x 2 = 20 }
11 x 2 = 22 _getch()
12 x 2 = 24 ;}
#include<stdio.h>
#include<conio.h>
void main(void)
#include<stdio.h> {
#i nclude<conio.h> int a=0,b;
void main(void) do
{
int a=0; {
do b=0;
Do while { Do while do
printf("%d x 2 = %d\n",a,a*2); {
a++; printf("%d%d\t",a,b);
b++;
} }while(b<=3);
while(a<=12); printf("\n");
_getch(); a++;
} }while(a<=3);
_getch();
}

67
This program of while loops takes continuous input until enter key is pressed.
Program Output
#include<stdio.h>
#include<conio.h>void main(void)

{ clrscr();
Type any sentence
int a=0; Iqra University
printf("Type any sentence\n"); Total Characters typed = 15
while(getche()!='\r')
a++;
printf("\nTotal Characters typed = %d",a); getch();

Exercise
Carefully observer the following program and write output with reasons.
Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
for(int a=0;a<=12;a++);
printf("%d x 2 = %d\n",a,a*2);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
for(int a=0;1 ;a++);
printf("%d x 2 = %d\n",a,a*2);
_getch();
}

Write the output for the program on left


#include<stdio.h>
#include<conio.h>
void main(void)
{

int a=0;
while(0)
{
printf("%d x 2 = %d\n",a,a*2);
a++;
}
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=0,b;
while(a<=3);
{
b=0;
while(b<=3);
{
printf("%d%d\t",a,b);
b++;
}
printf("\n");
a++;
}
_getch();
}

68
Program:
Following program gives the sum of all numbers input by the user using while loop. The program will display the
sum when user enters 0 as input.
#include<conio.h>
#include<stdio.h>

void main()
{
system("cls"); // clear screen clrscr();
int num=-1;
int sum=0;

printf("\nEnter 0 to stop adding the numbers");


while (num != 0)
{
printf("\nEnter Number: ");
scanf_s("%d", &num);

sum = sum + num;


}
printf("\nSum = %d ", sum);
_getch();
}

Understand the difference between break and continue by executing following programs.
break continue
int main() int main()
{ {
int i; int i;
double number, sum = 0.0; double number, sum = 0.0;

for(i=1; i <= 10; ++i) for(i=1; i <= 10; ++i)


{ {
printf("Enter a n%d: ",i); printf("Enter a n%d: ",i);
scanf("%lf",&number); scanf("%lf",&number);

// If user enters negative number, // If user enters negative number,


loop is terminated loop is terminated
if(number < 0.0) if(number < 0.0)
{ {
break; continue;
} }

sum += number; // sum = sum + sum += number; // sum = sum +


number; number;
} }

printf("Sum = %.2lf",sum); printf("Sum = %.2lf",sum);

return 0; return 0;
} }

Studying loops with cross combination


do-while
for while while for for do-while do-while for while do-while while
for( ) while( ) for( ) do while( ) { do
{ { { do { do {
while( ) for( ) while( ) for( ) while( ) } while( )
} } } }while( ) }while( )
Example

The table below shows loops with cross combinations.


Loop Program Output
#include<stdio.h>
#i ncl ude<conio. h>
void main(void)
{

int a,b=0;
for(a=0;a<=3;a++)
{
b=0;
For While while(b<=3)
{
printf("%d%d\t",a,b);
b++;
}
printf("\n");
} 00 01 02 03
_getch(); 10 11 12 13
}
#include<stdio.h> 20 21 22 23
#include<conio.h>
30 31 32 33
void main(void)

{
int a=0,b;
while(a<=3)

{
While For for(b=0;b<=3;b++)
{
printf("%d%d\t",a,b);
}
printf("\n");
a++;
}
_getch();
}

Assignment

1. Input any number


from user and generate its factorial e.g. factorial of 7 is 5040.
2. Write a program
using loops to generate following pattern.

3. Write a program
using loops to generate following pattern.

1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654320
4. Write a program using loops to generate following output.

12 x 2 = 24
11 x 2 = 22
10 x 2 = 20
9 x 2 = 18
8 x 2 = 16
7 x 2 = 14
6 x 2 = 12
5 x 2 = 10
4 x 2 = 8
3 x 2 = 6
2 x 2 = 4
1 x 2 = 2

5. The Fibonacci sequence is a series where the next term is the sum of pervious two terms. Write a C
program to generate this sequence.

S-ar putea să vă placă și