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

Copy of Computer Project 3

The document is a project report submitted by Nitya Kaphle for the Grade XII Computer Science curriculum at the Global School of Science in Kathmandu, Nepal. It covers topics in C programming, JavaScript, and Database Management, detailing various programming exercises and concepts. The project is submitted under the supervision of Dhirendra Kumar Yadav and includes a certificate of completion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Copy of Computer Project 3

The document is a project report submitted by Nitya Kaphle for the Grade XII Computer Science curriculum at the Global School of Science in Kathmandu, Nepal. It covers topics in C programming, JavaScript, and Database Management, detailing various programming exercises and concepts. The project is submitted under the supervision of Dhirendra Kumar Yadav and includes a certificate of completion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

GLOBAL SCHOOL OF SCIENCE

PROJECT WORK
(COMPUTER SCIENCE)

Submitted By: Submitted To:


Name: Nitya Kaphle Dhirendra Kumar Yadav
Class: 12, M2 Department of Computer
Roll No: 31

Kathmandu, Nepal
2025

A Project On
C Programming, Java Script and Database
Management

Submitted as a partial fulfillment of requirement of


the curriculum of GRADE-XII (Computer Science)
under National Education Board, Nepal

Submitted By:
Nitya Kaphle

Under Supervision Of
Dhirendra Kumar Yadav

Date:
27 February, 2025

Global School of Science


Mid Baneshwor, Kathmandu Nepal

GLOBAL SCHOOL OF SCIENCE


Mid Baneshwor, Kathmandu

Certificate
This is to certify that Mr./Ms. ……………………………………
has successfully completed his/her project work
as per the requirement of the curriculum of
GRADE-XII (Computer Science) under National
Education Board, Nepal. He/ She has completed
his/her project work within the prescribed period.

NEB Symbol no/Registration no.:

_______________ _______________
(Internal Examiner) (External Examiner)

Date: 27 February, 2025

Table of Content
Title Page No.
A. C programming 1-22

B. Java Script 23-35

C. Database Management 36 – 38

D. Conclusion 39

E. Bibliography 40

Topic coverage in Project


Section Topic/Subtopic No. of
Progra
ms

A. C Programming

1. Function

1.1 Function-related programs 6

1.2 Storage class (Automatic and 2


External)

1.3 Recursive function (Factorial and 2


Fibonacci)

2. Structure/Union

2.1 Simple program using structure 4

2.2 Array with structure 3

2.3 Union (To find the size of union) 1

3. Pointer

3.1 Simple program using pointer 5

3.2 Call by value and Call by 1+1


Reference

4. File Handling

4.1 Simple program 2

4.2 Reading/Writing with file 4

B. JavaScript

Simple Program using JavaScript 3


Using control structure (if, if-else, if- 6
else-if, switch case)

Using Loop (for, while, and do-while 3


loop)

Function in JavaScript / Object 2

Event Handling in JS 2

Form Validation 1

C. Database Management

Create a Database 1

Create a Table 1

Insert values into table 1

Select value from a table 1

Update the value from a table 1

Delete the value from a table 1

A.C-Programming
1. Function
i) Function related programs
a) Program to add to numbers using Function
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int num1 = 5, num2 = 10;
printf("Sum: %d\n", add(num1, num2));
return 0;
}
b) Program to find the maximum of two numbers using a
function:
#include <stdio.h>
int max(int a, int b) {
return (a > b) ? a : b;
}
int main() {
int num1 = 5, num2 = 10;
printf("Max: %d\n", max(num1, num2));
return 0;
}

c) Program to check if a number is prime using a


function:
#include <stdio.h>
int isPrime(int n) {
if (n <= 1) return 0;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) return 0; }
return 1;
}
int main() {
int num;
printf("Enter a number\n");
scanf("%d",&num);
if (isPrime(num)) {
printf("%d is prime.\n", num);
} else {
printf("%d is not prime.\n", num);
}
return 0;
}

d) Program to calculate the area of a circle using a


function:
#include <stdio.h>
float areaOfCircle(float r) {
return 3.14 * r * r;
}
int main() {
float a;
printf("Enter radius\n");
scanf("%f",&a);
printf("Area: %.2f\n", areaOfCircle(a));
return 0;
}
e) Program to swap two numbers using a function:
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x = 5, y = 10;
swap(&x, &y);
printf("x: %d, y: %d\n", x, y);
return 0;}

f) Program to calculate the factorial of a number using a


function:
#include <stdio.h>
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
int main() {
int num;
printf("Enter a number\n");
scanf("%d",&num);
printf("Factorial of %d: %d\n", num, factorial(num));
return 0;
}

ii) Storage class (Automatic and External)


a) Program to demonstrate automatic storage class:
#include <stdio.h>
void demo() {
auto int x = 10;
printf("Auto variable: %d\n", x);
}
int main() {
demo();
return 0;
}
b) Program to demonstrate external storage class:
#include <stdio.h>
int x = 10;
void demo() {
printf("External variable: %d\n", x);
}
int main() {
demo();
return 0;
}

iii) Recursive function (Factorial and Fibonacci)


a) Program to calculate factorial using recursion:
#include <stdio.h>
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
int main() {
int num;
printf("Enter a number:\n");
scanf("%d",&num);
printf("Factorial of %d: %d\n", num, factorial(num));
return 0;
}

b) Program to print Fibonacci series using recursion:


#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n;
printf("Enter a number\n");
scanf("%d",&n);
for (int i = 0; i < n; i++) {
printf("%d ", fibonacci(i));
}
return 0;
}

2. Structure / Union
i) Simple program using structure
a) Program to store and display student details:
#include <stdio.h>
struct Student {
char name[50];
int roll;
float marks;
};
int main() {
struct Student s1 = {"John", 101, 95.5};
printf("Name: %s\nRoll: %d\nMarks: %.2f\n", s1.name, s1.roll,
s1.marks);
return 0;
}

b) Program to store and display employee details:


#include <stdio.h>
struct Employee {
char name[50];
int id;
float salary;};
int main() {
struct Employee e1 = {"Alice", 101, 50000.0};
printf("Name: %s\nID: %d\nSalary: %.2f\n", e1.name, e1.id,
e1.salary);
return 0;}

c) Program to calculate the difference between two dates:


#include <stdio.h>
struct Date {
int day, month, year;
};
int main() {
struct Date d1 = {10, 1, 2020};
struct Date d2 = {5, 1, 2020};
int diff = d1.day - d2.day;
printf("Difference: %d days\n", diff);
return 0;
}

d) Program to store and display book details:


#include <stdio.h>
struct Book {
char title[50];
char author[50];
float price;
};
int main() {
struct Book b1 = {"Harry Potter", "J.K Rowling", 499.99};
printf("Title: %s\nAuthor: %s\nPrice: %.2f\n", b1.title,
b1.author, b1.price);
return 0;
}

ii) Array with structure


a) Program to store and display details of 5 students:
#include <stdio.h>
struct Student {
char name[50];
int roll;
float marks;
};
int main() {
struct Student s[5];
for (int i = 0; i < 5; i++) {
printf("Enter name, roll, and marks for student %d: ", i + 1);
scanf("%s %d %f", s[i].name, &s[i].roll, &s[i].marks);
}
for (int i = 0; i < 5; i++) {
printf("Student %d: %s, %d, %.2f\n", i + 1, s[i].name,
s[i].roll, s[i].marks);
}
return 0;
}

b) Program to find the highest marks scored by a student:


#include <stdio.h>
struct Student {
char name[50];
float marks;
};
int main() {
struct Student s[5];
for (int i = 0; i < 5; i++) {
printf("Enter name and marks for student %d: ", i + 1);
scanf("%s %f", s[i].name, &s[i].marks);
}
float maxMarks = s[0].marks;
int index = 0;
for (int i = 1; i < 5; i++) {
if (s[i].marks > maxMarks) {
maxMarks = s[i].marks;
index = i;
}
}
printf("Highest marks: %s with %.2f\n", s[index].name,
maxMarks);
return 0;
}

c) Program to sort students based on marks:


#include <stdio.h>
struct Student {
char name[50];
float marks;};
int main() {
struct Student s[5] = {{"John", 95.5}, {"Alice", 88.0}, {"Bob",
92.0}, {"Eve", 85.5}, {"Mike", 90.0}};
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
if (s[i].marks < s[j].marks) {
struct Student temp = s[i];
s[i] = s[j];
s[j] = temp;
}}}
for (int i = 0; i < 5; i++) {
printf("Student %d: %s, %.2f\n", i + 1, s[i].name,
s[i].marks);
}
return 0;}

iii) Union (To find the size of union)


#include <stdio.h>
union Data {
int i;
float f;
char str[20];
};
int main() {
union Data d;
printf("Size of union: %lu\n", sizeof(d));
return 0;
}
3. Pointer
i) Simple program using pointer
a) Program to demonstrate pointer declaration and
initialization:
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
printf("Value of x: %d\n", *p);
return 0;
}
b) Program to swap two numbers using pointers
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;}
int main() {
int x = 5, y = 10;
swap(&x, &y);
printf("x: %d, y: %d\n", x, y);
return 0;}

c) Program to access array elements using pointers:


#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
for (int i = 0; i < 5; i++) {
printf("%d ", *(p + i));
}
return 0;
}
d) Program to find the length of a string using pointers:
#include <stdio.h>
int main() {
char str[100] = "Hello";
char *p = str;
int len = 0;
while (*p != '\0') {
len++;
p++; }
printf("Length: %d\n", len);
return 0;}

e) Program to demonstrate pointer arithmetic:


#include <stdio.h>
int main() {
int arr[5] = {10, 20, 30, 40, 50};
int *p = arr;
printf("Value at p: %d\n", *p);
p++;
printf("Value at p after increment: %d\n", *p);
return 0;
}
ii) Call by value and Call by Reference
a) Program to demonstrate call by value:
#include <stdio.h>
int add(int x, int y){
int z = x + y;
return z; }
int main(){
int a = 10, b = 20;
int c = add(a, b);
printf("Addition: %d", c); }

b) Program to demonstrate call by reference:


#include <stdio.h>
void increment(int *var)
{
*var = *var+1;
}
int main()
{
int num=20;

increment(&num);
printf("Value of num is: %d", num);
return 0;
}

4. File Handling
i) Simple program
a) Program to create a file and write data into it:
#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "w");
fprintf(file, "Hello, World!");
fclose(file);
printf("File created and data written.\n");
return 0;
}
b) Program to read data from a file:
#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "r");
char ch;
while ((ch = fgetc(file)) != EOF) {
printf("%c", ch);
}
fclose(file);
return 0;
}

ii) Reading / Writing with file


a) Program to read and display the contents of a file:
#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "r");
char ch;
while ((ch = fgetc(file)) != EOF) {
printf("%c", ch);
}
fclose(file);
return 0;
}

b) Program to append data to a file:


#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "a");
fprintf(file, "\nAppended text.");
fclose(file);
printf("Data appended.\n");
return 0;
}
c) Program to copy the contents of one file to another:
#include <stdio.h>
int main() {
FILE *source = fopen("source.txt", "r");
FILE *dest = fopen("destination.txt", "w");
char ch;
while ((ch = fgetc(source)) != EOF) {
fputc(ch, dest);
}
fclose(source);
fclose(dest);
printf("File copied successfully.\n");
return 0;}
d) Program to count the number of lines in a file:
#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "r");
char ch;
int lines = 0;
while ((ch = fgetc(file)) != EOF) {
if (ch == '\n') lines++; }
fclose(file);
printf("Number of lines: %d\n", lines);
return 0;}

B) JavaScript
1) Simple Program using JavaScript
a) Program to display "Hello, World!":
<!DOCTYPE html>
<html>
<body>
<script>
document.write("Hello, World!");
</script>
</body>
</html>
b) Program to add two numbers and display the result:
<!DOCTYPE html>
<html>
<body>
<script>
let num1 = 5, num2 = 10;
document.write("Sum: " + (num1 + num2));
</script>
</body>
</html>

c) Program to display the current date and time:


<!DOCTYPE html>
<html>
<body>
<script>
let now = new Date();
document.write("Current Date and Time: " + now);
</script>
</body>
</html>
2) Using control structure (if, ifelse, if-else-if, switch
case)
a) Program to check if a number is positive, negative, or zero:
<!DOCTYPE html>
<html>
<body>
<script>
var num = prompt("Enter a number");
if (num > 0) {
document.write("Positive");
} else if (num < 0) {
document.write("Negative");
} else {
document.write("Zero");}
</script>
</body>
</html>

b) Program to check if a number is positive:


<!DOCTYPE html>
<html>
<body>
<script>
let num = 10;
if (num > 0) {
document.write("The number is positive.");
}
</script>
</body>
</html>

c) Program to check if a number is even or odd.


<!DOCTYPE html>
<html>
<body>
<script>
var num = prompt("Enter a number");
if (num % 2 === 0) {
document.write("The number is even.");
} else {
document.write("The number is odd.");
}
</script>
</body>
</html>
d) Program to display the day of the week based on a
number:
<!DOCTYPE html>
<html>
<body>
<script>
var day=3;
switch (day) {
case 1:
document.write("Monday");
break;
case 2:
document.write("Tuesday");
break;
case 3:
document.write("Wednesday");
break;
case 4:
document.write("Thursday");
break;
case 5:
document.write("Friday");
break;
case 6:
document.write("Saturday");
break;
case 7:
document.write("Sunday");
break;
default:
document.write("Invalid day"); }
</script>
</body>
</html>

e) Program to check if a year is a leap year:


<!DOCTYPE html>
<html>
<body>
<script>
var year = prompt(“Enter The Year”);
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
document.write("Leap year");
} else {
document.write("Not a leap year");
}
</script>
</body>
</html>

f) Program to find the largest of three numbers:


<!DOCTYPE html>
<html>
<body>
<script>
let a = 5, b = 10, c = 7;
if (a > b && a > c) {
document.write("Largest: " + a);
} else if (b > a && b > c) {
document.write("Largest: " + b);
} else {
document.write("Largest: " + c);
}
</script>
</body>
</html>
3) Using Loop (for, while and do while loop)
a) Program to print numbers from 1 to 10:
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 1; i <= 10; i++) {
document.write(i + "<br>");
}
</script>
</body>
</html>

b) Program to print numbers from 1 to 5:


<!DOCTYPE html>
<html>
<body>
<script>
let i = 1;
while (i <= 5) {
document.write(i + "<br>");
i++;
}
</script>
</body>
</html>

c) Program to print numbers from 1 to 5:


<!DOCTYPE html>
<html>
<body>
<script>
let i = 1;
do {
document.write(i + "<br>");
i++;
} while (i <= 5);
</script>
</body>
</html>

4) Function in JavaScript /Object


a) A function to add two numbers and display the result.
<!DOCTYPE html>
<html>
<body>
<script>
function add(a, b) {
return a + b;
}
let num1 = 5, num2 = 10;
let result = add(num1, num2);
document.write("Sum of " + num1 + " and " + num2 + " is: " +
result);
</script>
</body>
</html>

b) An object to store and display student details.


<body>
<script>
let student = {
name: "Nitya Kaphle",
age: 17,
rollNo: 31,
displayDetails: function() {
document.write("Name: " + this.name + "<br>");
document.write("Age: " + this.age + "<br>");
document.write("Roll No: " + this.rollNo + "<br>");
}
};
student.displayDetails();
</script>
</body>
</html>
5) Event Handling in JS
a) Program to Change Background Color on Button Click
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<html>
<body>
<button onclick="changeBackgroundColor()">Change
Background Color</button>
<script>
function changeBackgroundColor() {
document.body.style.backgroundColor = "lightblue"; }
</script>
</body></html>

b) Program to Change Text on Mouseover


<!DOCTYPE html>
<html>
<body>
<p onmouseover="changeText(this)">Hover over me!</p>
<script>
function changeText(element) {
element.innerHTML = "Mouse is over me!";
}
</script>
</body>
</html>
6) Form Validation
<!DOCTYPE html>
<html>
<head>
<title>Form Validation Example</title>
<style>
.error {
color: red;
font-size: 14px;
}
</style>
</head>
<body>
<h2>Form Validation Example</h2>
<form onsubmit="return validateForm()">

<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br>
<span id="nameError" class="error"></span><br><br>
<label for="email">Email:</label><br>
<input type="text" id="email" name="email"><br>
<span id="emailError" class="error"></span><br><br>

<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br>
<span id="passwordError" class="error"></span><br><br>

<input type="submit" value="Submit">


</form>

<script>
function validateForm() {

let name = document.getElementById("name").value.trim();


let email = document.getElementById("email").value.trim();
let password = document.getElementById("password").value.trim();

document.getElementById("nameError").innerHTML = "";
document.getElementById("emailError").innerHTML = "";
document.getElementById("passwordError").innerHTML = "";

if (name === "") {


document.getElementById("nameError").innerHTML = "Name is required.";
return false;
}

let emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;


if (!emailPattern.test(email)) {
document.getElementById("emailError").innerHTML = "Please enter a valid
email address.";
return false;
}
if (password.length < 6) {
document.getElementById("passwordError").innerHTML = "Password must
be at least 6 characters long.";
return false;
}

alert("Form submitted successfully!");


return true;
}

</body>
</html>

C. Database Management
Database Management involves the efficient and organized
handling of data within a database system. This process includes
creating, updating, retrieving, and managing data while ensuring
its integrity, security, and accessibility.
Here are key aspects of Database Management:
1. Database Systems: - A database is a structured collection of
data organized in a way that facilitates efficient retrieval and
manipulation. Database management systems (DBMS) are software
applications that provide an interface to interact with databases.

2. Data Modeling: - Data modeling involves designing the structure


of the database to represent real-world entities and their
relationships. It includes defining tables, fields, and constraints.

3. Database Schema: - The database schema defines the structure


of the database, specifying tables, fields, data types, and
relationships. It serves as a blueprint for organizing and storing
data.
4. Query Language: - SQL (Structured Query Language) is the
standard language for interacting with relational databases. It
allows users to perform operations such as data retrieval, insertion,
updating, and deletion.

5. Data Integrity: - Maintaining data integrity ensures that data


remains accurate and consistent throughout the database. This
involves enforcing constraints, such as primary keys, foreign keys,
and unique constraints.

6. Normalization: - Normalization is the process of organizing data


to minimize redundancy and dependency by dividing large tables
into smaller, related tables. It helps improve data integrity and
reduces the likelihood of data anomalies.

1: Create a database
CREATE DATABASE EMPLOYEE;
2: Create a table
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL, dept
TEXT NOT NULL
);

3: Insert values into the table


INSERT INTO EMPLOYEE VALUES (0001, 'Ram Krishna',
'Business'),
(0002, 'Bal Krishna', 'Accounting'), (0003, 'Shyam Krishna',
'Sales');
4: Select values from the table
SELECT * FROM EMPLOYEE
5: Update values in the table
UPDATE EMPLOYEE SET dept='Department Head' WHERE
empId=0001;

6: Delete values in the table


DELETE FROM EMPLOYEE WHERE empId=0003;
Conclusion

In summary, our project work involving JavaScript, C


programming, functions in the C language, and Database
Management Systems have provided us with a deep understanding of
these essential concepts. JavaScript, as a scripting language, is
crucial for creating dynamic and interactive web experiences.

Our study encompassed fundamental JavaScript principles,including


variables, data types, operators, control structures,functions, and
objects. C programming, a high level procedural language, is
extensively employed in system programming and application
development.

We explored key elements of C programming, such as data types,


control structures, functions, arrays, pointers, and advanced subjects
like dynamic memory allocation, file handling, and structures.
Functions in C, which act as reusable code segments, were thoroughly
investigated, focusing on aspects like syntax, structure, function
prototypes, parameter passing, return values, recursion, function
overloading, and function pointers.

Database Management Systems (DBMS) were examined as vital


software solutions for efficient data management. Our study included
foundational topics such as data modeling, schema design, SQL
queries, and database normalization, along with more advanced areas
like transaction management, indexing, and data warehousing.

In conclusion, our project work has equipped us with the skills and
knowledge required to develop sophisticated web applications, system
software, and database-driven solutions. These competencies are
invaluable for aspiring software developers, and we feel well-prepared
to implement them in practical, real-world situations.
Bibliography

- Roshan Dangi(2022) A Text Book Of Computer


ScienceXII,Heritage Publication
- Elmasri, R., & Navathe, S. B. (2015). Fundamentals of
Database Systems (7th ed.). Pearson
- Date, C. J. (2004). An Introduction to Database Systems
(8th ed.). Addison-Wesley
- Schildt, H. (2018). C: The Complete Reference (4th ed.).
McGraw-Hill Education
- Flanagan, D. (2020). JavaScript: The Definitive Guide
(7th ed.). O'Reilly Media Web

References:

- W3Schools. (n.d.). JavaScript Tutorial:


https://www.w3schools.com/js/
- GeeksforGeeks. (n.d.). C Programming
Language: https://www.geeksforgeeks.org/c-programming-
language/

- Mozilla Developer Network (MDN):


https://developer.mozilla.org/en-US/

You might also like