PDA

View Full Version : راهنمايي در برنامه مديريت كتابخانه.c



hobab1987
دوشنبه 09 دی 1387, 22:23 عصر
سلام
اين برنامه مربوط به مديريت كتابخانه است كه خيلي ارور ميده


//This program do management a library,add books,delete books, search a book.
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <string.h>
struct bookinfo{
private:
char title[10];
char author[10];
char publisher[10];
char stead[10];
int history;
int version_num;
public:
void addnew();
int search(char[]);
void print();
int menu1(int);
void menu2();
void quit();
int report();
void bubble1();
void bubble2();
};
//************************************************** ****************************
//Main Part Of The Program
//************************************************** ****************************
int main()
{
bookinfo inf1[400];
int count = 0, choise, error = 0, scount,i,n,num;
char wrd[10],t[10];
for( ; ; )
{
clrscr();
choise = inf1[0].menu1(error);
error = 0;
switch(choise)
{
case 1: //Entering new bookinfo
inf1[count].addnew();
count++;
break;
case 2: //Searching new bookinfo
clrscr();
gotoxy(31,20);
printf("Enter a word to search:");
gets(wrd);
clrscr();
scount = 0;
for(i = 0; i < count; i++)
{
if(inf1[i].search(wrd))
scount++;
if(scount == 1)
{
printf ("%-4s %-10s %-10s %-10s %-10s %-10s %-10s\n"
,"NO.", "Title", "Author", "Publisher", "Stead"
, "History", "Version");
printf("%-4d ", scount);
inf1[0].print();
inf1[i].menu2();
}
}
if(scount == 0)
{
printf("\n not found.");
printf("\n press any key to continue.");
getch();
}
break;
case 3: //Reports
clrscr();
inf1[0].report();
if(n==1)
{
inf1[400].bubble1();
}
if(n==2)
{
inf1[400].bubble2();
}
if(n==3)
{
inf1[0].menu1(error);
}
case 4: //Exit the program
inf1[0].quit();
break;
default: //incorrect value
error = -1;
break;
}
}
}
//***********<<Main menu1>>**********
int bookinfo::menu1(int error)
{
char ans;
int row=25;
gotoxy(row,17);
printf("1) Add record");
gotoxy(row,19);
printf("2) Search record");
gotoxy(row,21);
printf("3) Reports");
gotoxy(row,23);
printf("4) Exit");
gotoxy(row,25);
printf("Enter a valil number between 1 to 4 :");
if (error)
{
gotoxy(row,27);

printf("Enter a valid number between 1 to 4!");
}
fflush(stdin);
ans=getch();
return ans - '0';
}
//********************<<Quit>>**********************
void bookinfo::quit()
{
char ans;
clrscr();
gotoxy(35,22);
printf("<<Quit>>");
gotoxy(28,25);
printf("Do You Want to Quit(Y/N)?");
ans=getch();
if(ans == 'y' || ans == 'Y')
exit(0);
else
return;
}
//**************<<Add new bookinfo>>*************
void bookinfo::addnew()
{
int col=25;
clrscr();
gotoxy(col,18);
printf("Enter Title Of Book:");
scanf("%s",title);
gotoxy(col,20);
printf("Enter Author Name :");
scanf("%s",author);
gotoxy(col,22);
printf("Enter Publisher Name:");
scanf("%s",publisher);
gotoxy(col,24);
printf("Enter Stead Of Propagation:");
scanf("%s",stead);
gotoxy(col,26);
printf("Enter History Of Propagation :");
scanf("%d",&history);
gotoxy(col,28);
printf("Enter Number Of This Book Exist:");
scanf("%d",&version_num);
}
//********************<<Print bookinfo>>*******************
void bookinfo::print()
{
printf("%-10s %-10s %-10s %-10s %-10d %-10d\n", title, author
, publisher, stead, history, version_num);
}
//**************<<search bookinfo>>*************
int bookinfo::search(char wrd[])
{
if (strstr(title, wrd))
return -1;
if (strstr(author, wrd))
return -1;
if (strstr(publisher, wrd))
return -1;
return 0;
}
//*************<<Main menu2>>************
void bookinfo::menu2()
{
bookinfo inf1[400];
int num,i,j,scount,h,v;
char t[10],a[10],s[10],p[10];
printf("\n %s %s %s %s","1)Delete Record","2)Change Record"
,"3)Next Record>>","4)Main Menu");
printf(" Select:");
scanf("%d", &num);
for(j = i; j<scount; j++)
{
if(num == 1)
{
strcpy(inf1[j].title,inf1[j+1].title);
strcpy(inf1[j].author,inf1[j+1].author);
strcpy(inf1[j].publisher,inf1[j+1].publisher);
strcpy(inf1[j].stead,inf1[j+1].stead);
strcpy(inf1[j].history,inf1[j+1].history);
strcpy(inf1[j].version_num,inf1[j+1].version_num);
}
}
if(num == 2)
{
printf("\n Enter title:");
scanf("%s",t);
strcpy(inf1[j].title,inf1[j+1].title);
printf("\n Enter author:");
scanf("%s",a);
strcpy(inf1[j].author,inf1[j+1].author);
printf("\n Enter publisher:");
scanf("%s",p);
strcpy(inf1[j].publisher,inf1[j+1].publisher);
printf("\n Enter stead:");
scanf("%s",s);
strcpy(inf1[j].stead,inf1[j+1].stead);
printf("\n Enter history:");
scanf("%d",&h);
strcpy(inf1[j].history,inf1[j+1].history);
printf("\n Enter version:");
scanf("%d",&v);
strcpy(inf1[j].version_num,inf1[j+1].version_num);
}
if(num == 3)
{
return '10';
}
if(num == 4){
inf1[0].menu1(error);
}
//********<<Report by book title>>********
void bookinfo::bubble1()
{
bookinfo inf1[400],temp;
int i,j,count;
for(i = count - 1; i > 0; i--)
{
for(j = 0; j < i; j++)
{
if(strcmp(inf1[j].title, inf1[j + 1].title) > 0)
{
temp = inf1[j];
inf1[j] = inf1[j + 1];
inf1[j + 1] = temp;
}
}
}
}
//***********<<Report by author>>*****************
void bookinfo::bubble2()
{
bookinfo inf1[400],temp;
int i,j,count;
for(i = count - 1; i > 0; i--)
{
for(j = 0; j < i; j++)
{
if(strcmp(inf1[j].author, inf1[j + 1].author) > 0)
{
temp = inf1[j];
inf1[j] = inf1[j + 1];
inf1[j + 1] = temp;
}
}
}
}
//*********<<Report main menu>>************
int bookinfo::report()
{
int row=25,n;
gotoxy(row,18);
printf("1)report by title");
gotoxy(row,20);
printf("2)report by author");
gotoxy(row,22);
printf("3)return to main menu");
gotoxy(row,24);
printf("Select:");
scanf("%d",&n);
return n;
}


مشكل اين برنامه مربوط به توابع report و main menu 2 مي باشد
در تابع report گزارش بترتيب عنوان كتاب و گزارش به ترتيب نام نويسنده است
و در تابع main menu2 ايجاد يك منوي 4 گزينه اي بعد از اولين ركورد search شده است
كه گزينه اول حذف ركورد
گزينه 2 تغيير ركورد
گزينه 3 ركورد بعدي
و آخري صفحه اصلي
من تمام كدها رو نوشتم اما برنامه ارور ميده لطفا راهنماييم كنيد.