0% found this document useful (0 votes)
2 views12 pages

PracticalTaskReport CS Grade12

The document is a practical task report for a Computer Science course, detailing various programming tasks including DDL and DML statements, transmission media types, JavaScript programs for calculating factorial and sum, server-side scripting for creating a student table, and C programs for handling employee structures and student file records. Each task includes objectives, source code, and explanations of the output. The report is submitted by Rupak Dhakal under the guidance of Mr. Atul Bhattarai at Sukuna Multiple Campus, Nepal.

Uploaded by

mytv100000000
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)
2 views12 pages

PracticalTaskReport CS Grade12

The document is a practical task report for a Computer Science course, detailing various programming tasks including DDL and DML statements, transmission media types, JavaScript programs for calculating factorial and sum, server-side scripting for creating a student table, and C programs for handling employee structures and student file records. Each task includes objectives, source code, and explanations of the output. The report is submitted by Rupak Dhakal under the guidance of Mr. Atul Bhattarai at Sukuna Multiple Campus, Nepal.

Uploaded by

mytv100000000
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

Practical Task Report

of
COMPUTER SCIENCE
(Subject Code: 4282)

Submitted To
NATIONAL EXAMINATION BOARD
In Partial Fulfillment of the Requirements of the course
Grade XII

Submitted By:
Rupak Dhakal
Symbol No.: ...........................
N.E.B. Regd. No.:821050120100

Under the guidance of


Mr. Atul Bhattarai
Teaching Assistant
Sukuna Multiple Campus

SUKUNA MULTIPLE CAMPUS


Sundarharaincha-12, Morang,
Koshi Province, Nepal
2082

1
0

Table of Contents

S.N Task Page No.


o.

1 Demonstrate the various DDL and DML statement with 1


syntax and example.

2 Explain the various types of transmission media with 3


example.

3 Write a JavaScript program to display factorial of a number. 5

4 Write a JavaScript program to display the sum of two 6


numbers.

5 Write a server side scripting code to create a table named as 7


“student” with fields (firstname, lastname, mark and email).
Assume that servername=”localhost”, username=”root”,
password=””,databasename=”studentdb”.
6 Write a C program to create a structure named as employee 8
that stores name, address, age and salary for 100 employees.
This program should display all the record along with
provident fund (i.e. 10 % of salary).
7 Create a file named as "[Link]" that stores student name, 9
address and age. This program should store the records for n
student and display it.

………………….. …………………..
Internal Examiner External Examiner
Atul Bhattarai …………………..
Teaching Assistant Teaching Assistant
Sukuna Multiple Campus …………………..
Sundarharaincha-12, Morang

0
1

Task 1: DDL and DML Statements


Objective: Demonstrate the various DDL and DML statements with syntax and example.

A. DDL (Data Definition Language) Statements


DDL statements are used to define, modify, and delete database structures such as tables, indexes, and
schemas. They do not manipulate data itself.

1. CREATE
Used to create a new database or table.
Syntax:
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);

Example:
CREATE TABLE student (
id INT PRIMARY KEY AUTO_INCREMENT,
firstname VARCHAR(50) NOT NULL,
lastname VARCHAR(50) NOT NULL,
age INT,
email VARCHAR(100) UNIQUE
);

2. ALTER
Used to add, delete or modify columns in an existing table.
Syntax:
ALTER TABLE table_name ADD column_name datatype;
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE table_name MODIFY COLUMN column_name datatype;

Example:
ALTER TABLE student ADD phone VARCHAR(15);
ALTER TABLE student DROP COLUMN phone;
ALTER TABLE student MODIFY COLUMN age TINYINT;

3. DROP
Used to delete an entire table or database permanently.
Syntax:
DROP TABLE table_name;
DROP DATABASE database_name;

Example:
DROP TABLE student;
DROP DATABASE studentdb;

4. TRUNCATE
Used to remove all rows from a table without deleting the table structure.
Syntax:
TRUNCATE TABLE table_name;

Example:

1
2

TRUNCATE TABLE student;

B. DML (Data Manipulation Language) Statements


DML statements are used to manage data within database tables. These commands can be rolled back.

1. INSERT
Used to insert data into a table.
Syntax:
INSERT INTO table_name (col1, col2, ...) VALUES (val1, val2, ...);

Example:
INSERT INTO student (firstname, lastname, age, email)
VALUES ('Ram', 'Sharma', 18, 'ram@[Link]');

2. SELECT
Used to retrieve data from a table.
Syntax:
SELECT column1, column2 FROM table_name WHERE condition;

Example:
SELECT * FROM student;
SELECT firstname, email FROM student WHERE age > 17;

3. UPDATE
Used to modify existing records in a table.
Syntax:
UPDATE table_name SET column1=value1 WHERE condition;

Example:
UPDATE student SET age = 19 WHERE firstname = 'Ram';

4. DELETE
Used to remove records from a table.
Syntax:
DELETE FROM table_name WHERE condition;

Example:
DELETE FROM student WHERE id = 1;

Conclusion: DDL is used to define and manage database structures, while DML is used to insert, update,
delete, and retrieve data from those structures.

2
3

Task 2: Types of Transmission Media


Objective: Explain the various types of transmission media with examples.
Transmission media refers to the physical path between the transmitter and the receiver in a data
communication system. It is broadly classified into two categories: Guided (Wired) and Unguided (Wireless).

A. Guided (Wired) Transmission Media


In guided media, the signal is directed along a physical path (cable).

1. Twisted Pair Cable


Consists of pairs of insulated copper wires twisted together to reduce electromagnetic interference. It is the
most commonly used medium in LANs.
Types: Unshielded Twisted Pair (UTP) and Shielded Twisted Pair (STP).
Example: Telephone lines, Ethernet LAN (Cat5, Cat6 cables).

2. Coaxial Cable
Has a central conductor surrounded by insulation, metallic shield, and outer plastic jacket. Provides better
shielding than twisted pair and can carry signals over longer distances.
Example: Cable TV connections, broadband internet connections.

3. Fiber Optic Cable


Transmits data as pulses of light through a glass or plastic core. It provides very high bandwidth, low signal
loss, and immunity to electromagnetic interference.
Example: Internet backbone connections, hospital networks, submarine cables.

B. Unguided (Wireless) Transmission Media


In unguided media, signals are transmitted through the air or space without physical cables.

1. Radio Waves
Electromagnetic waves with frequencies ranging from 3 KHz to 1 GHz. They can penetrate walls and travel
long distances. Used for AM/FM radio, cordless phones, and wireless LANs.
Example: Wi-Fi (802.11), AM/FM Radio Broadcasting.

2. Microwaves
Electromagnetic waves with frequencies from 1 GHz to 300 GHz. They require line-of-sight transmission and
are used for long-distance communication.
Example: Satellite communication, mobile phone networks (4G/5G).

3. Infrared
Short-range communication using infrared light waves. It requires line-of-sight and cannot pass through walls.
Used in remote controls and short-range device communication.
Example: TV remotes, IrDA data transfer between devices.
Conclusion: Guided media offers higher speed and security while unguided media provides flexibility and
mobility in communication.

3
4

Task 3: JavaScript Program – Factorial of a Number


Objective: Write a JavaScript program to display the factorial of a number.

Source Code (HTML + JavaScript):


<!DOCTYPE html>
<html>
<head>
<title>Factorial</title>
</head>
<body>
<h2>Factorial Calculator</h2>
<script>
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorial(n - 1);
}

var num = parseInt(prompt('Enter a positive number:'));


if (num < 0) {
[Link]('Factorial is not defined for negative numbers.');
} else {
[Link]('Factorial of ' + num + ' = ' + factorial(num));
}
</script>
</body>
</html>

Output:
If the user enters 5, the output will be:
Factorial of 5 = 120

Explanation: The program uses a recursive function. It prompts the user to enter a number and calculates the
factorial by repeatedly multiplying n * (n-1) * ... * 1. The base case returns 1 when n equals 0 or 1.

4
5

Task 4: JavaScript Program – Sum of Two Numbers


Objective: Write a JavaScript program to display the sum of two numbers.

Source Code (HTML + JavaScript):


<!DOCTYPE html>
<html>
<head>
<title>Sum of Two Numbers</title>
</head>
<body>
<h2>Sum Calculator</h2>
<script>
var num1 = parseFloat(prompt('Enter the first number:'));
var num2 = parseFloat(prompt('Enter the second number:'));
var sum = num1 + num2;
[Link]('First Number: ' + num1 + '<br>');
[Link]('Second Number: ' + num2 + '<br>');
[Link]('Sum = ' + sum);
</script>
</body>
</html>

Output:
If the user enters 15 and 25:
First Number: 15
Second Number: 25
Sum = 40

Explanation: The program takes two numbers as input using prompt(), converts them to floating point with
parseFloat(), adds them together, and displays the result using [Link]().

5
6

Task 5: Server-Side Scripting – Create Student Table


Objective: Write a server side scripting code to create a table named "student" with fields (firstname,
lastname, mark and email).
Configuration: servername="localhost", username="root", password="", databasename="studentdb"

Source Code (PHP):


<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "studentdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// SQL to create table


$sql = "CREATE TABLE IF NOT EXISTS student (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
mark FLOAT NOT NULL,
email VARCHAR(50) UNIQUE
)";

if ($conn->query($sql) === TRUE) {


echo "Table 'student' created successfully!";
} else {
echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

Output:
Table 'student' created successfully!

Explanation: The PHP script connects to the MySQL database 'studentdb' using mysqli. It then runs a
CREATE TABLE SQL statement to create the 'student' table with the required fields. The IF NOT EXISTS
clause prevents an error if the table already exists.

6
7

Task 6: C Program – Employee Structure


Objective: Write a C program to create a structure named employee that stores name, address, age and salary
for 100 employees and display all records along with provident fund (10% of salary).

Source Code (C):


#include <stdio.h>
#include <string.h>

#define MAX 100

struct employee {
char name[50];
char address[100];
int age;
float salary;
};

int main() {
struct employee emp[MAX];
int n, i;

printf("Enter number of employees (max %d): ", MAX);


scanf("%d", &n);
getchar(); // consume newline

for (i = 0; i < n; i++) {


printf("\n--- Employee %d ---\n", i + 1);

printf("Enter Name: ");


fgets(emp[i].name, sizeof(emp[i].name), stdin);
emp[i].name[strcspn(emp[i].name, "\n")] = '\0';

printf("Enter Address: ");


fgets(emp[i].address, sizeof(emp[i].address), stdin);
emp[i].address[strcspn(emp[i].address, "\n")] = '\0';

printf("Enter Age: ");


scanf("%d", &emp[i].age);

printf("Enter Salary: ");


scanf("%f", &emp[i].salary);
getchar();
}

printf("\n%-5s %-20s %-25s %-5s %-12s %-12s\n",


"S.N.", "Name", "Address", "Age", "Salary", "PF (10%)");
printf("-------------------------------------------------------------------\n");

for (i = 0; i < n; i++) {


float pf = emp[i].salary * 0.10;
printf("%-5d %-20s %-25s %-5d %-12.2f %-12.2f\n",
i + 1, emp[i].name, emp[i].address,
emp[i].age, emp[i].salary, pf);
}

return 0;
}

Sample Output:
Enter number of employees (max 100): 2

7
8

--- Employee 1 ---


Enter Name: Ram Sharma
Enter Address: Kathmandu
Enter Age: 30
Enter Salary: 25000

--- Employee 2 ---


Enter Name: Sita Rai
Enter Address: Pokhara
Enter Age: 27
Enter Salary: 20000

S.N. Name Address Age Salary PF (10%)


-------------------------------------------------------------------
1 Ram Sharma Kathmandu 30 25000.00 2500.00
2 Sita Rai Pokhara 27 20000.00 2000.00

Explanation: The program defines a structure 'employee' with four fields. It reads data for 'n' employees using
a loop, then displays all records in a formatted table including the provident fund computed as 10% of each
employee's salary.

8
9

Task 7: C Program – File Handling ([Link])


Objective: Create a file named "[Link]" that stores student name, address and age. The program should
store records for n students and display them.

Source Code (C):


#include <stdio.h>
#include <stdlib.h>

struct student {
char name[50];
char address[100];
int age;
};

int main() {
FILE *fp;
struct student s;
int n, i;

printf("Enter number of students: ");


scanf("%d", &n);
getchar();

// Open file for writing


fp = fopen("[Link]", "w");
if (fp == NULL) {
printf("Error opening file!\n");
exit(1);
}

// Write student records to file


for (i = 0; i < n; i++) {
printf("\n--- Student %d ---\n", i + 1);

printf("Enter Name: ");


fgets([Link], sizeof([Link]), stdin);
[Link][strcspn([Link], "\n")] = '\0';

printf("Enter Address: ");


fgets([Link], sizeof([Link]), stdin);
[Link][strcspn([Link], "\n")] = '\0';

printf("Enter Age: ");


scanf("%d", &[Link]);
getchar();

fprintf(fp, "Name: %s\nAddress: %s\nAge: %d\n\n",


[Link], [Link], [Link]);
}
fclose(fp);
printf("\nRecords written to [Link] successfully.\n");

// Read and display records from file


fp = fopen("[Link]", "r");
if (fp == NULL) {
printf("Error reading file!\n");
exit(1);
}

printf("\n===== Student Records =====\n");


char line[200];
while (fgets(line, sizeof(line), fp) != NULL) {
printf("%s", line);

9
10

}
fclose(fp);

return 0;
}

Sample Output:
Enter number of students: 2

--- Student 1 ---


Enter Name: Hari Bahadur
Enter Address: Biratnagar
Enter Age: 17

--- Student 2 ---


Enter Name: Gita Kumari
Enter Address: Dharan
Enter Age: 16

Records written to [Link] successfully.

===== Student Records =====


Name: Hari Bahadur
Address: Biratnagar
Age: 17

Name: Gita Kumari


Address: Dharan
Age: 16

Explanation: The program opens '[Link]' in write mode and stores n student records using fprintf(). It then
reopens the file in read mode and prints all records using fgets() line by line. File pointers are properly closed
after each operation.

10

You might also like