
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Write a C program of library management system using switch case
Problem
How to store the books-related information of library using C programming.
Algorithm
Step 1: Declare a structure which holds data members Step 2: declare variables which are used for loop Step 3: use switch case to work on each module Step 4: case 1- for Adding book information Case 2- for Display book information Case 3- for Finding number for books in library Case 4- for EXIT
Program
#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> struct library{ char bookname[50]; char author[50]; int noofpages; float price; }; int main(){ struct library lib[100]; char bookname[30]; int i,j, keepcount; i=j=keepcount = 0; while(j!=6){ printf("
1. Add book information
"); printf("2.Display book information
"); printf("3. no of books in the library
"); printf("4. Exit"); printf ("
Enter one of the above : "); scanf("%d",&j); switch (j){ /* Add book */ case 1: printf ("Enter book name = "); scanf ("%s",lib[i].bookname); printf ("Enter author name = "); scanf ("%s",lib[i].author); printf ("Enter pages = "); scanf ("%d",&lib[i].noofpages); printf ("Enter price = "); scanf ("%f",&lib[i].price); keepcount++; i++; break; case 2: printf("you have entered the following information
"); for(i=0; i<keepcount; i++){ printf ("book name = %s
",lib[i].bookname); printf ("\t author name = %s
",lib[i].author); printf ("\t pages = %d
",lib[i].noofpages); printf ("\t price = %f
",lib[i].price); } break; case 3: printf("
No of books in library : %d", keepcount); break; case 4: exit (0); } } return 0; }
Output
1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 1 Enter book name = HarryPotter Enter author name = hp Enter pages = 250 Enter price = 350.6 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 2 you have entered the following information book name = HarryPotter author name = hp pages = 250 price = 350.600006 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 3 No of books in library : 1 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 4
- Related Articles
- Write a C program for electing a candidate in Elections by calling functions using Switch case
- Write a C program using time.h library function
- C program to find the areas of geometrical figures using switch case
- Using range in switch case in C/C++
- Java program to generate a calculator using the switch case
- Java Program to Make a Simple Calculator Using switch...case
- Haskell Program to Make a Simple Calculator Using switch...case
- Golang Program to make a Simple Calculator using Switch Case
- Write a C program to Reverse a string without using a library function
- Write a C program to compare two strings using strncmp library function
- C program to print area of triangle, square, circle, rectangle and polygon using switch case.
- Write a C program demonstrating strlen library function
- C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch...case
- Switch case statement in C
- Converting digits to word format using switch case in C language

Advertisements