BookStack

gavindu123 0 Tallied Votes 184 Views Share

This program was created by Gavindu Nuwan Dileepa and using this program you can add data to the stack , delete data and also you can view data from it... for more information contact gavindu123@gmail.com.. thanks

/* This program created by Gavindu Nuwan Dileepa .... gavindu123@gmail.com .. for my
DCS project... singapore informatics*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define NULL0


void exit(void);

/* ----- GLOBLE VARIABLES ------- */

char name[25];
int press;


/*--------- BOOK STRUCTURE --------------------*/

struct Books
{
	int book_id;
	char title[25];
	char author[25];
	float price;
	char publisher[25];
	char content[50];
	struct Books *Link;
};

typedef struct Books *StackPointer;

/*-------------- puse methode ----------------*/

 void push(StackPointer &Top,int book_id1,char titl[],char aut[],float
 price,char pub[])
{

 StackPointer p;
 p=(StackPointer)malloc(sizeof(struct Books));
 p->book_id=book_id1;
 for(int t1=0;t1<=24;t1++)
	p->title[t1]=titl[t1];

 for(int a1=0;a1<=24;a1++)
	p->author[a1]=aut[a1];
 p->price=price;

 for (int p1=0;p1<=24;p1++)
	p->publisher[p1]=pub[p1];
 p->Link = Top;
 Top = p;

 
 }

/* -------------------- pop methode ----------------- */
	void pop(StackPointer &Top)
 {
	int item1;
	char item2[25];
	char item3[25];
	float item4;
	char item5[25];
   StackPointer Temp;
	gotoxy(29,14);
	if(Top==NULL)
	 printf("Stack is empty");
	else
 {
	item1=Top->book_id;
	item2[25]=Top->title[25];
	item3[25]=Top->author[25];
	item4=Top->price;
	item5[25]=Top->publisher[25];
   Temp = Top;
	Top = Top->Link;
	free(Temp);
		gotoxy(22,19);printf("Your Record Has Been Deleted");
 }

}
void main()
{

	StackPointer Top;
	int book_id;
	char titl[25];
	char aut[25];
	char pub[25];
   int select;
	int opt;
	int bi;
	float price;
	Top=NULL;

/* ------- welcome screen one --------- */

	gotoxy(8,22);printf("ENTER YOUR NAME :");
	gotoxy(26,22);scanf("%s",&name);

/* ---------- welcome screen tow ------- */
	clrscr();
	gotoxy(13,12);printf(": -- Welcome to the A B C Booksellers company -- :");
	getch();


	do{
/* ---------- starting main program ----------- */
	clrscr();
	gotoxy(20,22);printf("Created by :- Gavindu Nuwan Dileepa");
	gotoxy(24,0);printf("**** A B C Booksellers ****\n");
	gotoxy(28,4);printf("Main Menu\n");
	gotoxy(26,5);printf("*************\n");
	gotoxy(25,8);printf("1.Add Books\n");
	gotoxy(25,10);printf("2.Delete Books\n");
	gotoxy(25,12);printf("3.Book Details\n");
	gotoxy(25,14);printf("4.Exit\n");
	gotoxy(25,17);printf("----------------------------\n");
	gotoxy(25,18);printf("Enter your choice :");
	gotoxy(25,19);printf("----------------------------\n");
	gotoxy(45,18);scanf("%i",&select);
	clrscr();

  switch(select)
	{
/* ----------start of menu screens ------------ */
	case 1:
	gotoxy(25,0);printf("**** A B C Booksellers ****");
	gotoxy(28,4);printf("Add Books");
	gotoxy(25,5);printf("***************");
	gotoxy(25,7);printf("Book ID :");
	gotoxy(35,7);scanf("%i",&book_id);
	fflush(stdin);
	gotoxy(25,9);printf("Book Title :");
	gotoxy(38,9); fflush(stdin);gets(titl);
	gotoxy(25,11);printf("Book Author:\n");
	gotoxy(38,11); fflush(stdin);gets(aut);
	gotoxy(25,13);printf("Book Price :\n");
	gotoxy(38,13);scanf("%f",&price);
	gotoxy(25,15);printf("Book Publisher :\n");
	gotoxy(42,15); fflush(stdin);gets(pub);
	fflush(stdin);
	gotoxy(12,17);printf("Do you want to save Press [1] For no Press [2]:\n");
	gotoxy(60,17);scanf("%i",&opt);
	fflush(stdin);

  if (opt==1)

  {
/* -------------- calling push methode ------------- */

	push(Top,book_id,titl,aut,price,pub);
	gotoxy(25,20);printf("You Record Has Been Saved");

  }

  else

  {
	if(opt==2)
	 gotoxy(25,20);printf("You Record Has Not Been Saved");
  }
  break;

	case 2:
		gotoxy(25,0);printf("**** A B C Booksellers ****");
		gotoxy(28,4);printf("Delete Books\n");
		gotoxy(25,5);printf("*****************");
		gotoxy(12,15);printf("For Delete Records [1] For Exit Program [2] :\n");
		gotoxy(58,15);scanf("%i",&opt);
		fflush(stdin);
		if (opt==1)
		{
		 clrscr();
		 gotoxy(25,0);printf("**** A B C Booksellers ****");
		 gotoxy(28,4);printf("Delete Books\n");
		 gotoxy(25,5);printf("*****************");
		 gotoxy(23,8);printf("Enter book id :");
		 gotoxy(39,8);scanf("%i",&bi);
		 int key;
		 key=bi;
		 StackPointer Here;
		 Here=Top;
		 while(Here!=NULL)
		 {
			if(Here->book_id==key)
				{
					clrscr(); /*------ RECALING THE SEARCH FUNCTION ----------- */
					gotoxy(25,0);printf("**** A B C Booksellers ****");
					gotoxy(28,4);printf("Delete Books\n");
					gotoxy(25,5);printf("****************");
					gotoxy(22,8);printf("book Title is : %s\n",Here->title);
					gotoxy(22,10);printf("book Author is: %s\n",Here->author);
					gotoxy(22,12);printf("book Price is : %.2f\n",Here->price);
					gotoxy(22,14);printf("book Publicher is: %s\n",Here->publisher);
					gotoxy(22,16);printf("[1] For delete [2] For exit :");
					gotoxy(52,16);scanf("%i",&press);
					if(press==1)
					{
					  pop(Top);
					}
					else
					{
						if(press==2)
						gotoxy(22,19);
						printf("Exit program");
					}
				}Here=Here->Link;
			}

		}
		else
		{
			if(opt==2)
			gotoxy(21,19);
			printf("Exit program");
		}

  break;

  case 3:
  gotoxy(25,0);printf("**** A B C Booksellers ****\n");
  gotoxy(28,4);printf("Book Details\n");
  gotoxy(25,5);printf("*****************");
  gotoxy(10,22);printf("[1] for Book Details [2] for exit program:\n");
  gotoxy(53,22);scanf("%i",&opt);
  fflush(stdin);

	if (opt==1)
	{
/* -------- searching nodes by using book_id -------------*/

		gotoxy(23,8);printf("Enter book id :");
		gotoxy(39,8);scanf("%i",&bi);
		int key;
		key=bi;
		StackPointer Here;
		Here=Top;
		while(Here!=NULL)
		{
			if(Here->book_id==key)
			{
				gotoxy(23,10);printf("book Title is : %s\n",Here->title);
				gotoxy(23,12);printf("book Author is: %s\n",Here->author);
				gotoxy(23,14);printf("book Price is : %.2f\n",Here->price);
				gotoxy(23,16);printf("book Publicher is: %s\n",Here->publisher);
				gotoxy(23,18);printf("PRESS ENTER TO EXIT :");
			}
/* ----------- printing the node information ----------------- */
			Here=Here->Link;

		}
	}

	else

	{
		if(opt==2)
			gotoxy(23,18);printf("Error Program Terminated");
	}

  break;

  case 4:
  exit();
  break;

  }
  getch();
 }while(select<4);
}

	/*-------------- EXIT FUNCTION -----------*/
	void exit(void)
	{
	clrscr();
	gotoxy(18,10);printf(":--- Thank you and have a nice day ---:");
	gotoxy(25,12);printf("24 HOUR CUSTOMER SERVICS");
	gotoxy(25,13);printf("ONLY FROM ABC BOOKSELLERS");
	gotoxy(25,16);printf("------------------------");
	gotoxy(25,17);printf("YOU ARE WELCOME %s",&name);
	gotoxy(25,18);printf("------------------------");
	}


/* Gavindu Nuwan Dilepa... gavindu123@gmail.com...gavindu321@yahoo.com*/
Shark7 0 Newbie Poster

when i try to compile the program it says that for exemple gotoxy and clrscr have not been declared...does anyone know why?
and it also says that function main must return a int...can anyone help me?
thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.