0% found this document useful (0 votes)
7 views24 pages

HSC 26 LabWork

The document outlines a series of experiments aimed at teaching HTML and C programming concepts, including creating web pages with various HTML tags, hyperlinks, tables, images, and writing C programs for calculating the area of a triangle, checking leap years, summing series, and sorting arrays. Each experiment includes objectives, theory, procedures, example codes, and results. The document serves as a practical guide for learning web development and programming fundamentals.

Uploaded by

mashiatafifa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views24 pages

HSC 26 LabWork

The document outlines a series of experiments aimed at teaching HTML and C programming concepts, including creating web pages with various HTML tags, hyperlinks, tables, images, and writing C programs for calculating the area of a triangle, checking leap years, summing series, and sorting arrays. Each experiment includes objectives, theory, procedures, example codes, and results. The document serves as a practical guide for learning web development and programming fundamentals.

Uploaded by

mashiatafifa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment No: 1

Name of the Experiment: Design a website to demonstrate different types of heading and formatting tags
and display them in a browser.

Objective:
To learn how to use HTML heading tags and text formatting tags and display them properly in a web
browser.

Required Tools:

Computer

Windows Operating System

Text Editor (e.g., Notepad)

Web Browser (e.g., Google Chrome / Mozilla Firefox)

Procedure:

1. Turn on the computer.


2. Open Notepad (or any text editor).
3. Write the following HTML code:
<!DOCTYPE html>

<html>

<head>

<title>Heading and Formatting Tags</title>

</head>

<body>

<h1>This is Heading 1</h1>

<h2>This is Heading 2</h2>

<h3>This is Heading 3</h3>

<h4>This is Heading 4</h4>

<h5>This is Heading 5</h5>

<h6>This is Heading 6</h6>

<p><b>This text is Bold</b></p>

<p><i>This text is Italic</i></p>

<p><u>This text is Underlined</u></p>

<p><strong>This text is Strong</strong></p>

<p><em>This text is Emphasized</em></p>

<p><mark>This text is Highlighted</mark></p>

<p><small>This text is Small</small></p>

<p>H<sub>2</sub>O (Subscript)</p>

<p>10<sup>2</sup> (Superscript)</p>

</body>

</html>

Result:
The webpage was successfully created and displayed different heading levels (H1–H6) and various
formatting styles such as bold, italic, underline, subscript, and superscript in the web browser.
Explanation / Discussion:

In this experiment, HTML heading tags <h1> to <h6> were used to display different sizes of headings,
where <h1> is the largest and <h6> is the smallest.

Formatting tags like <b>, <i>, <u>, <strong>, <em>, <mark>, <small>, <sub>, and <sup> were used to
modify the appearance of text.

This experiment helps to understand the basic structure of an HTML webpage and how text formatting
works. These tags are important in designing structured and readable websites.

Experiment No: 02

Experiment Name:

Design a webpage to create hyperlinks that connect more than one web page and display them in a
browser.

Objective:

To learn how to create hyperlinks using HTML anchor tags and connect multiple web pages so that users
can navigate between them through a web browser.

Theory:

A hyperlink is a connection from one web page to another page or resource. In HTML, hyperlinks are
created using the <a> (anchor) tag.

The basic syntax of a hyperlink is:

<a href="URL">Link Text</a>

 <a> = Anchor tag


 href = Hypertext Reference (specifies the destination page)
 Link Text = Clickable text displayed in the browser

Hyperlinks can connect:

 One webpage to another webpage


 A webpage to an external website
 A webpage to an email address
 A webpage to a specific section of the same page

When a user clicks a hyperlink, the browser loads the linked page.
Requirements:

 Notepad / VS Code
 Web Browser (Chrome / Firefox / Edge)
 Basic knowledge of HTML

Procedure:

1. Open Notepad or any code editor.


2. Create the first HTML file named [Link].
3. Write basic HTML structure.
4. Add hyperlink using the <a> tag to connect another page (e.g., [Link]).
5. Save the file.
6. Create another HTML file named [Link].
7. Add a hyperlink to return to [Link].
8. Save the file.
9. Open [Link] in a web browser.
10. Click the hyperlink to test navigation between pages.

Example Code:

[Link]

<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is the home page.</p>

<a href="[Link]">Go to About Page</a>


</body>
</html>

[Link]

<!DOCTYPE html>
<html>
<head>
<title>About Page</title>
</head>
<body>
<h1>About Us</h1>
<p>This is the about page.</p>

<a href="[Link]">Go Back to Home Page</a>


</body>
</html>

Result:
Experiment No: 03

Experiment Name:

Design a webpage to create a table using colspan and rowspan and display it in a browser.

Objective:

To learn how to create tables in HTML and use colspan and rowspan attributes to merge table cells
horizontally and vertically.

Theory:

In HTML, a table is created using the <table> tag.

<tr> defines a table row.

<th> defines a table header cell.

<td> defines a table data cell.

The colspan and rowspan attributes are used to merge cells:

 colspan: Merges two or more columns (horizontal merging).

<td colspan="2">Text</td>

 rowspan: Merges two or more rows (vertical merging).

<td rowspan="2">Text</td>

Requirements:

 Notepad / VS Code
 Web Browser (Chrome / Firefox / Edge)
 Basic knowledge of HTML
Procedure:

1. Open Notepad or any code editor.


2. Create a new file named [Link].
3. Write the basic HTML structure.
4. Use the <table> tag to create a table.
5. Add rows using <tr>.
6. Insert header and data cells using <th> and <td>.
7. Apply colspan and rowspan attributes where necessary.
8. Save the file.
9. Open the file in a web browser to view the output.

Example Code:

<!DOCTYPE html>
<html>
<head>
<title>Table with Colspan and Rowspan</title>
</head>
<body>

<h2>Student Information Table</h2>

<table border="1" cellpadding="10">


<tr>
<th rowspan="2">Name</th>
<th colspan="2">Marks</th>
<th rowspan="2">Grade</th>
</tr>
<tr>
<th>Math</th>
<th>Science</th>
</tr>
<tr>
<td>Rahim</td>
<td>85</td>
<td>90</td>
<td>A</td>
</tr>
<tr>
<td>Karim</td>
<td>75</td>
<td>80</td>
<td>B</td>
</tr>
</table>

</body>
</html>
Result:

Experiment No: 04

Experiment Name:

Design a webpage to add a specific image and display it in a browser.

Objective:

To learn how to insert and display an image in a webpage using the HTML <img> tag.

Theory:

In HTML, images are added using the <img> (image) tag. The <img> tag is an empty tag, meaning it
does not require a closing tag.

Basic Syntax:

<img src="[Link]" alt="Description" width="300" height="200">

Attributes:

 src → Specifies the path or location of the image file.


 alt → Alternative text displayed if the image cannot be loaded.
 width → Sets the width of the image.
 height → Sets the height of the image.

Images can be added from:

 The same folder (local image)


 Another folder (using path)
 An external website (using full URL)

Requirements:

 Notepad / VS Code
 A specific image file (e.g., [Link])
 Web Browser (Chrome / Firefox / Edge)
 Basic knowledge of HTML

Procedure:

1. Select a specific image and keep it in the same folder where the HTML file will be saved.
2. Open Notepad or any code editor.
3. Create a new file named [Link].
4. Write the basic HTML structure.
5. Use the <img> tag to insert the image.
6. Save the file.
7. Open the file in a web browser.
8. Check whether the image is displayed properly.

Example Code:

<!DOCTYPE html>
<html>
<head>
<title>Display Image</title>
</head>
<body>

<h2>My Favorite Image</h2>

<img src="[Link]" alt="Sample Image" width="300" height="200">

</body>
</html>

Explanation:

 The image file [Link] must be in the same folder as the HTML file.
 The alt attribute shows text if the image fails to load.
 The width and height attributes control the size of the image.

Result:

The webpage was successfully created, and the specific image was added using the <img> tag.
Experiment No: 05

Experiment Name:

Determining the Area of a Triangle Using Three Sides

Objective

To write a C program that calculates the area of a triangle when the lengths of its three sides are given,
using Heron’s Formula.

Theory

If three sides of a triangle are a, b, c, then:

 Semi-perimeter,

Area of triangle (Heron’s Formula),


Algorithm :

Step 1: Start

Step 2: Declare variables a, b, c, s, area

Step 3: Input three sides a, b, c

Step 4: Calculate semi-perimeter

s = (a + b + c) / 2

Step 5: Calculate area using formula

area = sqrt(s * (s - a) * (s - b) * (s - c))

Step 6: Display the value of area

Step 7: Stop

C program code:

#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, s, area;
printf("Enter three sides of the triangle: ");
scanf("%f %f %f", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of the triangle = %.2f\n", area);
return 0;

Result:

Sample Input

Enter three sides of the triangle: 3 4 5


Sample Output

Area of the triangle = 6.00

Experiment No: 6

Experiment Name:

Write a C program to determine whether a year is a leap year or not.

Objective:

To write and execute a C program that checks whether a given year is a leap year using conditional
statements.

Theory:

A leap year has 366 days instead of 365 days.

A year is considered a leap year if:

1. The year is divisible by 4 and


2. The year is not divisible by 100,
OR
3. The year is divisible by 400.

Algorithm: Steps to Determine Leap Year

Step 1: Start the program.


Step 2: Declare an integer variable year.
Step 3: Read or input the value of year from the user.
Step 4: Check if (year % 400 == 0)
→ If true, print "Leap Year".
Step 5: Else, check if (year % 100 == 0)
→ If true, print "Not Leap Year".
Step 6: Else, check if (year % 4 == 0)
→ If true, print "Leap Year".
Step 7: Else
→ Print "Not Leap Year".
Step 8: Stop the program.

Program Code (C):


#include <stdio.h>

int main() {
int year;

printf("Enter a year: ");


Sample Input&year);
scanf("%d", & Output:

if (year % 400 == 0) {
Input:
printf("%d is a Leap Year.", year);
}
Enter
elsea ifyear:
(year2024
% 100 == 0) {
printf("%d is Not a Leap Year.", year);
Output:
}
else if (year % 4 == 0) {
printf("%d
2024 is a Leap is a Leap Year.", year);
Year.
}
else {
printf("%d is Not a Leap Year.", year);
}

return 0;
}

Result:

The program successfully checks whether a given year is a leap year or not using conditional statements.

Input:

Enter a year: 2024

Output:

2024 is a Leap Year.

Experiment No: 7

Experiment Name:

Write a C program to determine the sum of the series: 1² + 3² + 5² + … + N²

Objective:
To write a C program that calculates the sum of squares of odd numbers up to a given number N.

Theory:

The series consists of squares of odd numbers:


1², 3², 5², …

To find the sum:

1. Initialize sum = 0
2. Start from the first odd number 1
3. Add squares of all odd numbers ≤ N to sum
4. Display the result

Algorithm (Step-wise):

Step 1: Start the program.


Step 2: Declare integer variables N, i, and sum.
Step 3: Initialize sum = 0.
Step 4: Input the value of N.
Step 5: For i = 1 to N with a step of 2 (i.e., i = 1, 3, 5, …):
→ Add i * i to sum.
Step 6: After completing the loop, print the value of sum.
Step 7: Stop the program.

Program Code (C):

#include <stdio.h>
int main() {
int N, i, sum = 0;

printf("Enter the value of N: ");


scanf("%d", &N);

for(i = 1; i <= N; i=i+2) {


sum += i * i;
}
}

printf("The sum of the series is: %d\n", sum);

return 0;
}

Sample Input & Output:

Input:

Enter the value of N: 7


Output:

The sum of the series is: 84

(Because 1² + 3² + 5² + 7² = 1 + 9 + 25 + 49 = 84)

Result:

The program calculates the sum of squares of odd numbers up to N successfully.

Here’s a detailed explanation for Experiment 8:

Experiment No: 8

Experiment Name:

Write a C program to arrange the input data of an array in ascending and descending order.

Objective:

To write a C program that sorts the elements of an array in ascending and descending order using simple
sorting techniques like Bubble Sort.

Theory:

An array is a collection of elements stored in contiguous memory locations.

Sorting an array means arranging the elements in a particular order:

1. Ascending order: Smallest to largest


2. Descending order: Largest to smallest

A simple way to sort is using Bubble Sort:

 Compare each element with the next element.


 Swap if they are not in the desired order.
 Repeat until the entire array is sorted.

Algorithm (Step-wise):

Step 1: Start the program.


Step 2: Declare an array arr and integer variables n, i, j, temp.
Step 3: Input the number of elements n.
Step 4: Input the elements of the array.
Step 5: Sort in ascending order:
- For i = 0 to n-1
- For j = i+1 to n-1
- If arr[i] > arr[j], swap arr[i] and arr[j].
Step 6: Print the array in ascending order.
Step 7: Sort in descending order:
- For i = 0 to n-1
- For j = i+1 to n-1
- If arr[i] < arr[j], swap arr[i] and arr[j].
Step 8: Print the array in descending order.
Step 9: Stop the program.

Program Code (C):

#include <stdio.h>

int main() {
int n, i, j, temp;

printf("Enter the number of elements: ");


scanf("%d", &n);

int arr[n];

printf("Enter %d elements:\n", n);


for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

// Ascending Order
for(i = 0; i < n-1; i++) {
for(j = i+1; j < n; j++) {
if(arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

printf("Array in Ascending Order: ");


for(i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");

// Descending Order
for(i = 0; i < n-1; i++) {
for(j = i+1; j < n; j++) {
if(arr[i] < arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

printf("Array in Descending Order: ");


for(i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");

return 0;
}

Sample Input & Output:

Input:

Enter the number of elements: 5


Enter 5 elements:
12 5 8 1 9

Output:

Array in Ascending Order: 1 5 8 9 12


Array in Descending Order: 12 9 8 5 1

Result:

The program successfully sorts an array in ascending and descending order.

Experiment No: 9

Experiment Name:

Create a database table and design its fields (SQLite).

Objective:

To create a database table in SQLite and define its fields with appropriate data types and constraints.
Theory:

A database table is a collection of related data organized in rows and columns.

Each column (field) has:

 A name
 A data type (e.g., INTEGER, TEXT, REAL)
 Optional constraints (e.g., PRIMARY KEY, NOT NULL, UNIQUE)

In SQLite, you can create a table using the CREATE TABLE statement.

Algorithm (Step-wise):

Step 1: Start the database session.


Step 2: Connect to or create a database (e.g., [Link]).
Step 3: Write a CREATE TABLE SQL statement with the following:
- Table name (e.g., Students)
- Field names and data types
- Optional constraints (PRIMARY KEY, NOT NULL, etc.)
Step 4: Execute the CREATE TABLE statement.
Step 5: Verify the table creation using SELECT * FROM table_name;
Step 6: Stop.

Example Table Design:

Table Name: Students

Field Name Data Type Constraints Description


StudentID Unique ID for each
INTEGER PRIMARY KEY
student
Name TEXT NOT NULL Student full name
Age INTEGER Student age
Department TEXT Department name
EnrollmentDate Date of enrollment
TEXT
(YYYY-MM-DD)
SQL Commands (SQLite):
-- Connect to or create the database
sqlite3 [Link]

-- Create the table


CREATE TABLE Students (
StudentID INTEGER PRIMARY KEY,
Name TEXT NOT NULL,
Age INTEGER,
Department TEXT,
EnrollmentDate TEXT
);

Insert sample data

INSERT INTO Students (StudentID, Name, Age, Department, EnrollmentDate)


VALUES (1, 'Alice', 20, 'CSE', '2026-02-23');

View data:
SELECT * FROM Students;

Table Name: Students

StudentID Name Age Department EnrollmentDate


1 Alice 20 CSE 2026-02-23

Result:

The Students table is successfully created in SQLite with designed fields and constraints. You can now
insert, update, delete, and query data from the table.
Experiment No: 10

Experiment Name:

Query a database and display records based on conditions (SQLite).

Objective:

To write SQL queries that retrieve data from a table based on specific conditions using the WHERE
clause.

Theory:

 A query fetches data from a database.


 Use SELECT to retrieve data.
 WHERE filters records based on conditions.
 Condition operators:
o = equal, > greater, < less
o >= greater/equal, <= less/equal
o != or <> not equal
o AND, OR to combine conditions

Procedure:

Step 1: Start the database session.


Step 2: Connect to or open the database (e.g., [Link]).
Step 3: Identify the table to query (e.g., Students).
Step 4: Write a SELECT query with a WHERE clause specifying the condition(s).
Step 5: Execute the query to fetch records.
Step 6: Display the retrieved records.
Step 7: Stop the program/session.

Example Table:

Students

StudentID Name Age Department EnrollmentDate


1 Alice 20 CSE 2026-02-23
2 Bob 22 EEE 2025-09-01
3 Carol 21 CSE 2026-01-15
4 David 23 ME 2024-07-10
SQL Queries (SQLite):

1. Select all students in CSE department:

SELECT * FROM Students


WHERE Department = 'CSE';

Output:

StudentID Name Age Department EnrollmentDate


1 Alice 20 CSE 2026-02-23
3 Carol 21 CSE 2026-01-15

2. Select students with age greater than 21:

SELECT * FROM Students


WHERE Age > 21;

Output:

StudentID Name Age Department EnrollmentDate


2 Bob 22 EEE 2025-09-01
4 David 23 ME 2024-07-10

3. Select students in CSE with age ≤ 21:

SELECT * FROM Students


WHERE Department = 'CSE' AND Age <= 21;

Output:

StudentID Name Age Department EnrollmentDate


1 Alice 20 CSE 2026-02-23
3 Carol 21 CSE 2026-01-15

Result:

Records from the database can be queried and displayed based on conditions using the WHERE clause
with comparison and logical operators.
Experiment No: 11

Experiment Name:

Create a database file with multiple fields, add records, and generate a query report based on conditions.

Objective:

 To create a SQLite database table with multiple fields.


 To insert records into the table.
 To query the table and generate reports based on specific conditions.

Theory:

 Database table: Stores related data in rows and columns.


 Fields (columns): Have names, data types, and optional constraints.
 SQL queries: Retrieve data using SELECT with conditions (WHERE) to generate reports.

Procedure:

Step 1: Start SQLite session and create/connect a database (e.g., [Link]).

Step 2: Design a table (e.g., Employees) with multiple fields:

Field Data type


EmpID INTEGER, PRIMARY KEY
Name TEXT
Age INTEGER
Department TEXT
Salary REAL

Step 3: Execute the CREATE TABLE statement.


Step 4: Insert multiple records using INSERT INTO.
Step 5: Generate query reports based on conditions using SELECT with WHERE.
Step 6: Display the results.
Step 7: Stop.

Table Design Example:

Field Data Type Constraints Description


EmpID INTEGER PRIMARY KEY Employee unique ID
Name TEXT NOT NULL Employee name
Age INTEGER Employee age
Department TEXT Department name
Salary REAL Employee salary
SQLite Commands:

Table creation:

CREATE TABLE Employees (


EmpID INTEGER PRIMARY KEY,
Name TEXT NOT NULL,
Age INTEGER,
Department TEXT,
Salary REAL
);

Insert records

INSERT INTO Employees (EmpID, Name, Age, Department, Salary) VALUES

(1, 'Alice', 28, 'CSE', 50000),

(2, 'Bob', 32, 'EEE', 55000),

(3, 'Carol', 25, 'CSE', 48000),

(4, 'David', 30, 'ME', 52000);

Status of the original Employees Table:

EmpID Name Age Department Salary


1 Alice 28 CSE 50000
2 Bob 32 EEE 55000
3 Carol 25 CSE 48000
4 David 30 ME 52000

Query 1: Employees in CSE


SELECT * FROM Employees WHERE Department = 'CSE';
Output:

EmpID Name Age Department Salary


1 Alice 28 CSE 50000
3 Carol 25 CSE 48000

Query 2: Employees with Salary > 50000


SELECT * FROM Employees WHERE Salary > 50000;
Output:

EmpID Name Age Department Salary


2 Bob 32 EEE 55000
4 David 30 ME 52000

Query 3: Employees Age <= 30 in CSE


SELECT * FROM Employees WHERE Department='CSE' AND Age <= 30;
Output:
EmpID Name Age Department Salary
1 Alice 28 CSE 50000
3 Carol 25 CSE 48000

Result:

A database table is created, records are added, and queries are used to generate reports based on specific
conditions.

You might also like