c programming for book store


#include<stdio.h>
 #include<conio.h>
#include<string.h>
struct record
{
          char author[20];
          char title[30];
          float price;
   struct
     {
          char month[10];
          int year;
      }
    date;
    char publisher[10];
    int quantity;
};
          int look_up(struct record table[],char s1[],char s2[],int m);
          void get(char string [ ]);
 main()
{
          char title[30],author[20];
          int index,no_of_records;
          char response[10], quantity[10];
          struct record book[]=     {
      { "Ritche","C language",45.00,"May",1977,"PHI",10},
      { "Kotchan","Programming in C",75.50,"July",1983,"Hayden",5},
      { "Balagurusamy","BASIC",30.00,"January",1984,"TMH",0},
      { "Balagurusamy","COBOL",60.00,"December",1988,"Macmillan",25}
                                         };
       no_of_records=sizeof(book)/sizeof(struct record);
          do
  {
          printf("Enter title and author name as per the list\n");
          printf("\n Title:");
          get(title);
          printf("Author:");

          get(author);
          index=look_up(book,title,author,no_of_records);
          if(index!=-1)
   {
          printf("\n %s %s %.2f %s %d %s\n\n",
          book[index].author,
          book[index].title,
          book [index].price,
          book[index].date.month,
          book[index].date.year,
          book[index].publisher);
          printf("Enter number of copies");
          get(quantity);
          if(atoi(quantity) < book[index].quantity)
          printf("cost of %d copies=%.2f\n",atoi(quantity),
          book[index].price*atoi(quantity));
     else
          printf("\n required copies not in stock\n\n");
      }
      else
      printf("\n Book not in list \n\n");
      printf("\n Do you want any other book?(YES/NO):");
      get(response);
      }
      while(response[0]=='Y'|| response[0]=='y');
      printf("\n\nthank you.good bye!\n");
   }
   void get(char string [])
   {
          char c;
          int i=0;
          do
   {
           c=getchar();
           string[i++]=c;
     }
       while(c !='\n');
       string[i-1]='\0';
     }
          int look_up(struct record table[],char s1[],char s2[],int m)
    {
          int i;
          for(i=0;i<m;i++)
          if(strcmp(s1,table[i].title)==0   &&
             strcmp(s2,table[i].author)==0)
             return(i);
      return(-1);

}



                                                      TESTING

Testing is the major control measure used during software development. Its basic function is to detect errors in the software. During requirement analysis and design, the output is a document that is usually textual and no executable. After the coding phase, computer programs are available that can be executed for testing purpose. This implies that testing not only, has to uncover errors introduced during coding, but also errors introduced during previous phase. Thus the goal of testing is to uncover the requirements, design and coding errors in the programs. So after testing the outputs of my project are as follows:

Enter title and author name as per the list

 Title:BASIC
Author:Balagurusamy

 Balagurusamy BASIC 30.00 January 1984 TMH

Enter number of copiesan
SHARE
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment