Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

anyone can debug for me?? urgent..pls help!

Status
Not open for further replies.

chintseming

Technical User
Oct 12, 2001
13
SG
question:

Develop a program to allow users to perform operations on book records.
A book record should contain the below minimum information:

· ISBN : 10 characters
· Title : 30 characters
· Author : 30 characters
· Price : floating point number
· Category : an enumerated type of SF-Science Fiction, HR-Horror, RM-Romance
· PublishedDate : date format in nested date structure type dd/mm/yyyy

You program should be able to store up to 10 book records in an array called BookArray

Your program should at least perform the below operations:

· Add book records in BookArray
· Display all book records
· Find and display book information given the ISBN

· Find all books written by a particular Author
· Delete book record given the Title

this is the program!




#include <stdio.h>
#include <string.h>
typedef enum
{
SF_Science_Fiction=0, HR_Horror=1, RM_Romance=2
} Category_Value;

typedef struct
{
char ISBN[10];
char Title[30];
char Author[30];
float Price;
Category_Value Category;
char PublishedDate[11];
} BkArray;


void add_records(BkArray []);
void display_all_records(BkArray []);
void display_information(char *IBSN, BkArray []);
void display_books(BkArray []);
void delete_records(char *title, BkArray library);
void BarLine(int num);

main()
{
//variables
int choice;
char ISBN[10];

BkArray library[10];

BarLine(30);
printf(&quot;\tMENU\n&quot;);
BarLine(30);
printf(&quot;1 - Add new records.\n&quot;);
printf(&quot;2 - Display all book records.\n&quot;);
printf(&quot;3 - Find and display book information given the ISBN.\n&quot;);
printf(&quot;4 - Find all books written by a particular author.\n&quot;);
printf(&quot;5 - Delete book record given the title.\n&quot;);
printf(&quot;\nEnter your choice: &quot;);
scanf(&quot;%d&quot;, &choice);

switch(choice)
{
case 1: add_records(library);
break;
case 2: display_all_records(library);
break;
case 3: printf(&quot;Enter ISBN: &quot;);
scanf(&quot;%s&quot;, ISBN);
break;
case 4: display_books(library);
break;
case 5: printf(&quot;Enter title: &quot;);
break;
default: printf(&quot;\nThere is no such choice.\n&quot;);
}

return 0;
}


void BarLine(int num)
{
for(int l = 0; l < num; l++)
printf(&quot;=&quot;);
printf(&quot;\n&quot;);
}



void add_records(BkArray lib[])
{

int number;

printf(&quot;\nEnter the number of records that you are going to enter: &quot;);
scanf(&quot;%d&quot;, &number);

for(int k = 0; k < number; k++)
{
printf(&quot;\n#%d Record:\n&quot;, k+1);
BarLine(30);
printf(&quot;Enter ISBN: &quot;);

gets( lib[k].ISBN);
printf(&quot;\nEnter the title of the book: &quot;);
gets( lib[k].Title);
printf(&quot;\nEnter the author of the book: &quot;);
gets(lib[k].Author);
printf(&quot;\nEnter the price of the book: &quot;);
scanf(&quot;%f&quot;, &lib[k].Price);
printf(&quot;\nEnter the category of the book\n&quot;);
scanf(&quot;%d&quot;, &lib[k].Category);
printf(&quot;\nEnter the published date in the format of dd/mm/yyyy: &quot;);
gets (lib[k].PublishedDate);
}
}



void display_all_records(BkArray library[])
{
for (int p = 0; p != 9; p++)
{
printf(&quot;\n#%d Record:\n&quot;, p+1);
BarLine(30);
printf(&quot;ISBN: %s\n&quot;, library[p].ISBN);
printf(&quot;Title: %s\n&quot;, library[p].Title);
printf(&quot;Author: %s\n&quot;, library[p].Author);
printf(&quot;Price: %f\n&quot;, library[p].Price);
printf(&quot;Category: %s\n&quot;, library[p].Category);
printf(&quot;Published Date: %s\n&quot;, library[p].PublishedDate);
}
return;
}



void display_information(char *ISBN, BkArray library[])
{
for (int q = 0; q != 9; q++)
{
if (strcmp(library[q].ISBN,ISBN))
{
printf(&quot;Book Found!&quot;);
printf(&quot;ISBN: %s\n&quot;, library[q].ISBN);
printf(&quot;Title: %s\n&quot;, library[q].Title);
printf(&quot;Author: %s\n&quot;, library[q].Author);
printf(&quot;Price: %s\n&quot;, library[q].Price);
printf(&quot;Category: %s\n&quot;, library[q].Category);
printf(&quot;Published Date: %s\n&quot;, library[q].PublishedDate);
return;
}
}
printf(&quot;Book cannot be found!&quot;);
}



void display_books(BkArray lib[])
{

char author1[31];

printf(&quot;Enter author: &quot;);
scanf(&quot;%s&quot;, &author1);

for(int r = 0; r != 9; r++)
{
if(lib[r].Author == author1)
printf(&quot;%s\n&quot;, lib[r].Title);
}

}



void delete_records(char *title, BkArray library)
{
for (int i = 0; i < sizeof(library.BookArray); i++)
{
if(title == library.BookArray.title)
{
for (int j = i; j < sizeof(library.BookArray); j++)
library.BookArray[j].title =
library.BookArray[j++].title;
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top