Professional Documents
Culture Documents
Nouman Mushtaq
FA20-CHE-085
Question No 1. Marks: 10
CLO:4; C5: PLO3
Learning Objectives: Demonstrate the knowledge of Structs.
Question 1:
Develop a program which handled book information for a bookshop. Your program should
store following information of a book:
BoodID, BookName, Author Name, Price, PublishingDate
In main create a menu and ask user’s choice:
1. Press 1 to add a book
2. Press 2 to display a book
3. Press 3 to display a book
Create functions to Add book. Ask user to input the information of a book. You have to add
at least 5 books.
Create function to display all book in tabular format.
Create a function to search a book by id. If the book found, display complete information of
that book.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct book
{
int b_id;
char b_name[60];
char b_author[40];
float b_price;
int b_publishingDate;
};
void AddBook(struct book *book, int n)
{
fflush(stdin);
printf("-------------------------------------\n");
printf("Add Details of %d Book\n",n);
printf("-------------------------------------\n");
for(int i = 0 ; i < n ; i++)
{
fflush(stdin);
printf("Enter Book ID : ");
scanf("%d",&book[i].b_id);
fflush(stdin);
printf(" Enter Book title : ");
scanf(" %[^\n]%*c", &book[i].b_name);
fflush(stdin);
printf("Enter Author Name : ");
Output: