Example #1
0
int baseManage(Book b[],int n)    	     /*该函数完成基本信息管理*/
{  
	int choice,t,find[NUM];
	char judge1='n',judge2='n';
	Book b1;
	do
	{   
		menuBase( );					/*显示对应的二级菜单*/
		printf("choose one operation you want to do:");
		scanf("%d",&choice);	        /*读入选项*/
		switch(choice)
		{
			case 1:	 readBook(&b1,1);   /*读入一条待插入的图书信息*/
				n=insertBook(b,n,b1);   /*调用函数插入图书信息*/
				break;
			case 2:  printf("Input the ISBN deleted\n");
				scanf("%s",b1.ISBN);    	/*读入一个待删除图书的ISBN*/
				n=deleteBook(b,n,b1);   	/*调用函数删除指定ISBN的图书记录*/
				break;
			case 3:
                do
				{
					printf("Input the ISBN you want search: \n");
					scanf("%s",b1.ISBN);    /*读入一个待查找图书的ISBN*/
                    getchar();
					t=searchBook(b,n,b1,1,find) ; /*调用函数查找指定ISBN的图书记录*/
					if (t)                  /*如果该ISBN的记录存在*/
					{
						printf("change this information? (y/n)\n");
						scanf("%c",&judge2);
						if (judge2 == 'y')   /*判断是否修改该条信息*/
						{
							readBook(&b1,1); /*读入一条完整的图书记录信息*/
							b[find[0]]=b1;   /*将刚读入的记录赋值给需要修改的数组记录*/
						}
					}					 
					else                     /*如果ISBN的记录不存在*/
					{
						printf("this book is not in.\ninput again? (y/n)\n"); /*输出提示信息*/
						scanf("%c",&judge1);
					}
				} while (judge1 == 'y');
				break;
			case 0: 
                break;
        }
    } while (choice);
	return n;                               /*返回当前操作结束后的实际记录条数*/
}
Example #2
0
//------------------------------------------------------------------------------
bool BibleQuoteModule::createBookFiles(QString pathToFiles)
{
    Q_UNUSED (pathToFiles)
    QString t_pathToXmlFile = QString(QString(Config::configuration()->getDataPath() + GL_MODULE_PATH + "%1/" +
                                              m_moduleShortName + "/text" + GL_FORMAT_TEXT).arg(m_typeModule.toLower()));

    if (QFile::exists(t_pathToXmlFile))
    {
        QFile::remove(t_pathToXmlFile);
    }
    createEmptyXML(t_pathToXmlFile);
    for (int i = 0; i < m_bookPath.size(); i++)
    {
        readBook(i);
    }
    endXML(t_pathToXmlFile);
    return false;
}
Example #3
0
int main( )
{
	 Book b[NUM];                 /*定义实参一维数组存储图书记录*/
     int choice,n=0;              /*n赋值0*/
	 printf("Input information from a file or keyboard? [1(file)/2(keyboard)]\n"); /*询问信息输入方式*/
	 scanf("%d",&choice);         /*读入选择*/
	 if (choice == 1)
		n=readFile(b);            /*读取文件,记录条数返回赋值给n*/
	 else if (choice == 2)
	 {
		 printf("\nInput an integer to indicate how many pieces of information to be input: \n");
		 scanf("%d",&n);
		 n=readBook(b,n);
	 }
	 else
     {
		 printf("choice error!\n");      /*输入非1、2数字按默认方式执行,从文件读取*/
         printf("Execute by default:\n");
     }
	 if (!n)                     /*如果原来的文件为空*/
	 {
         // printf("Target file is empty!\n");
		 n=createFile(b);        /*则首先要建立文件,从键盘上读入一系列记录存于文件*/
	 }	 	 
	 do
	 {
	     menu();                 /*显示菜单*/
	     printf("Please input your choice: ");
	     scanf("%d",&choice);
	     if (choice>=0 && choice<=5)
			n=runMain(b,n,choice);    /*通过调用此函数进行一级功能项的选择执行*/
	     else 
		    printf("Error input,please input your choice again!\n");
	} while (choice);
	sortBook(b,n,1);                  /*存入文件前按ISBN由小到大排序*/
	saveFile(b,n);                    /*将结果存入文件*/
    return 0;
}
Example #4
0
// hàm menu
void Menu(LIST l)
{
	int n = readBook(l); // số node được tạo sau khi đọc file dữ liệu

	int menu; // chọn chức năng menu
	printf("\n Nhap:\n\n  - 1: de them sach.");
	printf("\n  - 2: de xoa sach.");
	printf("\n  - 3: de xuat danh sach theo thu tu nam xuat ban tang dan.");
	printf("\n  - 4: de tim kiem sach theo ID.");
	printf("\n  - 5: de dem so luong sach trong thu vien cua cung mot tac gia.");
	printf("\n  - 6: de xuat danh sach nhung quyen xuat ban cung mot nam cua mot nha xuat ban.\n Nhap: ");
	scanf("%d", &menu);

	switch(menu)
	{
	case 1: // thêm sách
		{
			Input(l); // thêm sách
			saveBook(l, n); // ghi tiếp file 
			contApp(l); // gọi hàm sử dụng tiếp
			break;
		}
	case 2: // xóa sách
		{   
			delNode(l); // xóa sách
			saveBook2(l); // ghi lại từ đầu
			contApp(l); // gọi hàm sử dụng tiếp
			break;
		}
	case 3: // xuất mảng theo thứ tự
		{
			sortYear(l); // gọi hàm xuất mảng sau khi sắp xếp
			contApp(l); // gọi hàm sử dụng tiếp
			break;
		}
	case 4: // tìm sách theo ID
		{
			lookID(l); // gọi hàm tìm sách theo ID
			contApp(l); // gọi hàm sử dụng tiếp
			break;
		}
	case 5: // đếm số lượng sách của 1 tác giả
		{
			lookAuthor(l); // gọi hàm đếm số sách theo tên tác giả
			contApp(l); // gọi hàm sử dụng tiếp
			break;
		}
	case 6: // xuất danh sách những quyển xuất bản cùng năm YYYY cùng một nhà xuất bản
		{
			lookBook(l); // gọi hàm tìm sách theo yêu cầu trên
			contApp(l); // gọi hàm sử dụng tiếp
			break;
		}
		// trường hợp người dùng nhập 1 số khác 1, 2, 3, 4, 5, 6 thì cho người dùng nhập lại
	default:
		{
			delAll(l.pHead); // xóa danh sách cũ để khi đọc lại file (khi gọi lại hàm menu) sẽ không ghi tiếp vào danh sách cũ
			printf("\n\n\n     BAN DA NHAP SAI HUONG DAN. XIN VUI LONG NHAP LAI: ");
			Menu(l);
		}
	}
}