#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
typedef struct Lnode {
char name[65];
char loacation[41];
double price;
Lnode* next;
}Lnode;
void menu(void);
Lnode* creatlist(void);
void addnode(Lnode * head);
void shownode(Lnode* head);
int main(int argc, char* argv[]) {
printf("Welcome to use The Tourist Attraction information system by OldWifi\n");
Lnode* Head = creatlist();
char choose;
do {
menu();
scanf(" %c", &choose);
switch (choose)
{
case '1' :
addnode(Head);
break;
case '2':
shownode(Head);
break;
case '3':
printf("3 Success!\n");
break;
case '4':
printf("4 Success!\n");
break;
case '5':
printf("5 Success!\n");
break;
case '0':
printf("0 Success!\n");
break;
default:
printf("Input error\n");
break;
}
} while (choose!= '0');
return 0;
}
void menu(void) {
printf("Enter a number to perform the opeartion\n");
printf("1.Input information\n");
printf("2.Show all information\n");
printf("3.Lookup information\n");
printf("4.Modify information\n");
printf("5.Delete information\n");
printf("0.Quit\n");
}
Lnode* creatlist(void) {
Lnode* head = (Lnode*)malloc(sizeof(Lnode));
if (!head) {
printf("Error ! no data\n");
return NULL;
}
else {
head->next = NULL;
printf("Data had loaded successfully!\n");
return head;
}
}
void addnode(Lnode* head) {
Lnode* spot = (Lnode*)malloc(sizeof(Lnode));
if (!spot) {
printf("insert error!");
}
printf("Enter a name of scenic spot : ");
scanf("%s", spot->name);
printf("Enter the location of scenic spot: ");
scanf("%s", spot->loacation);
printf("Enter the price for scenic spot: ");
scanf("%lf", &spot->price);
spot->next = head->next;
head->next = spot;
printf("%s Add successfully!\n", spot->name);
}
void shownode(Lnode* head) {
printf("Name Location Price\n");
Lnode* Pnode = head->next;
while (Pnode!=head) {
printf("%s %s %f\n", Pnode->name, Pnode->loacation, Pnode->price);
Pnode = Pnode->next;
}
}