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

Computer Project

Uploaded by

manav.koirala
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Computer Project

Uploaded by

manav.koirala
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 64

COMPUTER PROJECT WORK ON C PROGRAMMING

Name of Students
Manav Koirala
Bibas Adhikari
Nitanta Acharya
Nabin Pandey
Class:12
Section:D8
Shift: Day
Name of Department Of HOD:Gaurav Mishra
Submission Date: 2081-10-
CERTIFICATE OF AUTHENTICITY

We hereby declare that all the works done here are original and are not plagiarized or copied
and are not submitted in others besides in this project. This Project title “COMPUTER
PROJECT WORK ON C PROGRAMMING” was also done under the guidance of our
Computer Teacher Mr.Gaurav Mishra.

Name: Submitted To:


Manav Koirala Gaurav Mishra
Bibas Adhikari HOD Of Computer Department
Nitanta Acharya
Nabin Pandey
Acknowledgement

We would like to thank our friends and family for helping us do this project. We also like to
thank our Computer Department for allowing us to work in this wonderful project. We also
like to thank our Computer Teacher Mr Gaurab sir for allowing us to work in this wonderful
project as well as his guidance in this project.

Name:
Manav Koirala
Bibas Adhikari
Nitanta Acharya
Nabin Pandey

I
Table of Content

Table of Content··························································································II
Abstract···································································································IV
1. School Management System·········································································1
1.1 Introduction······················································································1
1.2 Literature Work··················································································1
1.3 System Design···················································································2
1.4 Implementation··················································································3
1.5 Source Code······················································································5
1.6 Testing And Resulting········································································18
2. Library Management System·······································································19
2.1 Introduction·····················································································19
2.2 Literature Work················································································19
2.3 System Design·················································································19
2.4 Implementation·················································································20
2.5 Source code·····················································································22
2.6 Testing And Resulting········································································30
3.TIC TAC TOE·························································································31
3.1 Introduction·····················································································31
3.2 Literature Work················································································31
3.3 System Design·················································································32
3.4 Implementation·················································································32
3.5 Source Code····················································································33
3.6 Testing And Result············································································37
4. Bus Management System············································································38
4.1 Introduction·····················································································38
4.2 Literature Work················································································38
4.3 System Design·················································································38
4.4 Implementation·················································································39
4.5 Source Code····················································································40
4.6 Testing And Results···········································································44
5. Telecom Billing Systems············································································45
5.1 Introduction·····················································································45
5.2 Literature review···············································································45
5.3 System design··················································································46
5.4 Implementation·················································································46
5.5 Source code····················································································48
5.6 Testing and results·············································································52
6. Conclusion·····························································································54
6.1 School Management Sytem··································································54

II
6.2 Library Management System·································································54
6.3 Tic Tac Toe·····················································································54
6.4 Bus Management Sytem······································································55
7. Refrence································································································56

III
Abstract

This project is divided into four main topics:


Firstly, In the School Management System we defined two separate files i.e. for students and
for teachers. Then we gave a set of choices for operator(user) to proceed what to do and to
follow up after doing a set of task.In this way an user can do multiple works at same time
both in teacher as well as in students database.

Secondly, In Library Management System we defined a library.txt as a main file i.e. for
entering detail of Books as well as when it was taken and as well as for other manipulation in
the given system.
Thirdly, In the game of Tic Tac Toe is a simple, two-player game played on a 3x3 grid.
Players take turns marking a square with either "X" or "O." The first player to align three of
their marks horizontally, vertically, or diagonally wins.

Fourthly, In Bus Reservation System is a streamlined application designed to facilitate


efficient management of bus operations. It enables users to add new buses, view existing bus
details, and book seats with ease.

Lastly, In Telecom Billing System is a software that manages data and processes to calculate
and send invoices for telecom services. It also tracks usage, collects payments, and generates
financial reports. Telecom service is one of the biggest services having millions of users and
the data managed by these companies are quite large so, we need some software system to
efficiently manage this data.

IV
V
1. School Management System

1.1 Introduction

School Management System is a fundamental process of using file handling and Structure
work. The process done in this project is that two main files are declared one for teachers and
other for students and independently we can access them while remaining and running in the
same command prompt. Here we can easily check students' details as well as teachers' details
as well.
We can add new details as well as delete or edit the details using ID for both teacher and
student and also we can check all the details that are entered in the file. In this way we can
easily manipulate any data we need. In this System we also implement it in such a way that it
works so we can see Grade 1 to Grade 12 at once separately.
The given Program ask for Students following parameters like; ID,Name,Email,Phone
Number,Address as well as Guardian Name and their phone number as well as their Class
and Section.Whereas for teachers the following parameters are asked like; CID(Colleague
ID),Name, Phone Department, Salary , Experience and their Salary.

Hence,we can Enter,View,Edit,Delete Student and Teacher as well. This allows us to easily
administer any and all works that can be done in the given system.

1.2 Literature Work

Before I started the project I used some example shown in our text book “TEXTBOOK OF
COMPUTER SCIENCE” by Dr. Rupendra Man Rajkumar and his example for the given
work in “SCHOOL MANAGEMENT SYSTEM” especially on his work in File Handling
with Structure Program for better understanding of this project.

1
1.3 System Design

2
1.4 Implementation

The following program has a main function which has a switch case and do ... .while loop
such that the user can choose one of many options.
// Student Structure
struct student {
int ID;
char Name[100];
char Address[100];
char Phone[15];
char Email[50];
int Class;
char Section[5];
char GuardianName[100];
char GuardianPhone[15];
};

// Teacher Structure
struct teacher {
int CID;
char Name[100];
char Department[100];
char Phone[15];
char Email[50];
float Salary;
int Experience;
char Address[100];
};
The option here to access are as follows:
1. Register Student
2. Register Teacher

3
3. View Student Records
4. View Teacher Records
5. Edit Student Data
6.Delete Student Data
7.Edit Teacher Data
8.Delete Teacher Data
9. Exit
Similarly two structures one for Teacher and other for student is declared and as stated above
parameters are defined . The two files are also declared as “teacher.txt” for teacher and
“student.txt” for student.

For each option a function is declared such that it works properly to connect them. For
Register Student function RegisterStudent() is declared where record of student can be
added. Similarly RegisterTeacher() function is declared where record of teacher can be
stored. ViewStudentRecords() allows us to see record of student grade wise whereas
ViewTeacherRecords() function allows us to see record of teacher with their department as
well.For any mistake EditStudent() can be called to Edit detail of student using ID as
searching whereas DeleteStudent() can be initiated to delete the whole detail of student using
ID as well.Similarly EditTeacher() and DeleteTeacher() can be called to Edit or Delete detail
of teacher using CID as same instance as that of student.
printf("\nEnter Student Details:\n");
printf("ID: ");
scanf("%d", &s.ID);
printf("Name: ");
scanf(" %[^\n]s", s.Name);
printf("Address: ");
scanf(" %[^\n]s", s.Address);
printf("Phone: ");
scanf("%s", s.Phone);
printf("Email: ");
scanf("%s", s.Email);
printf("Class: ");
scanf("%d", &s.Class);
printf("Section: ");

4
scanf("%s", s.Section);
printf("Guardian Name: ");
scanf(" %[^\n]s", s.GuardianName);
printf("Guardian Phone: ");
scanf("%s", s.GuardianPhone);

Lastly, The given code is in the do.. .while loop so it can only be exited if and only if no 9 is
given which exits the program or there is Error in File Handling. The File Handling checks
the opening and closing of a file for all instances . Furthermore temp file is used for changes
and is immediately removed during the execution of the program so no duplication is
allowed.
FILE *fp = fopen("students.txt", "a");
if (fp == NULL) {
printf("ERROR: Unable to open file.\n");
return 1;
}

1.5 Source Code

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

// Student Structure
struct student {
int ID;
char Name[100];
char Address[100];
char Phone[15];
char Email[50];
int Class;
char Section[5];
char GuardianName[100];
char GuardianPhone[15];

5
};

// Teacher Structure
struct teacher {
int CID;
char Name[100];
char Department[100];
char Phone[15];
char Email[50];
float Salary;
int Experience;
char Address[100];
};

// Function Declarations
int RegisterStudent();
int RegisterTeacher();
int ViewStudentRecords();
int ViewTeacherRecords();
int EditStudent();
int DeleteStudent();
int EditTeacher();
int DeleteTeacher();

int main()
{
int choice;

do {
printf("\n1. Register Student\n2. Register Teacher\n3. View Student Records\n4. View
Teacher Records\n5. Edit Student Data \n6.Delete Student Data\n7.Edit Teacher Data\n
8.Delete Teacher Data \n9. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

6
switch (choice) {
case 1:
RegisterStudent();
break;
case 2:
RegisterTeacher();
break;
case 3:
ViewStudentRecords();
break;
case 4:
ViewTeacherRecords();
break;
case 5:
EditStudent();
break;
case 6:
DeleteStudent();
break;

case 7:
EditTeacher();
break;
case 8:
DeleteTeacher();
break;
case 9:
printf("Exiting the program.\n");
break;
default:
printf("Invalid choice. Try again.\n");
}
} while (choice !=9 );

7
return 0;
}

// Function to Register a Student


int RegisterStudent() {
struct student s;

// Open the file for appending


FILE *fp = fopen("students.txt", "a");
if (fp == NULL) {
printf("ERROR: Unable to open file.\n");
return 1;
}

// Input updated student details


printf("\nEnter Student Details:\n");
printf("ID: ");
scanf("%d", &s.ID);
printf("Name: ");
scanf(" %[^\n]s", s.Name);
printf("Address: ");
scanf(" %[^\n]s", s.Address);
printf("Phone: ");
scanf("%s", s.Phone);
printf("Email: ");
scanf("%s", s.Email);
printf("Class: ");
scanf("%d", &s.Class);
printf("Section: ");
scanf("%s", s.Section);
printf("Guardian Name: ");
scanf(" %[^\n]s", s.GuardianName);

8
printf("Guardian Phone: ");
scanf("%s", s.GuardianPhone);

// Write the student details to the file


fwrite(&s, sizeof(struct student), 1, fp);
printf("\nStudent Registration Successful!\n");

fclose(fp);
}

// Function to Register a Teacher


int RegisterTeacher() {
struct teacher t;

// Open the file for appending


FILE *fp = fopen("teachers.txt", "a");
if (fp == NULL) {
printf("ERROR: Unable to open file.\n");
return 1;
}

// Input teacher details


printf("\nEnter Teacher Details:\n");
printf("CID (Teacher ID): ");
scanf("%d", &t.CID);
printf("Name: ");
scanf(" %[^\n]s", t.Name);
printf("Department: ");
scanf(" %[^\n]s", t.Department);
printf("Phone: ");
scanf("%s", t.Phone);
printf("Email: ");
scanf("%s", t.Email);
printf("Salary: ");

9
scanf("%f", &t.Salary);
printf("Experience (in years): ");
scanf("%d", &t.Experience);
printf("Address: ");
scanf(" %[^\n]s", t.Address);

// Write the teacher details to the file


fwrite(&t, sizeof(struct teacher), 1, fp);
printf("\nTeacher Registration Successful!\n");

fclose(fp);
}

// Function to View All Student Records


int ViewStudentRecords() {
FILE *fp = fopen("students.txt", "r");
if (fp == NULL) {
printf("\nNo student records found.\n");
return 1;
}

struct student s;
printf("Grade wise list");
while (fread(&s, sizeof(struct student), 1, fp)) {
for (int i=0;i<=12;i++)
{
if(s.Class==i)
{
printf("GRADE %d\n",i);
printf("\nID: %d\nName: %s\nAddress: %s\nPhone: %s\nEmail: %s\nClass: %d\
nSection: %s\nGuardian Name: %s\nGuardian Phone: %s\n",
s.ID, s.Name, s.Address, s.Phone, s.Email, s.Class, s.Section, s.GuardianName,
s.GuardianPhone);
}

10
}
}

fclose(fp);
}

// Function to View All Teacher Records


int ViewTeacherRecords() {
FILE *fp = fopen("teachers.txt", "r");
if (fp == NULL) {
printf("\nNo teacher records found.\n");
return 1;
}

struct teacher t;
printf("\nAll Teacher Records:\n");
while (fread(&t, sizeof(struct teacher), 1, fp)) {
printf("\nCID: %d\nName: %s\nDepartment: %s\nPhone: %s\nEmail: %s\nSalary: %.2f\
nExperience: %d years\nAddress: %s\n",
t.CID, t.Name, t.Department, t.Phone, t.Email, t.Salary, t.Experience, t.Address);
}

fclose(fp);
}
// Function to Edit a Student Record
int EditStudent() {
FILE *fp, *temp;
struct student s;
int ID, found = 0;

fp = fopen("students.txt", "r");
if (fp == NULL) {
printf("No student records found.\n");
return 1;

11
}

temp = fopen("temp.txt", "w");


if (temp == NULL) {
printf("Unable to open temporary file.\n");
fclose(fp);
return 1;
}

printf("Enter Student ID to Edit: ");


scanf("%d", &ID);

while (fread(&s, sizeof(struct student), 1, fp)) {


if (s.ID == ID) {
found = 1;
printf("Editing Student ID: %d\n", s.ID);
printf("Enter New Name: ");
scanf(" %[^\n]s", s.Name);
printf("Enter New Address: ");
scanf(" %[^\n]s", s.Address);
printf("Enter New Phone: ");
scanf("%s", s.Phone);
printf("Enter New Email: ");
scanf("%s", s.Email);
printf("Enter New Class: ");
scanf("%d", &s.Class);
printf("Enter New Section: ");
scanf("%s", s.Section);
printf("Enter New Guardian Name: ");
scanf(" %[^\n]s", s.GuardianName);
printf("Enter New Guardian Phone: ");
scanf("%s", s.GuardianPhone);
}
fwrite(&s, sizeof(struct student), 1, temp);

12
}

fclose(fp);
fclose(temp);

if (found==1) {
remove("students.txt");
rename("temp.txt", "students.txt");
printf("Student record updated successfully.\n");
} else {
remove("temp.txt");
printf("Student ID not found.\n");
}
}

// Function to Delete a Student Record


int DeleteStudent() {
FILE *fp, *temp;
struct student s;
int ID, found = 0;

fp = fopen("students.txt", "r");
if (fp == NULL) {
printf("No student records found.\n");
return 1;
}

temp = fopen("temp.txt", "w");


if (temp == NULL) {
printf("Unable to open temporary file.\n");
fclose(fp);
return 1;
}

13
printf("Enter Student ID to Delete: ");
scanf("%d", &ID);

while (fread(&s, sizeof(struct student), 1, fp)) {


if (s.ID == ID) {
found = 1;
printf("Student ID: %d deleted successfully.\n", s.ID);
} else {
fwrite(&s, sizeof(struct student), 1, temp);
}
}

fclose(fp);
fclose(temp);

if (found==1) {
remove("students.txt");
rename("temp.txt", "students.txt");
} else {
remove("temp.txt");
printf("Student ID not found.\n");
}
}

// Function to Edit a Teacher Record


int EditTeacher() {
FILE *fp, *temp;
struct teacher t;
int CID, found = 0;

fp = fopen("teachers.txt", "r");
if (fp == NULL) {
printf("ERROR AT OPENING TEACHER FILE\n");
return 1;

14
}

temp = fopen("temp.txt", "w");


if (temp == NULL) {
printf("Unable to open temporary file.\n");
fclose(fp);
return 1;
}

printf("Enter Teacher CID to Edit: ");


scanf("%d", &CID);

while (fread(&t, sizeof(struct teacher), 1, fp)) {


if (t.CID == CID) {
found = 1;
printf("Editing Teacher CID: %d\n", t.CID);
printf("Enter New Name: ");
scanf(" %[^\n]s", t.Name);
printf("Enter New Department: ");
scanf(" %[^\n]s", t.Department);
printf("Enter New Phone: ");
scanf("%s", t.Phone);
printf("Enter New Email: ");
scanf("%s", t.Email);
printf("Enter New Salary: ");
scanf("%f", &t.Salary);
printf("Enter New Experience: ");
scanf("%d", &t.Experience);
printf("Enter New Address: ");
scanf(" %[^\n]s", t.Address);
}
fwrite(&t, sizeof(struct teacher), 1, temp);
}

15
fclose(fp);
fclose(temp);

if (found==1) {
remove("teachers.txt");
rename("temp.txt", "teachers.txt");
printf("Teacher record updated successfully.\n");
} else {
remove("temp.txt");
printf("Teacher CID not found.\n");
}
}

// Function to Delete a Teacher Record


int DeleteTeacher() {
FILE *fp, *temp;
struct teacher t;
int CID, found = 0;

fp = fopen("teachers.txt", "r");
if (fp == NULL) {
printf("No teacher records found.\n");
return 1;
}

temp = fopen("temp.txt", "w");


if (temp == NULL) {
printf("Unable to open temporary file.\n");
fclose(fp);
return 1;
}

printf("Enter Teacher CID to Delete: ");


scanf("%d", &CID);

16
while (fread(&t, sizeof(struct teacher), 1, fp)) {
if (t.CID == CID) {
found = 1;
printf("Teacher CID: %d deleted successfully.\n", t.CID);
} else {
fwrite(&t, sizeof(struct teacher), 1, temp);
}
}

fclose(fp);
fclose(temp);

if (found==1) {
remove("teachers.txt");
rename("temp.txt", "teachers.txt");
}
else {
remove("temp.txt");
printf("Teacher CID not found.\n");
}
}

17
1.6 Testing And Resulting

SYSTEM DESIGN

18
2. Library Management System

2.1 Introduction

In the Library Management System a Main Screen is there from which we can choose
whether to add or lend a book as well as search the book and who is using it easily. We can
also see which books are lended to other people which are not and are able to easily access
the return the book function as well.
All of the function requires the book Id for implementing the add ,lend,search function in the
given program.

2.2 Literature Work

Before I started the project I used some example shown in our textbook “TEXTBOOK OF
COMPUTER SCIENCE” by Dr. Rupendra Man Rajkumar and his example for the given
work in “SCHOOL MANAGEMENT SYSTEM” especially on his work in File Handling
with Structure Program for better understanding of this project.

2.3 System Design

19
2.4 Implementation
1. Main Menu:

The main entry point of the library management system.


Displays the main menu options for the user to choose from.
Redirects the user to the corresponding functionality based on their
selection.

2. Add Book:

Allows the user to add a new book to the library.Opens the

'Library.txt' file in append mode to add the new book record.

Prompts the user for the book ID, name, and author.

Creates a 'books' structure with the user input.Writes the

book details to the file.Closes the file and displays a success

message.

3. Lend Book:

Allows the user to lend a book to a borrower.

Prompts the user for the book ID.Opens the 'Library.txt'

file in read mode and 'temp.txt' file in write mode.Reads

each book record from 'Library.txt'.Checks if the book

ID matches the user input.If a match is found,

prompts the user for the borrower's name, ID, and date,

and updates the book record with the borrower details.

Writes the updated record to 'temp.txt'.If no match is

20
found, writes the record to 'temp.txt' as is.Closes both files.If a match was found, deletes
'Library.txt' and renames 'temp.txt' to 'Library.txt'.If no match was found, deletes
'temp.txt'.Displays the appropriate success or error message.

4. Search Book:

Allows the user to search for a book by its ID


.Prompts the user for the book ID.Opens the 'Library.txt' file in read mode.Reads each book
record from the file.Checks if the book ID matches the user input.If a match is found,
displays the book details.If no match is found, displays a 'Not Found' message.Closes the file.
5. Return Book:

Allows the user to return a borrowed book.

Prompts the user for the book ID.Opens the 'Library.txt' file in

read+write mode and 'temp.txt' file in write mode.

Reads each book record from 'Library.txt'

.Checks if the book ID matches the user input

.If a match is found, resets the borrower details in the book record

.Writes the updated record to 'temp.txt'.If no match is found, writes the record to 'temp.txt' as
is.Closes both files.

If a match was found, deletes 'Library.txt' and renames 'temp.txt' to 'Library.txt'.

If no match was found, deletes 'temp.txt'.Displays the appropriate

success or error message.

6. View Lent Books:

Displays the books that have not been returned.

Opens the 'Library.txt' file in read mode.Reads each book

record from the file

21
.Checks if the book has a borrower ID

.If the book is borrowed, displays the book details.

If no books are currently borrowed, displays a message.Closes the file.

2.5 Source code

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

// Structure definition
struct books {
int ID;
char Book[20];
char Author[20];
int IDBorrower;
char Borrower_Name[40];
char Date[10];
};

// Function prototypes
int Add_Books();
int Books_Taken();
int Search_Books();
int Book_Returned();
int Books_Not_Returned();

int main() {
int a;
do {

22
printf("\nENTER\n1. ADD BOOK\n2. Book Lend\n3. Search Book\n4. Return Book\n5.
Lended Book\n6. Exit\n");
printf("Your choice: ");
scanf("%d", &a);

switch (a) {
case 1: Add_Books(); break;
case 2: Books_Taken(); break;
case 3: Search_Books(); break;
case 4: Book_Returned(); break;
case 5: Books_Not_Returned(); break;
case 6:
printf("Exiting the program.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (a != 6);
return 0;
}

// Add a new book to the library


int Add_Books() {
FILE *fp = fopen("Library.txt", "a");
if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}

struct books book;


printf("Enter ID of the book: ");
scanf("%d", &book.ID);
printf("Enter name of the book: ");
scanf(" %[^\n]%*c", book.Book);

23
printf("Enter name of the author: ");
scanf(" %[^\n]%*c", book.Author);

fprintf(fp, "%d\t%s\t%s\n", book.ID, book.Book, book.Author);


fclose(fp);
printf("Book added successfully.\n");
return 0;
}

// Lend a book to a borrower


int Books_Taken() {
int Id;
printf("Enter ID of the book: ");
scanf("%d", &Id);

FILE *fp = fopen("Library.txt", "r");


if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}

struct books book;


FILE *tempFile = fopen("temp.txt", "w");
if (tempFile == NULL) {
printf("Error creating temporary file.\n");
fclose(fp);
return 1;
}

int found = 0;
while (fscanf(fp, "%d\t%[^\t]\t%[^\n]\n", &book.ID, book.Book, book.Author) != EOF) {
if (book.ID == Id) {
found = 1;
printf("Enter borrower's name: ");

24
scanf(" %[^\n]%*c", book.Borrower_Name);
printf("Enter borrower's ID: ");
scanf("%d", &book.IDBorrower);
printf("Enter date (DD/MM/YYYY): ");
scanf(" %[^\n]%*c", book.Date);
fprintf(tempFile, "%d\t%s\t%s\t%d\t%s\t%s\n", book.ID, book.Book, book.Author,
book.IDBorrower, book.Borrower_Name, book.Date);
} else {
fprintf(tempFile, "%d\t%s\t%s\n", book.ID, book.Book, book.Author);
}
}

fclose(fp);
fclose(tempFile);

if (found == 1) {
remove("Library.txt");
rename("temp.txt", "Library.txt");
printf("Book lent successfully.\n");
} else {
remove("temp.txt");
printf("Book with ID %d not found.\n", Id);
}
return 0;
}

// Search a book
int Search_Books() {
int ID;
struct books book; // Declare an instance of the books structure

printf("ENTER BOOK ID TO SEARCH: ");

25
scanf("%d", &ID);

FILE *fp = fopen("Library.txt", "r"); // Open file in read mode


if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}

// Read each line from the file and match the ID


while (fscanf(fp, "%d\t%s\t%s\t%d\t%s\t%s\n", &book.ID, book.Book, book.Author,
&book.IDBorrower, book.Borrower_Name, &book.Date) != EOF) {
if (book.ID == ID) {
printf("Book Found:\n");
printf("ID: %d\nName: %s\nAuthor: %s\nBorrower ID: %d\nBorrower Name: %s\
nDate: %s\n",
book.ID, book.Book, book.Author, book.IDBorrower, book.Borrower_Name,
book.Date);
break; // Exit loop as book is found
}
else
{
printf("NOT FOUND");
break;
}

fclose(fp); // Close the file

// If no match is found

}
// Function to display books that have not been returned

26
int Books_Not_Returned() {
FILE *fp = fopen("Library.txt", "r");
if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}

struct books book;


int found = 0;

printf("\nBooks not returned:\n");


printf("ID\tBook\tAuthor\tBorrower ID\tBorrower Name\tDate\n");

// Loop through the file and check for books that are still borrowed
while (fscanf(fp, "%d\t%[^\t]\t%[^\t]", &book.ID, book.Book, book.Author) != EOF) {
if (fscanf(fp, "\t%d\t%[^\t]\t%[^\n]\n", &book.IDBorrower, book.Borrower_Name,
book.Date) == 3) {
// Book is still borrowed
found = 1;
printf("%d\t%s\t%s\t%d\t%s\t%s\n", book.ID, book.Book, book.Author,
book.IDBorrower, book.Borrower_Name, book.Date);
}
}

if (found == 0) {
printf("No books are currently borrowed.\n");
}

fclose(fp); // Close file

}
int Book_Returned()
{
int Id = 0;

27
printf("Enter ID of the book: ");
scanf("%d", &Id);

FILE *fp = fopen("Library.txt", "r+");


if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}

struct books book;


FILE *temp = fopen("temp.txt", "w");
if (temp == NULL) {
printf("Error creating temporary file.\n");
fclose(fp);
return 1;
}
printf("%d",Id);
int found = 0;
while (fscanf(fp, "%d\t%s\t%s\t%d\t%s\t%s\n", &book.ID, book.Book, book.Author,
&book.IDBorrower, book.Borrower_Name, book.Date) != EOF) {
if (book.ID == Id) {
found = 1;
book.IDBorrower = 0;
strcpy(book.Borrower_Name, "");
strcpy(book.Date, "");
printf("Book returned successfully.\n");
break;
}
fprintf(temp, "%d\t%s\t%s\t%d\t%s\t%s\n", book.ID, book.Book, book.Author);

fclose(fp);
fclose(temp);

28
if (found == 1) {
remove("Library.txt");
rename("temp.txt", "Library.txt");

return 0;
} else {
remove("temp.txt");
printf("Book with ID %d not found.\n", Id);
return 1;
}
}

29
2.6 Testing And Resulting

30
3.TIC TAC TOE

3.1 Introduction

Tic-Tac-Toe is a classic two-player game, often played on a 3x3 grid. The objective is to get
three of your marks (either an "X" or an "O") in a row, either horizontally, vertically, or
diagonally. Players take turns placing their marks on the grid, with one player using "X" and
the other using "O." The game ends when one player achieves three marks in a row or all grid
spaces are filled, resulting in a draw if no one wins.

3.2 Literature Work

31
3.3 System Design

3.4 Implementation

The main() function is the entry point of the Tic Tac Toe game.It initializes the game by
setting the initial player, input, and status variables.The printBoard() function is called to
display the initial game board.The game loop continues until a win or draw condition is
met.Inside the game loop:The current player is determined,
and their mark ('X' or 'O') is set.The player is prompted for input,
and the input is validated.
The board is updated with the
player's mark.
The printBoard() function is called to display the updated board.

32
The checkWin() function is called to check for a win or draw condition.
The game result is handled, and the player is incremented for the next turn.
2. PrintBoard:
The printBoard() function is responsible for
clearing the screen and printing the Tic Tac Toe board
.It prints the game header, followed by the
three rows of the board, using the values stored in the board array.
3. CheckWin:
The checkWin() function checks for a win or draw condition.
It first checks for horizontal, vertical,
and diagonal wins by iterating through the
predefined winning combinations.
If a winning combination is found, the
function returns 1 to indicate a win.
If no winning combination is found,
the function checks for a draw by iterating through the board cells and ensuring that all cells
are either 'X' or 'O'.If a draw is detected, the function returns 0.If the game is still ongoing,
the function returns -1.

3.5 Source Code

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

// Function prototypes
void printBoard();
int checkWin();
void system();

// Global array to store the board state

33
char board[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

// Main function
void main() {
// Initialize variables
int player = 1, input, status = -1;

// Print the initial board


printBoard();

// Game loop
while (status == -1) {
// Switch player
player = (player % 2 == 0) ? 2 : 1;
// Determine the player's mark (X or O)
char mark = (player == 1) ? 'X' : 'O';

// Prompt the player for input


printf("Please enter Number For Player %d\n", player);
scanf("%d", &input);

// Check for invalid input


if (input < 1 || input > 9) {
printf("Invalid input\n");
continue; // Skip to the next iteration of the loop
}

// Update the board with the player's mark


board[input] = mark;

// Print the updated board


printBoard();

// Check for a win or a draw

34
int result = checkWin();

// Handle the game result


if (result == 1) {
printf("Player %d is the Winner\n", player);
return;
} else if (result == 0) {
printf("Draw\n");
return;
}

// Increment the player for the next turn


player++;
}
}

// Function to print the game board


void printBoard() {
system("cls"); // Clear the screen
printf("\n\n");
printf("=== TIC TAC TOE ===\n\n");
printf(" | | \n");
printf(" %c | %c | %c \n", board[1], board[2], board[3]);
printf("_____|_____|_____\n");
printf(" | | \n");
printf(" %c | %c | %c \n", board[4], board[5], board[6]);
printf("_____|_____|_____\n");
printf(" | | \n");
printf(" %c | %c | %c \n", board[7], board[8], board[9]);
printf(" | | \n");
}

// Function to check for a win or draw


int checkWin() {

35
// Winning combinations
int winConditions[8][3] = {
{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, // Horizontal
{1, 4, 7}, {2, 5, 8}, {3, 6, 9}, // Vertical
{1, 5, 9}, {3, 5, 7} // Diagonal
};

// Check each winning condition


for (int i = 0; i < 8; i++) {
if (board[winConditions[i][0]] == board[winConditions[i][1]] &&
board[winConditions[i][1]] == board[winConditions[i][2]]) {
return 1; // A player has won
}
}

// Check for a draw


for (int i = 1; i <= 9; i++) {
if (board[i] != 'X' && board[i] != 'O') {
return -1; // Game is still ongoing
}
}

return 0; // It's a draw


}

36
3.6 Testing And Result

37
4. Bus Management System

4.1 Introduction

A Bus Management System is a software application designed to streamline the operations of


bus services. It enables efficient management of bus schedules, bookings, and passenger
information, ensuring a seamless travel experience. The system allows users to add buses,
view details, and book seats while maintaining real-time records of available and booked
seats. By automating manual processes, it reduces errors, saves time, and improves overall
service quality. This system is ideal for bus operators aiming to enhance operational
efficiency and customer satisfaction. Its user-friendly interface and centralized data storage
make it a reliable tool for modern transportation management.

4.2 Literature Work

Before I started the project I used some example shown in our text book “TEXTBOOK OF
COMPUTER SCIENCE” by Dr. Rupendra Man Rajkumar and his example for the given
work in “SCHOOL MANAGEMENT SYSTEM” especially on his work in File Handling
with Structure Program for better understanding of this project.

4.3 System Design

38
4.4 Implementation
1. MainMenu:

This subgraph represents the main menu of the Bus Reservation System.It displays the
available options (Add Bus, View Buses, Book a Seat, Exit) and prompts the user to make a
choice.Based on the user's choice, it navigates to the corresponding subgraphs (AddBus,
ViewBuses, BookSeat, Exit).
2. AddBus:

This subgraph handles the process of adding a new bus to the system.It prompts the user to
enter the bus ID, driver name, and total seats.
It initializes the booked seats to 0.It opens the 'buses.txt' file in append mode and writes the
bus details to the file.Finally, it displays a success message.

3. ViewBuses:

This subgraph is responsible for displaying the list of buses.It opens the 'buses.txt' file in read
mode and checks if the file exists.If the file exists, it displays the table header and reads the
bus details from the file, displaying them to the user.If the file does not exist, it displays a
message indicating that no buses are found.

39
4. BookSeat:

This subgraph handles the process of booking a seat on a specific bus.It prompts the user to
enter the bus ID to book a seat.It opens the 'buses.txt' file in read mode and checks if the file
exists.If the file exists, it creates a temporary file 'temp.txt' and reads the bus details from the
original file.It checks if the bus with the provided ID is found.If the bus is found, it prompts
the user to enter the number of seats to book and updates the booked seats accordingly.It then
writes the updated bus details to the temporary file, closes both files, and replaces the original
file with the temporary file.If the bus is not found or an error occurs, it displays an
appropriate error message.

5. Exit:
This subgraph represents the exit point of the Bus Reservation System.When the user chooses
to exit, the program terminates.

4.5 Source Code


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

struct Bus {
int bus_id;
char driver_name[50];
int total_seats;
int booked_seats;
};

// Function prototypes
int addBus();
int viewBuses();

40
int bookSeat();

FILE *file;

int main() {
int choice;
while (1) {
printf("\n=== Bus Reservation System ===\n");
printf("1. Add Bus\n");
printf("2. View Buses\n");
printf("3. Book a Seat\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addBus();
break;
case 2:
viewBuses();
break;
case 3:
bookSeat();
break;
case 4:
printf("Exiting the program.\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}

int addBus() {
struct Bus bus;
printf("Enter Bus ID: ");
scanf("%d", &bus.bus_id);
printf("Enter Driver's Name: ");
scanf("%s", bus.driver_name);
printf("Enter Total Seats: ");
scanf("%d", &bus.total_seats);
bus.booked_seats = 0; // Initially, no seats are booked

41
file = fopen("buses.txt", "a");
if (file == NULL) {
printf("Error opening file!\n");
return 1;
}
fprintf(file, "%d %s %d %d\n", bus.bus_id, bus.driver_name, bus.total_seats,
bus.booked_seats);
fclose(file);
printf("Bus added successfully!\n");
}

int viewBuses() {
struct Bus bus;
file = fopen("buses.txt", "r");
if (file == NULL) {
printf("No buses found!\n");
return 1;
}
printf("\nList of Buses\n");
printf("ID\tDriver\tTotal Seats\tBooked Seats\n");
printf("----------------------------------------\n");
while (fscanf(file, "%d %s %d %d", &bus.bus_id, bus.driver_name, &bus.total_seats,
&bus.booked_seats) != EOF) {
printf("%d\t%s\t%d\t%d\n", bus.bus_id, bus.driver_name, bus.total_seats,
bus.booked_seats);
}
fclose(file);
}

int bookSeat() {
int bus_id, seats_to_book, found = 0;
struct Bus bus;
FILE *tempFile;

printf("Enter Bus ID to book a seat: ");


scanf("%d", &bus_id);

file = fopen("buses.txt", "r");


if (file == NULL) {
printf("No buses found!\n");
return;
}

tempFile = fopen("temp.txt", "w");

42
if (tempFile == NULL) {
printf("Error opening temporary file!\n");
fclose(file);
return 1;
}

while (fscanf(file, "%d %s %d %d", &bus.bus_id, bus.driver_name, &bus.total_seats,


&bus.booked_seats) != EOF) {
if (bus.bus_id == bus_id) {
found = 1;
printf("Enter number of seats to book: ");
scanf("%d", &seats_to_book);
if (bus.booked_seats + seats_to_book <= bus.total_seats) {
bus.booked_seats += seats_to_book;
printf("%d seat(s) booked successfully!\n", seats_to_book);
} else {
printf("Not enough available seats!\n");
}
}
fprintf(tempFile, "%d %s %d %d\n", bus.bus_id, bus.driver_name, bus.total_seats,
bus.booked_seats);
}

fclose(file);
fclose(tempFile);

if (found) {
remove("buses.txt");
rename("temp.txt", "buses.txt");
} else {
printf("Bus with ID %d not found!\n", bus_id);
remove("temp.txt");
}

4.6 Testing And Results

43
5. Telecom Billing Systems

5.1 Introduction
Telecom billing system improves the data collection technique and helps the admins control
the billing system well. It has the following advantages:
 Telecom billing systems help ensure customer satisfaction.
 They help reduce manual errors and aint billing disputes.

44
 They help accelerate payment collections.
 They help improve the customer experience.

The telecom billing system so given in the project can do the following tasks:
 Add New Record: Add new customer record.
 View List of Records: View all the records at a glance.
 Modify Record: Modification of an already existing record.
 View Payment: View the bill for a given customer.
 Delete Record: The deletion of a record from the memory.

5.2 Literature review


This project requires you to have a basic understanding of the C programming language
concepts such as arrays, strings, structures, etc. the consideration of preparation of bill is
that for every 1 minute 0.1rs is charged.
The following libraries are used
1. <stdio.h>: For Input and Output
2. <string.h>: For String Manipulation

45
5.3 System design

5.4 Implementation
int addRecord()
{
if (customerCount < 100) {
printf("\nEnter name: ");
scanf(" %[^\n]s", customers[customerCount].name);
printf("Enter phone number: ");
scanf("%s", customers[customerCount].phoneNumber);
printf("Enter usage (in minutes): ");
scanf("%f", &customers[customerCount].usage);
customers[customerCount].totalBill
= customers[customerCount].usage * 0.1;
customerCount++;

46
printf("\nRecord added successfully!\n");
}
else {
printf("\nMaximum number of records reached!\n");
}
return 0;
}
addRecord() is a function to add new customer record. It checks if the current number of
customers given by customerCount is less than 100 ensuring there’s space for a new
record. The function prompts the user to enter the customer’s name, phone number,
usage in minutes. It calculates the total bill for the customer by multiplying their usage
in minutes by 0.1. After adding the record, customerCount is incremented by 1.If
maximum records is reached then it notifies the user.

viewRecords() function

int viewRecords()
{
printf("\nName\tPhone Number\tUsage(min)\tTotal "
"Bill($)\n");
for (int i = 0; i < customerCount; i++) {
printf("%s\t%s\t%.2f\t\t%.2f\n", customers[i].name,
customers[i].phoneNumber, customers[i].usage,
customers[i].totalBill);
}
}
The function named viewRecords() is responsible for displaying the list of customer
records. It uses a loop to iterate through each customer record .Within the loop, it prints the
name, phone number, usage in minutes, and total bill for each customer.
int searchRecord(char phoneNumber[]) {
printf("\nName\tPhone Number\tUsage(min)\tTotal Bill($)\n");
for (int i = 0; i < customerCount; i++) {
if (strcmp(customers[i].phoneNumber, phoneNumber) == 0) {
printf("%s\t%s\t%.2f\t\t%.2f\n", customers[i].name, customers[i].phoneNumber,
customers[i].usage, customers[i].totalBill);
return;
}
}
printf("\nRecord not found!\n");
}
This function searchRecord responsible for searching for a customer record based on their
phone number. It takes a char array phoneNumber as a parameter which is used to identify
the customer. It uses a loop to iterate through each customer record. Within the loop it
checks if the phone number of the current customer matches the provided phoneNumber. If
a matching phone number is found it prints the information of the customer including name,
phone number, usage in minutes, total bill. It displays output to the user either displaying
the customer record or informing them if the record was not found.

47
5.5 Source code
#include <stdio.h>
#include <string.h>

// Structure to hold customer information


struct Customer {
char name[50];
char phoneNumber[15];
float usage;
float totalBill;
};

struct Customer
customers[100]; // Array to store customer data
int customerCount = 0; // Variable to keep track of the
// number of customers

int main()
{
int choice;
char phoneNumber[15];

while (1) {
displayMenu();
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
addRecord();
break;
case 2:
viewRecords();
break;
case 3:
printf(
"\nEnter phone number to modify record: ");
scanf("%s", phoneNumber);
modifyRecord(phoneNumber);
break;
case 4:
printf(
"\nEnter phone number to view payment: ");

48
scanf("%s", phoneNumber);
viewPayment(phoneNumber);
break;
case 5:
printf(
"\nEnter phone number to delete record: ");
scanf("%s", phoneNumber);
deleteRecord(phoneNumber);
break;
case 6:
return 0;
default:
printf("\nInvalid choice! Please try again.\n");
}
}

return 0;
}

// Function to add a new customer record


int addRecord()
{
if (customerCount < 100) {
printf("\nEnter name: ");
scanf(" %[^\n]s", customers[customerCount].name);
printf("Enter phone number: ");
scanf("%s", customers[customerCount].phoneNumber);
printf("Enter usage (in minutes): ");
scanf("%f", &customers[customerCount].usage);
customers[customerCount].totalBill
= customers[customerCount].usage * 0.1;
customerCount++;
printf("\nRecord added successfully!\n");
}
else {
printf("\nMaximum number of records reached!\n");
}
}

// Function to view the list of customer records


int viewRecords()
{
printf("\nName\tPhone Number\tUsage(min)\tTotal "
"Bill($)\n");

49
for (int i = 0; i < customerCount; i++) {
printf("%s\t%s\t%.2f\t\t%.2f\n", customers[i].name,
customers[i].phoneNumber, customers[i].usage,
customers[i].totalBill);
}
}

// Function to modify a customer record


int modifyRecord(char phoneNumber[])
{
for (int i = 0; i < customerCount; i++) {
if (strcmp(customers[i].phoneNumber, phoneNumber)
== 0) {
printf(
"\nEnter new usage (in minutes) for %s: ",
customers[i].name);
scanf("%f", &customers[i].usage);
customers[i].totalBill
= customers[i].usage * 0.1;
printf("\nRecord modified successfully!\n");
return 1;
}
}
printf("\nRecord not found!\n");
}

// Function to view payment for a customer


int viewPayment(char phoneNumber[])
{
for (int i = 0; i < customerCount; i++) {
if (strcmp(customers[i].phoneNumber, phoneNumber)
== 0) {
printf(
"%s\t%s\t%.2f\t\t%.2f\n", customers[i].name,
customers[i].phoneNumber,
customers[i].usage, customers[i].totalBill);
return 1;
}
}
printf("\nRecord not found!\n");
}

// Function to delete a customer record


int deleteRecord(char phoneNumber[])

50
{
for (int i = 0; i < customerCount; i++) {
if (strcmp(customers[i].phoneNumber, phoneNumber)
== 0) {
for (int j = i; j < customerCount - 1; j++) {
customers[j] = customers[j + 1];
}
customerCount--;
printf("\nRecord deleted successfully!\n");
return 1;
}
}
printf("\nRecord not found!\n");
}

// Function to display menu options


int displayMenu()
{
printf("\n1. Add New Record\n");
printf("2. View List of Records\n");
printf("3. Modify Record\n");
printf("4. View Payment\n");
printf("5. Delete Record\n");
printf("6. Exit\n");
}

51
5.6 Testing and results

52
53
6. Conclusion

6.1 School Management Sytem

The School Management System developed as part of this project demonstrates the effective
use of file handling and structured programming in C. The system enables efficient
management of both student and teacher data, including functionalities for adding, viewing,
editing, and deleting records. By automating these tasks, it significantly reduces manual
effort and ensures better organization of information, making it a practical solution for school
administration.

For future improvements, the system can be enhanced by adding advanced features such as a
sorting function. This would allow users to sort records based on parameters like name, ID,
class, or experience, further improving data accessibility and usability. Such enhancements
would make the system more dynamic and user-friendly, catering to the growing needs of
educational institutions

6.2 Library Management System

The Library Management System developed in this project showcases an efficient approach
to managing books and borrower records using file handling and structured programming in
C. It simplifies core library functions such as adding books, lending books, searching for
records, returning books, and viewing borrowed items. By automating these operations, the
system reduces manual work and enhances the overall efficiency of library management.

For future improvements, the system can be expanded by incorporating a fine calculation
function. This feature would allow the system to track overdue books and calculate fines
based on the delay, ensuring accountability and timely returns. Such an addition would make
the system more comprehensive and beneficial for both librarians and users.

6.3 Tic Tac Toe

The Tic Tac Toe game implemented in this project highlights the fundamentals of structured
programming and interactive user input. This classic two-player game is simple yet engaging,
allowing players to compete on a 3x3 grid with real-time updates and a winning condition
check. The game successfully demonstrates the use of arrays, control structures, and modular
programming to create a fun and functional application.

For future enhancements, the game can be upgraded by adding a "1-Player Mode" that
enables a player to compete against the computer. This would involve implementing an AI
function to determine the computer's moves, ranging from simple random placement to more
strategic algorithms.

54
6.4 Bus Management Sytem

The Bus Management System developed in this project efficiently manages bus schedules,
bookings, and passenger information. It allows users to add buses, view details, and book
seats while maintaining accurate records of available and booked seats. By automating these
processes, the system reduces manual errors and ensures a seamless experience for both
operators and passengers. Its user-friendly interface and straightforward functionality make it
a valuable tool for modernizing transportation management.

For future enhancements, the system can incorporate advanced features such as online
payment integration, route optimization, and dynamic seat allocation based on user
preferences. Adding a feature to generate booking reports and analytics would also help
operators make informed decisions and improve operational efficiency. These improvements
would make the system more comprehensive, adaptable, and beneficial for users and
administrators alike.

6.5 Telecom Billing System

The Telecom Billing System developed in this project provides an efficient way to manage
customer billing processes, including generating bills, tracking usage, and maintaining
payment records. The system ensures accuracy and minimizes manual errors, making the
billing process streamlined and reliable. Its simplicity and effectiveness make it a practical
tool for telecom service providers to handle customer accounts and transactions efficiently.

For future upgrades, the system can be enhanced by integrating an online payment feature.
This would allow customers to pay their bills directly through the system using various
payment methods, such as credit/debit cards, digital wallets, or bank transfers. Such an
addition would provide convenience for customers, reduce delays in payment processing, and
further enhance the system's utility and efficiency.

55
7. Reference
 Geekforgeeks
 TEXTBOOK OF COMPUTER SCIENCE by Dr. Rupendra Man Rajkumar
 W3C School
 StackOverflow

56

You might also like