Professional Documents
Culture Documents
Labfile
Labfile
Lab Assignment
Alekhya Gudibandla
22mc3015
Mathematics and Computing
Q1 Design an ER diagram for a simple library management system that tracks books, authors, and
library members. The system should keep track of which books are available in the library and which
are currently checked out by members. Each book has a unique ISBN and title and may be written by
one or more authors. Each author has a unique ID and a name. Each member of the library has a
unique ID and a name and can check out multiple books.
Write down the basic implementation of the library management system using the C programming
language, focusing on managing books and members. The program should define structures for books
and members to represent entities in the ER diagram. Add functions like addBook and addMember to
allow adding books and members to the system. The displayBooks and displayMembers functions
print the list of books and members, respectively.
ANSWER:
1. Entities
a. Books
This table contains all the books present in the library
b. Authors
This entity represents authors of the books.
c. Members
This entity represents library members
d. Checkout
This entity represents the checkout history of books by members.
e. Book_Authors
This entity represents the relationship between books and authors. This table allows us to
search for all the books written by an author or all the authors of a book.
2. Attributes
a. Books
• ISBN (Primary key)
• Title
• No. of copies
b. Authors
• Author_ID (Primary Key)
• Name.
c. Members
• Member_ID (Primary Key)
• Name
d. Checkout
• Checkout_ID (Primary Key)
• Book_ISBN (Foreign Key referencing ISBN in Book table)
• Member_ID (Foreign Key referencing Member_ID in Member table)
• Checkout_Date
• Return_Date
e. Book_Authors
• Book_ISBN
• Author_ID
3. Relationships
a. Book to Author
Many to many relationship
b. Book to checkout
One to many relationship
c. Members to checkout
One to many relationship
ER DIAGRAM:
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int member_id;
char name[100];
} Member;
// Function prototypes
void addBook(Book books[], int *num_books);
void addMember(Member members[], int *num_members);
void displayBooks(Book books[], int num_books);
void displayMembers(Member members[], int num_members);
int main() {
Book books[100]; // Maximum 100 books
Member members[100]; // Maximum 100 members
int num_books = 0;
int num_members = 0;
int choice;
do {
printf("\nLibrary Management System Menu\n");
printf("1. Add Book\n");
printf("2. Add Member\n");
printf("3. Display Books\n");
printf("4. Display Members\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addBook(books, &num_books);
break;
case 2:
addMember(members, &num_members);
break;
case 3:
displayBooks(books, num_books);
break;
case 4:
displayMembers(members, num_members);
break;
case 5:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice! Please enter a number between 1 and 5.\n");
}
} while (choice != 5);
return 0;
}
(*num_books)++;
printf("Book added successfully.\n");
}
(*num_members)++;
printf("Member added successfully!\n");
}
if (num_books == 0) {
printf("No books available.\n");
return;
}
if (num_members == 0) {
printf("No members available.\n");
return;
}
Q2 Consider an ER diagram for a university database system that includes entities like student,
course, and enrollment. Each student can enroll in multiple courses, and each course can have
multiple students enrolled. Design an ER diagram for this system and convert it into a relation model.
Then, implement basic functionalities in the C language to add students, courses, and enrollments and
display them. Add Functions like addStudent, addCourse, and enrollStudent allow adding students,
courses, and enrollments to the system. The displayStudents, displayCourses, and displayEnrollments
functions print the list of students, courses, and enrollments, respectively.
ANSWER:
1. Entities:
a. Student
b. Course
c. Enrollment
2. Attributes:
a. Student:
• StudentID (Primary Key)
• Name
• Email
• Address
• Phone number
b. Course:
• CourseID (Primary Key)
• Title
• Department
• Credits
c. Enrollment:
• EnrollmentID (Primary Key)
• StudentID (Foreign Key referencing Student)
• CourseID (Foreign Key referencing Course)
• Enrollment date
• Grade
3. Relationships:
a. Student – Enrollment
One-to-Many
b. Course – Enrollment
One-to-Many
4. Relational Model:
Tables:
• Student (StudentID, Name, Address, Email, PhoneNumber)
• Course (CourseID, Title, Credits, Department)
• Course (CourseID, Title, Credits, Department)
• Enrollment (EnrollmentID, StudentID, CourseID, EnrollmentDate, Grade)
ER Diagram
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int id;
char name[100];
} Student;
typedef struct {
char code[20];
char name[100];
} Course;
typedef struct {
int studentID;
char courseCode[20];
} Enrollment;
int main() {
Student students[100];
Course courses[100];
Enrollment enrollments[100];
int numStudents = 0;
int numCourses = 0;
int numEnrollments = 0;
int choice;
do {
printf("\nUniversity Database System\n");
printf("1. Add Student\n");
printf("2. Add Course\n");
printf("3. Enroll Student\n");
printf("4. Display Students\