- 分享
- 0
- 人气
- 0
- 主题
- 9
- 帖子
- 514
- UID
- 55545
- 积分
- 4160
- 阅读权限
- 22
- 注册时间
- 2006-12-24
- 最后登录
- 2017-10-17
- 在线时间
- 4527 小时
|
谢谢各位上次帮我解决assessment1的问题。。。
现在希望大家能帮我这更难的assessment2啊,快疯了!
1.Write a C program to read a list of books from a file and create a linked list to store them. The purpose of this program is to keep track of the books kept in a shelf. The shelf is a three-tier shelf and each tier can store up to 4500 pages maximum. The books are kept in alphabetical order (ascending).
Your program should provide the following functions:-
a. Print the detail of all books.
b. Insert new book to the shelf in alphabetical order. However, if the first-tier is full, you must put the book into the second tier.
c. Remove a book from the list.
d. Search for a book using the book title, return the tier where the book is placed.
e. Generate warning if the shelf is 75% full.
f. Store all the books information back into a file for future use.
这是我的没完成的code,因为真的不会了啊!
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
char data,data1;
int data2;
struct node* link;
}NODE;
NODE* Insert_Book(NODE* bList , NODE* bPre , NODE* bCur , char bName,char bAuthor,int bPages){
NODE* bNew = (NODE*)malloc(sizeof(NODE));
bNew->data = bName;
bNew->data1 = bAuthor;
bNew->data2 = bPages;
bNew->link = NULL;
if(bPre == NULL){
bNew->link = bList;
bList = bNew;
}
else{
bNew->link = bCur;
bPre->link = bNew;
}
return bList;
}
int search_Book(NODE** pCur,NODE** pPre,NODE* pList,int book){
*pCur = pList;
*pPre = NULL;
while(*pCur != NULL){
if((*pCur)->data == book){
return 1; }
*pPre = *pCur;
*pCur = (*pCur)->link ;
}return 0;
}
NODE* delete_Book(NODE* pList){
NODE* pCur = pList;
pList = pList->link;
free(pCur);
return pList;
}
int main(){
NODE* bList = NULL;
NODE* bCur = NULL;
NODE* bPre = NULL;
char Name;
char Author;
int Pages;
int choice;
do{
printf("*************************\n");
printf("*\tMAIN MENU\t*\n");
printf("*************************\n");
printf("1.Insert a new book.\n");
printf("2.Remove a book.\n");
printf("3.Search for a book.\n");
printf("4.List all the books.\n");
printf("5.Exit the process.\n");
do{
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice){
case 1:
printf("Enter the book name : ");
scanf("%c",&Name);
printf("Enter the author name of the book : ");
fflush(stdin);
scanf("%c",&Author);
printf("Enter the pages of the book : ");
scanf("%d",&Pages);
bList = Insert_Book(bList,bPre,bCur,Name,Author,Pages);
bCur = bList;
while(bCur!=NULL){
printf("%c %c %d\n",bCur->data,bCur->data1,bCur->data2);
bCur = bCur->link;
}system("PAUSE");
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
system("cls");
printf("\nThank you\n");
system("PAUSE");
break;
default:
printf("\n\n\n>>>>>you must type in 1,2,3,4,or 5!<<<<<\n\n\n");
system("PAUSE");
break;
}
}while(choice != 1 && 2 && choice != 3 && choice != 4 && choice != 5);
}while(choice != 5);
}
请帮帮我。。。
这是我的probem statement.
1.我要怎样将我所key in 的book name,author 换成string由function放进main里的case 1(Insert function)。
资料:Book Name ---string ; Author ---string ; Page ---int.
2.要怎样分3tier。
3怎样做ascending a-z。
4file《不懂啊~
5还有很多。。。
有好心人的话,求求你帮我解决吧!
[ 本帖最后由 凯茹 于 2009-7-26 09:04 PM 编辑 ] |
|