Skip to content

Commit 99e4655

Browse files
authored
Add files via upload
1 parent a3893c1 commit 99e4655

File tree

2 files changed

+387
-0
lines changed

2 files changed

+387
-0
lines changed

Book Management System.c

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
//......... PF Assignment 3.........//
2+
/* Code written By Kunwar Ahmad
3+
FA-20-BSE-064 G1(Section B)*/
4+
5+
#include<stdio.h>
6+
#include<string.h>
7+
8+
struct book
9+
{
10+
int bookid;
11+
int bookcode;
12+
char name[20];
13+
char Aname[20];
14+
int d, m, y;
15+
float price;
16+
int copy_in_hand;
17+
int copy_sold;
18+
};
19+
20+
// Display Books in Tabular Form
21+
void display(struct book books[])
22+
{
23+
int i;
24+
printf("\n BOOKS ENTERED : \n\n"); //displaying the books with
25+
printf("|------------------------------------------------------------------------------------------------------------|\n");
26+
printf("|------------------------------------------------------------------------------------------------------------|\n");
27+
printf("| ID CODE NAME AUTHOR DATE PRICE STOCK SOLD |\n");
28+
printf("|------------------------------------------------------------------------------------------------------------|\n");
29+
printf("|------------------------------------------------------------------------------------------------------------|");
30+
for (int i = 0; i < 100; i++)
31+
{
32+
if (books[i].bookcode != 0) //deleted book will not be visible
33+
printf("\n| %3d | %5d | %12s | %12s | (%d/%d/%d) | %9.2f | %5d | %5d |", books[i].bookid,
34+
books[i].bookcode,
35+
books[i].name,
36+
books[i].Aname,
37+
books[i].d,
38+
books[i].m,
39+
books[i].y,
40+
books[i].price,
41+
books[i].copy_in_hand,
42+
books[i].copy_sold);
43+
}
44+
printf("\n--------------------------------------------------------------------------------------------------------------");
45+
}
46+
47+
//Deleting Book
48+
void del(struct book books[])
49+
{
50+
int i;
51+
printf("\n Enter Book Code you want to delete: ");
52+
scanf("%d", &i);
53+
books[i - 1].bookcode = 0;
54+
printf(" Book Deleted\n");
55+
}
56+
57+
//Searching Book
58+
void search(struct book books[])
59+
{
60+
int i, k, flag;
61+
printf("\nEnter Book Code to search : ");
62+
scanf("%d", &i);
63+
64+
for (k = 0; k < 100; k++)
65+
{
66+
if (books[k].bookcode == i)
67+
{
68+
printf("Found Book %d. \n ", k + 1);
69+
flag = 0;
70+
break;
71+
}
72+
else
73+
{
74+
flag = 1;
75+
}
76+
}
77+
if (flag == 1)
78+
{
79+
printf("Book not Found.\n ");
80+
}
81+
}
82+
83+
//Selling Book
84+
void sale(struct book books[])
85+
{
86+
int i, k, flag = 0, sale;
87+
printf("\nEnter Book Code to Sale : ");
88+
scanf("%d", &i);
89+
printf("\nEnter no of books you want to sale : ");
90+
scanf("%d", &sale);
91+
92+
for (k = 0; k < 100; k++)
93+
{
94+
if (i == books[k].bookcode)
95+
{
96+
if (sale <= books[k].copy_in_hand)
97+
{
98+
books[k].copy_in_hand -= sale;
99+
books[k].copy_sold += sale;
100+
printf("%d Books at ID %d is Sold", sale, k + 1);
101+
}
102+
else
103+
{
104+
printf("Out of stock or enter less quantity\n ");
105+
}
106+
}
107+
}
108+
}
109+
110+
111+
void main()
112+
{
113+
int i, no;
114+
struct book books[100] = { {1,1011,"Calculus","Ahmad",10,02,2005,2000.25,45,5},
115+
{2,1012,"Geometry","Kunwar",10,02,2005,2200,37,13},
116+
{3,1013,"Calculus II","Fahad",10,02,2005,2300,35,15},
117+
{4,1014,"Islamiyat","Rohan",10,02,2005,2350,34,16},
118+
{5,1015,"English","Ali",10,02,2005,1000,37,13},
119+
{6,1016,"Chemistry","Saim",10,02,2005,150,25,25},
120+
{7,1017,"Physics","Arsalan",10,02,2005,1700,47,3},
121+
{8,1018,"Urdu","Faizan",10,02,2005,950,40,10},
122+
{9,1019,"Maths","Humayun",10,02,2005,2350,15,35},
123+
{10,1020,"Pak Studies","Shahzad",10,02,2005,1200,35,15},
124+
{0,0," "," ",0,0,0,0.0,0,0}
125+
};
126+
char option;
127+
128+
129+
int menu = 0;
130+
while (menu != 6) //for repetition of Menu
131+
{
132+
//Displaying Menu
133+
printf("\n\n\n");
134+
printf(" ____*********____\n\n");
135+
printf(" 1 - Add book\n\n");
136+
printf(" 2 - Display books\n\n");
137+
printf(" 3 - Delete book\n\n");
138+
printf(" 4 - Search book\n\n");
139+
printf(" 5 - Sale book\n\n");
140+
printf(" 6 - Exit\n\n");
141+
printf(" ____*********____\n\n\n");
142+
143+
144+
145+
printf("\nEnter following option to perform function (1 to 6) = ");
146+
scanf("%d", &menu);
147+
148+
if (menu == 1) //OPTION 1 To Add Book Record
149+
{
150+
printf("Enter Book Id: ");
151+
scanf("%d", &no);
152+
for (i = no - 1; i < 100; i++)
153+
{
154+
//User will enter No of Book
155+
books[i].bookid = no;
156+
157+
printf("Book Code: ");
158+
scanf("%d", &books[i].bookcode);
159+
fflush(stdin);
160+
161+
printf("Book Name: ");
162+
gets(books[i].name);
163+
fflush(stdin);
164+
165+
printf("Author Name: ");
166+
gets(books[i].Aname);
167+
fflush(stdin);
168+
169+
printf("Publish Date (dd/mm/yyyy) : ");
170+
scanf("%d/%d/%d", &books[i].d, &books[i].m, &books[i].y);
171+
fflush(stdin);
172+
173+
printf("Book Price: ");
174+
scanf("%f", &books[i].price);
175+
fflush(stdin);
176+
177+
printf("Books in hand: ");
178+
scanf("%d", &books[i].copy_in_hand);
179+
fflush(stdin);
180+
181+
printf("Books Sold: ");
182+
scanf("%d", &books[i].copy_sold);
183+
fflush(stdin);
184+
185+
printf("\nYou want to enter more(Y/N) :");
186+
scanf("%c", &option);
187+
188+
if (option == 'y' || option == 'Y')
189+
{
190+
printf("Enter Book ID =");
191+
scanf("%d", &no);
192+
}
193+
else
194+
{
195+
break;
196+
}
197+
}
198+
}
199+
200+
else if (menu == 2) //OPTION 2 To Display Book Record
201+
{
202+
printf("\n2-Display book \n");
203+
display(books);
204+
}
205+
206+
else if (menu == 3)
207+
{
208+
del(books);
209+
}
210+
211+
else if (menu == 4)
212+
{
213+
printf("\n4-Search book codes : \n");
214+
search(books);
215+
}
216+
217+
else if (menu == 5)
218+
{
219+
sale(books);
220+
}
221+
222+
if (menu > 6) //if user entered invalid option
223+
{
224+
printf("\n Enter a valid option.");
225+
}
226+
227+
}
228+
printf("\nExited Successfully\n");
229+
}

Library Management System.c

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
//......... PF Assignment 2.........//
2+
/* Code written By Kunwar Ahmad
3+
FA-20-BSE-064 G1(Section B)*/
4+
5+
#include<stdio.h>
6+
int add_book(int books[]);
7+
int print_books(int books[]);
8+
int del_book(int books[]);
9+
int searchBook(int books[]);
10+
int sortBooks(int books[]);
11+
12+
13+
int main()
14+
{
15+
//Displaying Menu
16+
printf("_______________________\n");
17+
printf("1 - Add book code\n");
18+
printf("2 - Display book codes\n");
19+
printf("3 - Delete book code\n");
20+
printf("4 - Search book Code\n");
21+
printf("5 - Arrange book code\n");
22+
printf("6 - Exit\n");
23+
printf("_______________________\n");
24+
25+
int books[20] = {0};
26+
int menu = 0;
27+
while (menu != 6) //for repetition of Menu
28+
{
29+
printf("\nEnter following option to perform function (1 to 6) = ");
30+
scanf("%d", &menu);
31+
if (menu == 1) //Comparing the options
32+
{
33+
add_book(books);
34+
}
35+
36+
else if (menu == 2)
37+
{
38+
printf("\n2-Display book codes : \n");
39+
print_books(books);
40+
}
41+
42+
else if (menu == 3)
43+
{
44+
del_book(books);
45+
}
46+
47+
else if (menu == 4)
48+
{
49+
printf("\n4-Search book codes : \n");
50+
searchBook(books);
51+
}
52+
53+
else if (menu == 5)
54+
{
55+
printf("\n5 - Arranged Book Codes : \n");
56+
sortBooks(books);
57+
}
58+
59+
if (menu > 6) //if user entered invalid option
60+
{
61+
printf("Enter a valid option.");
62+
}
63+
printf("\nExited Successfully.\n\n");
64+
}
65+
return 0;
66+
}
67+
68+
//Adding Books
69+
int add_book(int books[])
70+
{
71+
int i;
72+
printf("\nEnter 20 book codes \n\n");
73+
for (i = 0; i < 20; i++)
74+
{
75+
printf(" Book %d = ", i + 1); //User will enter 20 book codes
76+
scanf("%d", &books[i]);
77+
}
78+
return books[i];
79+
}
80+
81+
//Printing Entered Books
82+
int print_books(int books[])
83+
{
84+
int i;
85+
printf("\n BOOKS ENTERED : \n"); //displaying the books with code
86+
for (int i = 0; i < 20; i++)
87+
{
88+
if (books[i] != 0) //deleted book will not be visib
89+
printf(" \nBook [%d] = %d", i + 1, books[i]);
90+
}
91+
92+
return 0;
93+
}
94+
95+
//Deleting Book
96+
int del_book(int books[])
97+
{
98+
int i;
99+
printf("\n Enter Book you want to delete: ");
100+
scanf("%d", &i);
101+
books[i - 1] = 0;
102+
printf(" Book Deleted\n");
103+
return 0;
104+
}
105+
106+
//Searching Book
107+
int searchBook(int books[])
108+
{
109+
int i, k, flag;
110+
printf("\nEnter Book Code to search : ");
111+
scanf("%d", &i);
112+
113+
for (k = 0; k < 20; k++)
114+
{
115+
if (books[k] == i)
116+
{
117+
printf("Found Book %d. \n ", k + 1);
118+
flag = 0;
119+
break;
120+
}
121+
else
122+
{
123+
flag = 1;
124+
}
125+
}
126+
if (flag == 1)
127+
{
128+
printf("Book not Found.\n ");
129+
}
130+
return 0;
131+
}
132+
133+
//Arranging Books in ascending order
134+
int sortBooks(int books[])
135+
{
136+
int i, pass, k = 1, hold;
137+
for (pass = 1; pass < 20; pass++)
138+
{
139+
for (i = 0; i <= 20 - 2; i++)
140+
{
141+
if (books[i] > books[i + 1])
142+
{
143+
hold = books[i];
144+
books[i] = books[i + 1];
145+
books[i + 1] = hold;
146+
}
147+
}
148+
}
149+
for (i = 0; i < 20; i++) // displaying Arranged books
150+
{
151+
if (books[i] != 0)
152+
{
153+
printf("book %d- %d\n", k, books[i]);
154+
k++;
155+
}
156+
}
157+
return 0;
158+
}

0 commit comments

Comments
 (0)