Computer Science Project File Class 12 Cbse
Computer Science Project File Class 12 Cbse
A Project Report on
School Hostel
Management System
Project Prepared by:
Anwesha Prakash
CLASS – XII A
UNDER THE guidance of: Ms.
Anu Joseph
PGT (Computer Science)
OPG World School
2|Page OPG WORLD SCHOOL CS PROJECT FILE
Index
S.no Contents Page no
1. Certificate 3
2. Acknowledgement 4
3. Requirement 5
4. Introduction 6
5. About 7
6. Functions & Files 8
7. Program Code 9- 33
8. SQL Queries 34-35
9. Output 36-41
10. Bibliography 42
3|Page OPG WORLD SCHOOL CS PROJECT FILE
CERTIFICATE
Date: -
Registration No.:-
Signature Signature
(Internal Examiner) (External Examiner)
4|Page OPG WORLD SCHOOL CS PROJECT FILE
ACKNOWLEDGEMENT
REQUIREMENTS
Hardware Required
RAM – 4GB or above
Processor – Core™ i5 or above
Hard Disk – 5 GB
SOFTWARE REQUIRED
Operating System – Windows 7 or 10
Python – Version (3.7.9)
SQL – Version (8.0.21)
6|Page OPG WORLD SCHOOL CS PROJECT FILE
INTRODUCTION
Python is an open source, interpreted, high-level and
general-purpose programming language. It was created by
Guido van Rossum and first released in 1991 at the National
Research Institute for Mathematics, Netherlands. It is
presently owned by Python Software Foundation (PSF).
TEAM MEMBERS:
Anwesha Prakash and Tanushree Mohanty
8|Page OPG WORLD SCHOOL CS PROJECT FILE
Functions performed
by the program
ADDING STUDENT
REMOVING STUDENT
ADDING STAFF
REMOVING STAFF
HOSTEL ATTENDANCE
STAFF ATTENDANCE
SUBMITING FEES
PAY SALARY
DISPLAYING ROOMMATES
STAFF LIST
ADMISSION FORM
SHOWING FEES
PROGRAM CODE
MySQL-Connector code
"""Connection class using the C Extension
"""
import os
import socket
import sysconfig
HAVE_CMYSQL = False
# pylint: disable=F0401,C0413
try:
import _mysql_connector
from .cursor_cext import (
CMySQLCursor, CMySQLCursorRaw,
CMySQLCursorBuffered, CMySQLCursorBufferedRaw, CMySQLCursorPrepared,
CMySQLCursorDict, CMySQLCursorBufferedDict, CMySQLCursorNamedTuple,
CMySQLCursorBufferedNamedTuple)
from _mysql_connector import MySQLInterfaceError # pylint: disable=F0401
except ImportError as exc:
raise ImportError(
"MySQL Connector/Python C Extension not available ({0})".format(
str(exc)
))
else:
HAVE_CMYSQL = True
# pylint: enable=F0401,C0413
class CMySQLConnection(MySQLConnectionAbstract):
10 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
if kwargs:
self.connect(**kwargs)
def _add_default_conn_attrs(self):
"""Add default connection attributes"""
license_chunks = version.LICENSE.split(" ")
if license_chunks[0] == "GPLv2":
client_license = "GPL-2.0"
else:
client_license = "Commercial"
self._conn_attrs.update({
"_connector_name": "mysql-connector-python",
"_connector_license": client_license,
"_connector_version": ".".join(
[str(x) for x in version.VERSION[0:3]]),
"_source_host": socket.gethostname()
})
def _do_handshake(self):
"""Gather information of the MySQL server before authentication"""
self._handshake = {
'protocol': self._cmysql.get_proto_info(),
'server_version_original': self._cmysql.get_server_info(),
'server_threadid': self._cmysql.thread_id(),
'charset': None,
'server_status': None,
'auth_plugin': None,
11 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
'auth_data': None,
'capabilities': self._cmysql.st_server_capabilities(),
}
self._server_version = self._check_server_version(
self._handshake['server_version_original']
)
@property
def _server_status(self):
"""Returns the server status attribute of MYSQL structure"""
return self._cmysql.st_server_status()
Set allow_local_infile_in_path.
"""
if self._cmysql:
self._cmysql.set_load_data_local_infile_option(path)
@property
def autocommit(self):
"""Get whether autocommit is on or off"""
value = self.info_query("SELECT @@session.autocommit")[0]
return True if value == 1 else False
@autocommit.setter
def autocommit(self, value): # pylint: disable=W0221
"""Toggle autocommit"""
try:
12 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
self._cmysql.autocommit(value)
self._autocommit = value
except MySQLInterfaceError as exc:
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlstate=exc.sqlstate)
@property
def database(self):
"""Get the current database"""
return self.info_query("SELECT DATABASE()")[0]
@database.setter
def database(self, value): # pylint: disable=W0221
"""Set the current database"""
self._cmysql.select_db(value)
@property
def in_transaction(self):
"""MySQL session has started a transaction"""
return self._server_status & ServerFlag.STATUS_IN_TRANS
def _open_connection(self):
charset_name = CharacterSet.get_info(self._charset_id)[0]
self._cmysql = _mysql_connector.MySQL( # pylint: disable=E1101,I1101
buffered=self._buffered,
raw=self._raw,
charset_name=charset_name,
connection_timeout=(self._connection_timeout or 0),
use_unicode=self._use_unicode,
auth_plugin=self._auth_plugin,
plugin_dir=self._plugin_dir)
if not self.isset_client_flag(ClientFlag.CONNECT_ARGS):
self._conn_attrs = {}
cnx_kwargs = {
'host': self._host,
'user': self._user,
'password': self._password,
'password1': self._password1,
'password2': self._password2,
'password3': self._password3,
'database': self._database,
'port': self._port,
'client_flags': self._client_flags,
'unix_socket': self._unix_socket,
13 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
'compress': self.isset_client_flag(ClientFlag.COMPRESS),
'ssl_disabled': True,
"conn_attrs": self._conn_attrs,
"local_infile": self._allow_local_infile,
"load_data_local_dir": self._allow_local_infile_in_path,
"oci_config_file": self._oci_config_file,
}
tls_versions = self._ssl.get('tls_versions')
if tls_versions is not None:
tls_versions.sort(reverse=True)
tls_versions = ",".join(tls_versions)
if self._ssl.get('tls_ciphersuites') is not None:
ssl_ciphersuites = self._ssl.get('tls_ciphersuites')[0]
tls_ciphersuites = self._ssl.get('tls_ciphersuites')[1]
else:
ssl_ciphersuites = None
tls_ciphersuites = None
if tls_versions is not None and "TLSv1.3" in tls_versions and \
not tls_ciphersuites:
tls_ciphersuites = "TLS_AES_256_GCM_SHA384"
if not self._ssl_disabled:
cnx_kwargs.update({
'ssl_ca': self._ssl.get('ca'),
'ssl_cert': self._ssl.get('cert'),
'ssl_key': self._ssl.get('key'),
'ssl_cipher_suites': ssl_ciphersuites,
'tls_versions': tls_versions,
'tls_cipher_suites': tls_ciphersuites,
'ssl_verify_cert': self._ssl.get('verify_cert') or False,
'ssl_verify_identity':
self._ssl.get('verify_identity') or False,
'ssl_disabled': self._ssl_disabled
})
try:
self._cmysql.connect(**cnx_kwargs)
self._cmysql.converter_str_fallback = self._converter_str_fallback
if self.converter:
self.converter.str_fallback = self._converter_str_fallback
except MySQLInterfaceError as exc:
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlstate=exc.sqlstate)
14 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
self._do_handshake()
def close(self):
"""Disconnect from the MySQL server"""
if self._cmysql:
try:
self.free_result()
self._cmysql.close()
except MySQLInterfaceError as exc:
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlstate=exc.sqlstate)
disconnect = close
def is_closed(self):
"""Return True if the connection to MySQL Server is closed."""
return not self._cmysql.connected()
def is_connected(self):
"""Reports whether the connection to MySQL Server is available"""
if self._cmysql:
return self._cmysql.ping()
return False
When reconnect is set to True, one or more attempts are made to try
to reconnect to the MySQL server using the reconnect()-method.
try:
connected = self._cmysql.ping()
except AttributeError:
pass # Raise or reconnect later
15 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
else:
if connected:
return
if reconnect:
self.reconnect(attempts=attempts, delay=delay)
else:
raise errors.InterfaceError(errmsg)
return first_row
@property
def connection_id(self):
"""MySQL connection ID"""
try:
return self._cmysql.thread_id()
except MySQLInterfaceError:
pass # Just return None
return None
if raw is None:
raw = self._raw
rows = []
if count is not None and count <= 0:
raise AttributeError("count should be 1 or higher, or None")
counter = 0
try:
row = prep_stmt.fetch_row() if prep_stmt \
else self._cmysql.fetch_row()
while row:
if not self._raw and self.converter:
row = list(row)
for i, _ in enumerate(row):
if not raw:
row[i] = self.converter.to_python(self._columns[i],
row[i])
row = tuple(row)
rows.append(row)
counter += 1
if count and counter == count:
break
row = prep_stmt.fetch_row() if prep_stmt \
else self._cmysql.fetch_row()
if not row:
_eof = self.fetch_eof_columns(prep_stmt)['eof']
if prep_stmt:
prep_stmt.free_result()
self._unread_result = False
else:
self.free_result()
else:
_eof = None
except MySQLInterfaceError as exc:
if prep_stmt:
prep_stmt.free_result()
raise errors.InterfaceError(str(exc))
else:
self.free_result()
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlstate=exc.sqlstate)
17 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
def next_result(self):
"""Reads the next result"""
if self._cmysql:
self._cmysql.consume_result()
return self._cmysql.next_result()
return None
def free_result(self):
"""Frees the result"""
if self._cmysql:
self._cmysql.free_result()
def commit(self):
"""Commit current transaction"""
if self._cmysql:
self._cmysql.commit()
def rollback(self):
"""Rollback current transaction"""
if self._cmysql:
self._cmysql.consume_result()
self._cmysql.rollback()
sqlstate=exc.sqlstate)
return {
'eof': {
'status_flag': self._server_status,
'warning_count': self._cmysql.st_warning_count(),
},
'columns': self._columns,
}
def fetch_eof_status(self):
"""Fetch EOF and status information"""
if self._cmysql:
return {
'warning_count': self._cmysql.st_warning_count(),
'field_count': self._cmysql.st_field_count(),
'insert_id': self._cmysql.insert_id(),
'affected_rows': self._cmysql.affected_rows(),
'server_status': self._server_status,
}
19 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
return None
try:
stmt = self._cmysql.stmt_prepare(statement)
stmt.converter_str_fallback = self._converter_str_fallback
return stmt
except MySQLInterfaceError as err:
raise errors.InterfaceError(str(err))
# pylint: disable=W0221
def cmd_stmt_execute(self, prep_stmt, *args):
"""Executes the prepared statement"""
try:
prep_stmt.stmt_execute(*args)
except MySQLInterfaceError as err:
raise errors.InterfaceError(str(err))
self._columns = []
if not prep_stmt.have_result_set:
# No result
self._unread_result = False
return self.fetch_eof_status()
self._unread_result = True
return self.fetch_eof_columns(prep_stmt)
self._columns = []
if not self._cmysql.have_result_set:
# No result
return self.fetch_eof_status()
return self.fetch_eof_columns()
_execute_query = cmd_query
cursor_type = 0
if buffered is True:
cursor_type |= 1
if raw is True:
cursor_type |= 2
if dictionary is True:
cursor_type |= 4
if named_tuple is True:
cursor_type |= 8
if prepared is True:
cursor_type |= 16
types = {
0: CMySQLCursor, # 0
22 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
1: CMySQLCursorBuffered,
2: CMySQLCursorRaw,
3: CMySQLCursorBufferedRaw,
4: CMySQLCursorDict,
5: CMySQLCursorBufferedDict,
8: CMySQLCursorNamedTuple,
9: CMySQLCursorBufferedNamedTuple,
16: CMySQLCursorPrepared
}
try:
return (types[cursor_type])(self)
except KeyError:
args = ('buffered', 'raw', 'dictionary', 'named_tuple', 'prepared')
raise ValueError('Cursor not available with given criteria: ' +
', '.join([args[i] for i in range(5)
if cursor_type & (1 << i) != 0]))
@property
def num_rows(self):
"""Returns number of rows of current result set"""
if not self._cmysql.have_result_set:
raise errors.InterfaceError("No result set")
return self._cmysql.num_rows()
@property
def warning_count(self):
"""Returns number of warnings"""
if not self._cmysql:
return 0
return self._cmysql.warning_count()
@property
def result_set_available(self):
"""Check if a result set is available"""
if not self._cmysql:
return False
return self._cmysql.have_result_set
@property
def unread_result(self):
"""Check if there are unread results or rows"""
23 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
return self.result_set_available
@property
def more_results(self):
"""Check if there are more results"""
return self._cmysql.more_results()
Returns dict.
"""
if isinstance(params, (list, tuple)):
if self.converter:
result = [
self.converter.quote(
self.converter.escape(
self.converter.to_mysql(value)
)
) for value in params
]
else:
result = self._cmysql.convert_to_mysql(*params)
elif isinstance(params, dict):
result = {}
if self.converter:
for key, value in params.items():
result[key] = self.converter.quote(
self.converter.escape(
self.converter.to_mysql(value)
)
)
else:
for key, value in params.items():
result[key] = self._cmysql.convert_to_mysql(value)[0]
else:
raise ValueError("Could not process parameters")
return result
def consume_results(self):
24 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
self._charset_id = charset
self._post_connection()
def cmd_reset_connection(self):
"""Resets the session state without re-authenticating
self._post_connection()
25 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
return self.fetch_eof_status()
def cmd_quit(self):
"""Close the current connection with the server"""
self.close()
if shutdown_type:
if not ShutdownType.get_info(shutdown_type):
raise errors.InterfaceError("Invalid shutdown type")
level = shutdown_type
else:
level = ShutdownType.SHUTDOWN_DEFAULT
try:
self._cmysql.shutdown(level)
except MySQLInterfaceError as exc:
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlstate=exc.sqlstate)
self.close()
def cmd_statistics(self):
"""Return statistics from the MySQL server"""
self.handle_unread_result()
try:
stat = self._cmysql.stat()
return MySQLProtocol().parse_statistics(stat, with_header=False)
except (MySQLInterfaceError, errors.InterfaceError) as exc:
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlstate=exc.sqlstate)
26 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
This method resets the session state, if the MySQL server is 5.7.3
or later active session will be reset without re-authenticating.
For other server versions session will be reset by re-authenticating.
try:
self.cmd_reset_connection()
except (errors.NotSupportedError, NotImplementedError):
if self._compress:
raise errors.NotSupportedError(
"Reset session is not supported with compression for "
"MySQL server version 5.7.2 or earlier.")
elif self._server_version < (5, 7, 3):
raise errors.NotSupportedError(
"Reset session is not supported with MySQL server "
27 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
if user_variables or session_variables:
cur = self.cursor()
if user_variables:
for key, value in user_variables.items():
cur.execute("SET @`{0}` = %s".format(key), (value,))
if session_variables:
for key, value in session_variables.items():
cur.execute("SET SESSION `{0}` = %s".format(key), (value,))
cur.close()
Main code
import mysql.connector as a
if con.is_connected():
print('connected successfully')
else:
print('not connected')
def addst():
n = input("Student Name: ")
c = input("Class: ")
r = input("Room number: ")
a = input("Address: ")
p = input("Phone no.: ")
data = (n, c, r, a, p)
sql = 'insert into student values(%s,%s,%s,%s,%s)'
x = con.cursor()
x.execute(sql, data)
con.commit()
print("Data entered successfully")
28 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
print("------------------------------------------------------------------------
---------------")
main()
def removest():
n = input("Name of the student: ")
c = input("Class: ")
data = (c, n)
sql = 'delete from student where Name=%s and Class=%s'
x = con.cursor()
x.execute(sql, data)
con.commit()
print("Data updated")
print("------------------------------------------------------------------------
---------------")
main()
def addstaff():
n = input("Name: ")
p = input("Post: ")
s = input("Salary: ")
a = input("Address: ")
ph = input("Phone: ")
i = input("ID: ")
data = (n, p, s, a, ph, i)
sql = 'insert into staff values(%s,%s,%s,%s,%s,%s)'
x = con.cursor()
x.execute(sql, data)
con.commit()
print("Data entered successfully")
print("------------------------------------------------------------------------
----------------")
main()
def removestaff():
n = input("Staff name:")
i = input("ID: ")
data = (n, i)
sql = 'delete from staff where Name=%s and id=%s'
x = con.cursor()
x.execute(sql, data)
29 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
con.commit()
print("Data updated")
print("------------------------------------------------------------------------
-----------------")
main()
def abstudent():
d = input("Date: ")
r = input("Room no.: ")
ab = input("names of the absent students: ")
data = (d, r, ab)
sql = 'insert into studattendance values(%s,%s,%s)'
x = con.cursor()
x.execute(sql, data)
con.commit()
print("Data updated")
print("------------------------------------------------------------------------
-----------------")
main()
def abstaff():
d = input("Date: ")
ab = input("Names of the absent staff: ")
data = (d, ab)
sql = 'insert into staffattendance values(%s,%s)'
x = con.cursor()
x.execute(sql, data)
con.commit()
print("Data updated")
print("------------------------------------------------------------------------
-----------------")
main()
def submitf():
n = input("Student name: ")
c = input("Class: ")
r = input("Room no.: ")
m = input("Month and year: ")
f = input("Fees: ")
dpt = input("Department: ")
data = (n, c, r, m, dpt, f)
30 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
def pays():
n = input("Staff name: ")
m = input("Month: ")
p = input("Yes/No: ")
data = (n, m, p)
sql = 'insert into salary values(%s,%s,%s)'
x = con.cursor()
x.execute(sql, data)
con.commit()
print("Data entered successfully")
print("------------------------------------------------------------------------
-----------------")
main()
def dstudent():
sql = 'select * from student'
x = con.cursor()
x.execute(sql)
d = x.fetchall()
for i in d:
print("Name: ", i[0])
print("Class: ", i[1])
print("Room no.: ", i[2])
print("Address: ", i[3])
print("Phone: ", i[4])
print("--------------------------------------------")
print("------------------------------------------------------------------------
-----------------")
main()
def dstaff():
sql = 'select * from staff'
31 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
x = con.cursor()
x.execute(sql)
d = x.fetchall()
for i in d:
print("Name: ", i[0])
print("Post: ", i[1])
print("Salary: ", i[2])
print("Address: ", i[3])
print("Phone: ", i[4])
print("ID: ", i[5])
print("--------------------------------------------")
print("------------------------------------------------------------------------
-----------------")
main()
def adform():
roll = input("ENTER YOUR ROLL NUMBER")
name = input("ENTER YOUR NAME")
add = input("ENTER YOUR ADDRESS")
room_no = input("ENTER YOUR ROOM NUMBER")
dept = input("ENTER YOUR DEPARTMENT")
fees = input("ENTER YOUR FEES")
bal = input("ENTER YOUR BALANCE")
abc = (
"insert into adform values (" + roll + ",'" + name + "','" + add + "'," + room_no + ",'" +
dept + "'," + fees + "," + bal + ")")
print(abc)
x = con.cursor()
x.execute(abc)
con.commit()
print("Data entered successfully")
print("------------------------------------------------------------------------
-----------------")
main()
def fc():
print("AVAILABLE DEPARTMENTS AS FOLLOWS")
print("1.COMPUTER")
print("2.BIO")
print("3.TECH")
print("4.PHYSICS")
32 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
print("5.ECO")
print("6.ENG")
department = input("ENTER YOUR DEPARTMENT")
mysql = "select*from fees where department='{}'".format(department)
x = con.cursor()
x.execute(mysql)
data = x.fetchall()
print("your fees is:", data[0][5])
print("------------------------------------------------------------------------
-----------------")
main()
def main():
print(""" HOSTEL MANAGEMENT SYSTEM
1. ADD STUDENT 2. REMOVE STUDENT
3. ADD STAFF 4. REMOVE STAFF
5. HOSTEL ATTENDANCE 6. STAFF ATTENDANCE
7. SUBMIT FEES 8. PAY SALARY
9. DISPLAY ROOMMATES 10. STAFF LIST
11.ADMISSION FORM 12. SHOW FEES
""")
choice = int(input("Enter task no.: "))
print("---------------------------")
if choice == 1:
addst()
elif choice == 2:
removest()
elif choice == 3:
addstaff()
elif choice == 4:
removestaff()
elif choice == 5:
abstudent()
elif choice == 6:
abstaff()
elif choice == 7:
submitf()
elif choice == 8:
pays()
elif choice == 9:
dstudent()
elif choice == 10:
dstaff()
33 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
def pswd():
p = input("Password: ")
if p == "ihateorganic":
main()
else:
print("incorrect password!")
pswd()
pswd()
34 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
OUTPUT
1. ADD
STUDENT
2. REMOVE
STUDENT
37 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
3. ADD STAFF
4. REMOVE
STAFF
38 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
5. HOSTEL
ATTENDANCE
6. STAFF ATTENDANCE
7. SUBMIT
FEES
39 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
8. PAY
SALARY
9. DISPLAY ROOMMATES
40 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
10. STAFF
LIST
11.ADMISSION FORM
41 | P a g e OPG WORLD SCHOOL CS PROJECT FILE
BIBLIOGRAPHY
Sumita Arora – Computer Science With
Python – Class XII
W3schools.com
tutorialspoint.com
python.org
mysql.com