#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<windows.h>
void clear(){
system("cls");
}
void gotoxy(int x,int y){
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_H ANDLE),coord);
}
void enqueue();
void dequeue();
void display();
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++
struct node
{
int bookid; double bookprice;
char booktitle[30]; char bookauthor[30];
struct node *link;
}*start=NULL, *end=NULL, *new,*temp,*e;
typedef struct node N;
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++
main()
{
int ch;
do
{
clear();
gotoxy(25,7);
printf("***** ABC Booksellers *****");
gotoxy(26,8);
printf("Please select your choice:");
gotoxy(29,10);
printf("1.Enqueue / Append ");
gotoxy(29,11);
printf("2.Dequeue / Serve ");
gotoxy(29,12);
printf("3.Display");
gotoxy(29,13);
printf("4.Exit");
gotoxy(28,15);
printf("Enter your choice : ");
scanf("%d",&ch);
gotoxy(25,17);
printf("\n");
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++
switch(ch)
{
case 1:
clear();
enqueue();
break;
case 2:
clear();
break;
case 3:
clear();
break;
case 4:
clear();
gotoxy(32,10);
printf("THANK YOU !!!");
Sleep(3000);
clear();
printf("\n\t\t");
exit(0);
break;
default:
gotoxy(32,18);
printf("Invalid choice\n\n");
break;
}
}
while(ch<=3);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++
void enqueue()
{
new=(N*)malloc(sizeof(N));
gotoxy(23,3);
printf("Note: Please refrain from using spaces");
gotoxy(19,4);
printf("Instead of Spaces please use a underscore.. ^_^");
gotoxy(24,7);
printf("***** Enter Book Details *****");
gotoxy(26,9);
printf("Enter Book ID: ");
scanf("%d",&new->bookid);
gotoxy(26,10);
printf("Enter Book TITLE: ");
scanf("%s",&new->booktitle);
gotoxy(26,11);
printf("Enter Book AUTHOR: ");
scanf("%s",&new->bookauthor);
gotoxy(26,12);
printf("Enter Book Price: P");
scanf("%lf",&new->bookprice);
gotoxy(14,14);
printf("Thank you, Book has been successfully appended");
Sleep(1500);
new->link=NULL;
if(end==NULL)
start=new;
else
{
e=end;
while(e->link!=NULL)
e=e->link;
e->link=new;
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++
void dequeue()
{
if(start==NULL)
printf("\nStack is empty\n");
else if(start->link==NULL)
{
gotoxy(28,7);
printf("***** Book Deleted *****");
gotoxy(24,9);
printf("Book ID: %d\n",start->bookid);
gotoxy(24,10);
printf("Book Title: %s",start->booktitle);
gotoxy(24,11);
printf("Book Author: %s",start->bookauthor);
gotoxy(24,12);
printf("Book Price: P%.2lf",start->bookprice);
gotoxy(24,13);
printf("Book has been successfully served!");
Sleep(1500);
free(start);
start=NULL;
}
else
{
e=end;
while(e->link!=NULL)
{
temp=e;
e=e->link;
}
gotoxy(28,7);
printf("***** Book Deleted *****");
gotoxy(24,9);
printf("Book ID: %d\n",end->bookid);
gotoxy(24,10);
printf("Book Title: %s",end->booktitle);
gotoxy(24,11);
printf("Book Author: %s",end->bookauthor);
gotoxy(24,12);
printf("Book Price: P%.2lf",end->bookprice);
gotoxy(24,13);
printf("Book has been successfully served!");
Sleep(1500);
temp->link=NULL;
free(e);
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++
void display()
{
if(start==NULL)
printf("\nStack is empty\n");
else
{
gotoxy(28,7);
printf("***** Stored Books *****");
e=start;
while(e!=NULL)
{
printf("\n\t\t Book ID: %d",e->bookid);
printf("\n\t\t Book Title: %s",e->booktitle);
printf("\n\t\t Book Author: %s",e->bookauthor);
printf("\n\t\t Book Price: P%.2lf\n\n",e->bookprice);
Sleep(3000);
e=e->link;
}
printf("\n");
}
}
im really getting confused olready cant seem to serve data stored.. please help me.. really need it..