Code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
struct Book{
char title[30],author[30],ISBN[30],publisher[30],month[30],price[30],quantity[30];
};
void AddBook(struct Book [],int *);
void displayTable(struct Book [],int *);
int Search(struct Book [],int *,char *);
void changePrice(struct Book [],int,char *);
void find_ToTal_New_Books(struct Book [],int *,char *[],int *);
enum Month {JAN=1,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC} ;
void main()
{
struct Book book[100];
char *MonthsName[]={"","January","February","March","April","May","June","July","August","September","October","November","December"};
int size = 100,key,count[13] = {0};
char enter,ISBN[30],price[30];
enum Month months;
do{
puts("1 - Add a Book");
puts("2 - Display Table");
puts("3 - Search for a Book");
puts("4 - Change a Price ");
puts("5 - Sold in each month");
puts("6 - Exit");
puts("Enter your Choice :");
scanf("%d%c",&key,&enter);
switch(key)
{
case 1:{
AddBook(book,&(--size));
break;
}
case 2:{
displayTable(book,&size);
break;
}
case 3:{
puts("Enter The ISBN of the Book:");
gets(ISBN);
if(Search(book,&size,ISBN)== -1)
printf("Not Found\n");
else
{
printf("ISBN : %s\n",ISBN);
printf("Book Title : %s\n",book[Search(book,&size,ISBN)].title );
}
break;
}
case 4:{
puts("Enter The ISBN of the Book:");
gets(ISBN);
if(Search(book,&size,ISBN)== -1)
printf("Not Found\n");
else
{
puts("Enter the new Price: ");
gets(price);
changePrice(book,Search(book,&size,ISBN),price);
}
break;
}
case 5:{
find_ToTal_New_Books(book,count,MonthsName,&size);
for( months=JAN;months<=DEC;months++)
printf("%-12s\t%d\n",*(MonthsName+months),count[months]);
break;
}
case 6:
{
break;
}
default:{
puts("Invalid Choice");
break;
}}
}while(key!=6);
}
void AddBook(struct Book *book,int *size)
{
puts("Enter the Title of the Book :");
gets(book[*size].title);
puts("Enter the Author of the Book :");
gets(book[*size].author);
puts("Enter the ISBN Number of the Book :");
gets(book[*size].ISBN );
puts("Enter the Publisher of the Book :");
gets(book[*size].publisher );
puts("Enter the Month of the Book first sold :");
gets(book[*size].month );
puts("Enter the Price of the Book :");
gets(book[*size].price );
puts("Enter the Quantity of the Book :");
gets(book[*size].quantity);
}
void displayTable(struct Book *book,int *size)
{
printf("%-15s%-15s%-10s%-10s%-10s%-10s%-10s\n","Title","Author","ISBN","Publisher","Month","Price","Quantity");
for(int i = 99;i>=*size;i--)
{
printf("%-15s%-15s%-10s%-10s%-10s%-10s%-10s\n",(book+i)->title,(book+i)->author,(book+i)->ISBN,(book+i)->publisher,(book+i)->month,(book+i)->price,(book+i)->quantity);
}
}
int Search(struct Book *book,int *size,char *ISBN)
{
for(int i = 99;i>=*size;i--)
if(strcmpi(book.ISBN,ISBN)==0)
return i;
return -1;
}
void changePrice(struct Book *book,int pos,char *price)
{
strcpy(book[pos].price,price);
}
void find_ToTal_New_Books(struct Book *book,int *count,char *MonthsName[],int *size)
{
for(int i = 99;i>=*size;i--)
{
if (isdigit(book.month[0]))
{
int m;
sscanf(book.month,"%d",&m);
strcpy(book.month,*(MonthsName+m));
++*(count+m);
}
else
{
for(int j=1;j<=12;j++)
if (strcmpi(MonthsName[j],book.month)==0)
++*(count+j);
}
}
}
Bookmarks