Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Computer Science

Project

2023-24
Done by:
Anurag Subramaniyan
Chris itty biju
Vedanth saravanan
of
CLASS XII-A3
INDEX:

Sno Topic Remarks


1. Synopsis

2. Software used

3. Modules used

4. Algorithm

5. Source code

6. Output

7. Bibliography
Synopsis:
Our Python program is a console-based Gym Management System that interacts with a
MySQL database for storing information about trainers, members, and other related data.
Here's a concise overview of what the program does:
• The program connects to a MySQL database with a predefined host, username, and
password.
• It checks if the necessary database tables ('fees', 'login', 'member', 'trainer', 'serial
no.') exist. If not, it creates these tables.
• The program then presents a main menu with two options: LOGIN and EXIT.
• If the user chooses LOGIN, they are prompted to enter a password. If the entered
password matches the predefined admin password, a sub-menu is displayed with
options for various management tasks.
• Management tasks include:
• Adding trainers with unique IDs and attributes like name, age, gender, and salary.
• Adding members with unique IDs and attributes like name, gender, category (silver,
gold, platinum), and amount.
• Removing trainers and members based on provided IDs.
• Modifying information of trainers and members including name, age, gender, salary,
and membership category.
• Changing the admin password.
• Returning to the main menu.
Overall, the program allows gym administrators to perform essential management
functions like adding and removing trainers/members, modifying details, and changing
passwords using a command-line interface. The program utilizes a MySQL database for
data storage and retrieval.

Software used:

Our Python program utilizes several software components to achieve its functionality:
• Python:
• Python is the programming language in which the entire application is written. It is
used to define the logic, control flow, and interactions with various components.
• MySQL Database:
• MySQL is an open-source relational database management system (RDBMS) used to
store structured data. In this program, MySQL is used to store information about
trainers, members, login credentials, and other related data.
• mysql-connector-python:
• This is a Python library that provides an interface for connecting to a MySQL
database and performing various database operations using Python code. In the
program, the mysql.connector module is used to establish connections, create
tables, execute SQL queries, and commit changes.
• Text Editor/IDE:
• A text editor or integrated development environment (IDE) is used to write, edit,
and save the Python code. Common choices include Visual Studio Code, PyCharm,
Sublime Text, or any other preferred code editor.
• Command Line Interface (CLI):
• The program primarily interacts with users through a command-line interface. The
CLI provides a way to input data, make choices, and receive textual output. The user
enters options and data as text, and the program processes these inputs accordingly.
• MySQL Server:
• A MySQL server is required to host the database where the program stores its data.
The program connects to this server to read and write data.
• Database Management Tool (Optional):
• While not directly mentioned in the code, a database management tool like
phpMyAdmin or MySQL Workbench can be used to interact with and manage the
MySQL database visually. These tools offer graphical interfaces to manage database
schemas, execute queries, and view data.
• Terminal/Command Prompt:
• The program is run from a terminal or command prompt, where the user interacts
with the program by entering choices and data. The terminal provides an
environment for executing the Python script and observing its output.
• Operating System:
• The program can run on various operating systems, such as Windows, macOS, or
Linux, as long as Python and the required libraries are installed.
In summary, the program utilizes Python as the programming language and the mysql-
connector-python library to connect to and manipulate a MySQL database. It interacts
with users through a command-line interface and relies on the MySQL server for data
storage and retrieval. The overall execution environment includes a text editor or IDE, a
terminal/command prompt, and potentially a database management tool for database
administration.

Modules used :
, here's a brief description of the modules used in the program:
• mysql.connector:
• This module provides the necessary tools for connecting to a MySQL database and
performing operations such as executing queries and managing transactions.
• print:
• The built-in print function is used to display text on the console. It's used to show
menus, messages, and information to the user.
• input:
• The built-in input function is used to capture user input from the console. It's used
to gather choices, passwords, and other information from the user.
• while loop:
• The while loop is used to repeatedly display menus and gather user input until the
user decides to exit. It ensures an interactive experience.
• if statements:
• if statements are used to conditionally execute certain parts of the program.
They're used to determine if the provided password matches the admin password
and for various menu options.
• execute:
• The execute method is part of the mysql.connector module and is used to execute
SQL queries on the database.
• commit:
• The commit method is used in combination with database operations to save
changes made to the database.
• string manipulation:
• Various string manipulation techniques are used to format and construct SQL
queries, messages, and user prompts.
• integer conversion:
• The int function is used to convert user input (which is captured as a string) into
integer values for comparisons and calculations.
• input validation and loops:
• Loops and conditional statements are used for input validation, ensuring that users
enter appropriate data.
These modules and techniques collectively enable the program to interact with users,
manage data in the MySQL database, and provide a functional and interactive experience
for gym management tasks.
Algorithm :
here's a stepwise algorithm for the Gym Management System program:
• Import the mysql.connector module for database interactions.
• Print the gym management title.
• Establish a connection to the MySQL database using a predefined host, username,
and password.
• Create necessary database tables ('fees', 'login', 'member', 'trainer', 'sno') if they
don't already exist.
• Initialize flags for table existence checks.
• Check if 'sno' table exists:
• If not, insert an initial record with ID and DID set to 0.
• Check if 'fees' table exists:
• If not, insert default membership fee values for silver, gold, and platinum plans.
• Check if 'login' table exists:
• If not, insert an initial admin login record with a default password.
• Display the main menu with options: LOGIN and EXIT.
• Take user's choice:
• If choice is 1 (LOGIN):
• Prompt user for admin password.
• Fetch the stored admin password from the 'login' table.
• If entered password matches stored password, proceed to admin sub-menu.
• Display admin sub-menu with various options.
• Based on the selected option, execute corresponding actions:
• Add Trainer:
• Gather trainer details and generate a unique ID.
• Insert trainer data into the 'trainer' table and update 'sno' table.
• Add Member:
• Gather member details and membership category.
• Generate a unique ID and calculate the membership fee.
• Insert member data into the 'member' table and update 'sno' table.
• Remove Trainer:
• Take the ID of the trainer to be removed.
• Delete the corresponding record from the 'trainer' table.
• Remove Member:
• Take the ID of the member to be removed.
• Delete the corresponding record from the 'member' table.
• Modify:
• Display options to modify trainer info, member info, or go back.
• Depending on the choice:
• Update necessary fields in the respective table.
• Change Password:
• Take the old and new passwords.
• If the old password matches the stored admin password, update the password in the
'login' table.
• Go Back:
• Return to the main menu.
• If the password does not match, show an error message and return to the main
menu.
• If choice is 2 (EXIT):
• End the program.
• If an invalid choice is entered, display an error message.
• Close the connection to the MySQL database.
This stepwise algorithm outlines the flow of the Gym Management System program,
detailing how it interacts with users, manages data in the database, and performs various
gym management tasks.
Source code:
import mysql.connector

print('''

GYM MANAGEMENT

''')

myd=mysql.connector.connect(host='localhost',user='root',passwd='kuki2510')

myc=myd.cursor()

# Creating DATABASE

myc.execute('create database if not exists dio')

myc.execute('use dio')

myc.execute('create table if not exists fees(silver int,gold int,platinum int)')

myc.execute('create table if not exists login(username varchar(100),password varchar(100)not null)')

myc.execute('create table if not exists member(id int,name varchar(100),gender char,category


varchar(100),amt int)')

myc.execute('create table if not exists sno(id int,did int)')

myc.execute('create table if not exists trainer(id int,name varchar(100),age varchar(100),gender


char,salary int)')

myd.commit()

#Creating Tables

flag=0

myc.execute('select * from sno')

for i in myc:

flag=1

if flag==0:

myc.execute('insert into sno values(0,0)')


flag=0

myc.execute('select * from fees')

for i in myc:

flag=1

if flag==0:

myc.execute('insert into fees values(700,600,500)')

myd.commit()

flag=0

myc.execute('select * from login')

for i in myc:

flag=1

if flag==0:

myc.execute("insert into login values('admin','ng')")

myd.commit()

#main section

while True:

print('''

1.LOGIN

2.EXIT

''')

ch=int(input('''

ENTER YOUR CHOICE : '''))

if ch==1:

passs=input('''

ENTER PASSWORD: ''')

myc.execute('select * from login')

for i in myc:
t_user,t_pas=i

if t_pas==passs:

print('''

1.ADD TRAINER

2.ADD MEMBER

3.REMOVE TRAINER

4.REMOVE MEMBER

5.MODIFY

6.CHANGE PASSWORD

7.GO BACK

''')

ch=int(input('''

ENTER YOUR CHOICE: '''))

#Adding Trainer

if ch==1:

name=input('''

ENTER YOUR NAME: ''')

age=input('''

ENTER YOUR AGE: ''')

gender=input('''

ENTER YOUR GENDER(M,F): ''')

salary=int(input('''

ENTER YOUR SALARY: '''))

myc.execute('select * from sno')

for i in myc:

t_id,t_did=i

t_id=t_id+1
myc.execute("insert into trainer
values('"+str(t_id)+"','"+name+"','"+age+"','"+gender+"','"+str(salary)+"')")

myc.execute("update sno set id='"+str(t_id)+"'")

myd.commit()

print(f'''

TRAINER ADDED WITH UNIQUE ID {t_id}

''')

print('''

SUCCESSFULLY ADDED..........

''')

#Adding Member

elif ch==2:

name=input('''

ENTER YOUR NAME: ''')

gender=input('''

ENTER YOUR GENDER(M/F): ''')

print('''

1.SILVER

2.GOLD

3.PLATINUM

''')

ch=int(input('''

ENTER YOUR CHOICE: '''))

myc.execute('select * from fees')

for i in myc:

t_silver,t_gold,t_platinum=i

if ch==1:

category='silver'
amt=t_silver

elif ch==2:

category='gold'

amt=t_gold

elif ch==3:

category='platinum'

amt=t_platinum

myc.execute('select * from sno')

for i in myc:

t_id,t_did=i

t_did=t_did+1

myc.execute("insert into member


values('"+str(t_did)+"','"+name+"','"+gender+"','"+category+"','"+str(amt)+"')")

myc.execute("update sno set did='"+str(t_did)+"'")

myd.commit()

print(f'''

TRAINER ADDED WITH UNIQUE ID {t_id}

''')

#Removing Trainer

elif ch==3:

idd=int(input('''

ENTER ID TO REMOVE: '''))

myc.execute('select * from trainer')

flag=0

for i in myc:

t_id=i[0]

if t_id==idd:

flag=1

if flag==1:
myc.execute("delete from trainer where id='"+str(idd)+"'")

myd.commit()

print('''

SUCCESSFULLY REMOVED!!! ''')

else:

print('''

ID NOT FOUND ''')

#Removing Member

elif ch==4:

idd=int(input('''

ENTER ID TO REMOVE: '''))

myc.execute('select * from member')

flag-0

for i in myc:

t_id=i[0]

if t_id==idd:

flag=1

if flag==1:

myc.execute("delete from member where id='"+str(idd)+"'")

myd.commit()

print('''

SUCCESSFULLY REMOVED!!! ''')

else:

print('''

ID NOT FOUND ''')

#Modify

elif ch==5:

loop1='y'

while loop1=='y':
print('''

1.PLANS

2.TRAINER INFO

3.MEMBER INFO

4.GO BACK ''')

ch=int(input('''

ENTER YOUR CHOICE: '''))

if ch==1:

print('''

1.SILVER

2.GOLD

3.PLATINUM

''')

ch2=int(input('''

ENTER YOUR CHOICE: '''))

amt=int(input('''

ENTER AMOUNT PER MONTH UPDATE: '''))

if ch2==1:

myc.execute("update fees set silver='"+str(amt)+"'")

myd.commit()

elif ch2==2:

myc.execute("update fees set gold='"+str(amt)+"'")

myd.commit()

elif ch2==3:

myc.execute("update fees set platinum='"+str(amt)+"'")

myd.commit()

elif ch==2:

idd=int(input('''

ENTER ID TO MODIFY: '''))


myc.execute('select * from trainer')

flag=0

for i in myc:

t_id=i[0]

if t_id==idd:

flag=1

if flag==1:

print('''

1.NAME

2.AGE

3.GENDER

4.SALARY ''')

ch=int(input('''

ENTER YOUR CHOICE: '''))

if ch==1:

name=input('''

ENTER UPDATED NAME: ''')

myc.execute("update trainer set name='"+name+"' where id='"+str(idd)+"'")

myd.commit()

if ch==2:

age=input('''

ENTER UPDATED AGE: ''')

myc.execute("update trainer set age='"+age+"' where id='"+str(idd)+"'")

myd.commit()

if ch==3:

gender=input('''

ENTER UPDATED GENDER(M/F): ''')

myc.execute("update trainer set gender='"+gender+"' where id='"+str(idd)+"'")


myd.commit()

if ch==4:

salary=int(input('''

ENTER UPDATED SALARY: '''))

myc.execute("update trainer set salary='"+str(salary)+"' where id='"+str(idd)+"'")

myd.commit()

elif ch==3:

idd=int(input('''

ENTER ID TO MODIFY: '''))

myc.execute('select * from member')

flag=0

for i in myc:

t_id=i[0]

if t_id==idd:

flag=1

if flag==1:

print('''

1.NAME

2.GENDER

3.CATEGORY ''')

ch2=int(input('''

ENTER YOUR CHOICE: '''))

if ch2==1:

name=input('''

ENTER UPDATED NAME: ''')

myc.execute("update member set name='"+name+"' where id='"+str(idd)+"'")

myd.commit()

elif ch2==2:

gender=input('''
ENTER UPDATED GENDER: ''')

myc.execute("update member set gender='"+gender+"' where id='"+str(idd)+"'")

myd.commit()

elif ch2==3:

print('''

1.SILVER

2.GOLD

3.PLATINUM

''')

myc.execute('select * from fees')

for i in myc:

t_silver,t_gold,t_platinum=i

ch3=int(input('''

ENTER YOUR CHOICE: '''))

if ch3==1:

category="silver"

amt=t_silver

elif ch3==2:

category="gold"

amt=t_gold

elif ch3==3:

category="platinum"

amt=t_platinum

myc.execute("update member set category='"+category+"', amt='"+str(amt)+"'


where id='"+str(idd)+"'")

myd.commit()

else:

print('''

ID NOT FOUND ''')


elif ch==4:

break

#Change Password

elif ch==6:

passs=input('''

ENTER OLD PASSWORD: ''')

myc.execute('select * from login')

for i in myc:

t_user,t_pas=i

if t_pas==passs:

new_pas=input('''

ENTER NEW PASSWORD: ''')

myc.execute("update login set password='"+new_pas+"'")

myd.commit()

print('''

CHANGED PASSWORD SUCCESSFULLY :D ''')

else:

print('''

WRONG PASSWORD ''')

else:

Break
Output:
1. Adding trainer:
2. Adding member:
3.Removing Trainer:
4.Removing Member:
5.MODIFY:

Member table before modification of information :

Member table post info modification now category changed to platinum from silver :
BIBLIOGRAPHY:
. CLASS 12 – SUMITA ARORA CS TEXTBOOK
.Geeksforgeeks.org
. Youtube

You might also like