Tuesday, September 9, 2014

Library management using structure

8 comments

Problem

Write a menu driven program that depicts the working of a library. The menu options should be:
  1. Add book information
  2. Display book information
  3. List all books of given author
  4. List the title of specified book
  5. List the count of books in the library
  6. List the books in the order of accession number
  7. Exit
Create a structure called library to hold accession number, title of the book, author name, price of the book, and flag indicating whether book is issued or not.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct library
{
 char bk_name[30];
 char arthur[30];
 int pages;
 float price;
};

int main()
{
 struct library l[3];
 char ar_nm,bk_nm;
 int i,j;

 printf ("1. Add book information\n2. Display book information\n3. List all books of given author\n4. List the title of specified book\n5. List the count of books in the library\n6. Exit");

 printf ("\n\nEnter one of the above : ");
 scanf("%d",&j);

 switch (j)
 {
  case 1:
   for (i=0;i<3;i++)
   {

    printf ("Enter book name = ");
    scanf ("%s",&l[i].bk_name);

    printf ("Enter arthur name = ");
    scanf ("%s",&l[i].arthur);

    printf ("Enter pages = ");
    scanf ("%d",&l[i].pages);

    printf ("Enter price = ");
    scanf ("%f",&l[i].price);
   }
   break;
  case 2:
   printf("you have entered the following information\n");
   for(i=0;i<3;i++)
   {
    printf ("book name = %s",l[i].bk_name);

    printf ("arthur name = %s",l[i].arthur);

    printf ("pages = %d",l[i].pages);

    printf ("price = %f",l[i].price);
   }
   break;

  case 3:
   printf ("Enter arthur name : ");
   scanf ("%s",&ar_nm);
   for (i=0;i<3;i++)
   {
    if (ar_nm == l[i].arthur)
     printf ("%s %s %d %f",l[i].bk_name,l[i].arthur,l[i].pages,l[i].price);
   }
   break;

  case 4:
   printf ("Enter book name : ");
   scanf ("%s",&bk_nm);
   for (i=0;i<3;i++)
   {
    if (bk_nm == l[i].bk_name)
     printf ("%s %s %d %f",l[i].bk_name,l[i].arthur,l[i].pages,l[i].price);
   }
   break;

  case 5:
   for (i=0;i<3;i++)
   {

   }
   break;
  case 6:
   exit (0);


 }
 return 0;
}

Sample Output

library working using struct

Read More..

compare two dates input by the user, using structure

0 comments

Problem

Write a program that compares two given dates. To store date use structure say date that contains three members namely date, month and year. If the dates are equal then display message as "Equal" otherwise "Unequal".

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct dt_cmp
{
 int day;
 int month;
 int year;
};
main()
{
 struct dt_cmp s[2];
 int i;

 for (i=0;i<2;i++)
 {
  printf ("Enter day : ");
  scanf ("%d",&s[i].day);
  printf ("Enter month : ");
  scanf ("%d",&s[i].month);
  printf ("Enter year : ");
  scanf ("%d",&s[i].year);
 }

 if ( (s[0].day == s[1].day) && (s[0].month == s[1].month) && (s[0].year == s[1].year) )
  printf ("Equal\n");
 else
  printf ("Unequal\n");

 system("pause");
}

Sample Output

compare dates using structres

Read More..

search for a user (student) input data by using an array of structure, add user roll number, name, department, course, and year of joining by declaring a function name searchstudent(int)

0 comments

Problem

Create a structure to specify data on students given below:
  • Roll number
  • Name
  • Department
  • Course
  • Year of joining
Create above program by declaring an array of structure., input some value from user and then display those values. Also write a function:
void searchstudent (int roll_no);
This function will search a student record from that array whose Roll number is same as roll_no and display that record otherwise it displays record not found.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
 char name[30];
 int roll_no;
 char department[30];
 char course[30];
 int year;
};
void searchstudent (struct student *, int );

int main()
{

 struct student s[5];
 int i,rl,p;

 for (i=0;i<5;i++)
 {
  printf ("Enter name, ID, department, course, year : ");
  scanf("%s%d%s%s%d",&s[i].name,&s[i].roll_no,&s[i].department,&s[i].course,&s[i].year);
 }

 for (i=0;i<5;i++)
 {
  printf("And here is whhat you have entered\n\n");
  printf("Name = %s\n\nRoll No. = %d\n\nDepartment = %s\n\nCopurse = %s\n\nYear = %d\n\n",s[i].name,s[i].roll_no,s[i].department,s[i].course,s[i].year);
 }

 printf ("Enter number you want to search : ");
 scanf("%d",&rl);

 searchstudent (s ,rl);

 system("pause");
}
void searchstudent (struct student *p, int roll_no)
{
 int i,found = 0;
 for(i=0;i<5;i++)
 {
  if(p->roll_no == roll_no)
  {
   printf("record found");
   printf("Name = %s\n\nRoll No. = %d\n\nDepartment = %s\n\nCopurse = %s\n\nYear = %d\n\n",p->name,p->roll_no,p->department,p->course,p->year);
   found = 1;
  }
  if (found == 0)
   printf("Not found");
 }

}

Sample Output

search user roll# name using array of structure

Read More..

Display user input data by using an array of structure, add user roll number, name, department, course, and year of joining

0 comments

Problem

Create a structure to specify data on students given below:
  • Roll number
  • Name
  • Department
  • Course
  • Year of joining
Create above program by declaring an array of structure., input some value from user and then display those values.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct stud
{
 char name[30];
 int roll_no;
 char department[30];
 char course[30];
 int year;
}
int main()
{
 struct stud s[5];
 int i;

 for (i=0;i<5;i++)
 {
  printf ("Enter name, ID, department, course, year : ");
  scanf("%s%d%s%s%d",&s[i].name,&s[i].roll_no,&s[i].department,&s[i].course,&s[i].year);
}

 for (i=0;i<5;i++)
 {
  printf("And here is whhat you have entered\n\n");
  printf("Name = %s\n\nRoll No. = %d\n\nDepartment = %s\n\nCopurse = %s\n\nYear = %d\n\n",s[i].name,s[i].roll_no,s[i].department,s[i].course,s[i].year);
 }

 system("pause");
 return 0;
}

Sample Output

display user roll# name using array of structure

Read More..

write a program display user input data using structure, add user roll number, name, department, course, and year of joining

0 comments

Problem

Create a structure to specify data on students given below:
  • Roll number
  • Name
  • Department
  • Course
  • Year of joining
Create a variable of that structure, input some value from user and then display those values.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct stud
{
 char name[30];
 int roll_no;
 char department[30];
 char course[30];
 int year;
}
int main()
{
 struct stud s1;

 printf ("Enter name, ID, department, course, year : ");
 scanf("%s%d%s%s%d",&s1.name,&s1.roll_no,&s1.department,&s1.course,&s1.year);

 printf("And here is whhat you have entered\n");
 printf("Name = %s\n\nRoll No. = %d\n\nDepartment = %s\n\nCopurse = %s\n\nYear = %d\n\n",s1.name,s1.roll_no,s1.department,s1.course,s1.year);

 system("pause");
 return 0;
}

Sample Output


display user roll# name using struct

Read More..

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact