Gilang official site

NOngkrong yuk sambil cuap-cuap n belajar IT bareng2

Subscribe
Add to Technorati Favourites
Add to del.icio.us
Wednesday, December 3, 2008
Posted by Gilang kurniaji

Anjrit posting lagi :p

indonesia tanah air beta

Tuesday, September 2, 2008

application of linked list in c "small library"

Posted by Gilang kurniaji

This program is an application of linked list in C language
This program was written in microsoft visual C
In this program we can add data to the list,delete some data and searching

This is the code :
#include
#include
#include
#include
#include
#include


struct node
{
char code[20];
char title[40];
char writer[40];
char info[40];
int stock;
node *next;
};

node *HEAD = NULL;
char option,pil,pin,oyi;
char code[40],comp[40];;


//************************************insert at front************************************

void add_node_at_end()
{
node *temp, *temp2,*help;
char comp[40];
char comp1[40];

temp = new node;
system("color 04");
system("cls");
printf("\nInsert book code :");
gets(temp->code);
strcpy(comp,temp->code);
// fflush(stdin);


printf("Insert book title[less 40 character]:");
gets(temp->title);
strupr(temp->title);
// fflush(stdin);


printf("Insert book writer[less 40 character]:");
gets(temp->writer);
// fflush(stdin);


printf("Insert book information[less 40 character]:");
gets(temp->info);
strupr(temp->info);
// fflush(stdin);


printf("Insert book stock :");
cin>>temp->stock;

temp->next = NULL;


if (HEAD == NULL)
{
HEAD = temp;
}
else
{
temp2 = HEAD;
help=NULL;
strcpy(comp1,temp2->code);
while (temp2->next != NULL&&(strcmp(comp1,comp)<0))
{
help=temp2;
temp2 = temp2->next;
strcpy(comp1,temp2->code);
}
if(help==NULL)
{
temp->next=temp2;
HEAD=temp;
}
else
{
temp->next=temp2;
help->next=temp;
}
}
printf("%s is added to the list\n",&temp->title);
}


//**************************************DELete front*************************************



void delete_start_node()
{
node *temp;
temp = HEAD;
HEAD = HEAD->next;
delete temp;
}


void delete_end_node()
{
node *temp1, *temp2;


if (HEAD == NULL)
cout << "daftar masih kosong..." << endl;
else
{
temp1 = HEAD;
if (temp1->next == NULL)
{
delete temp1;
HEAD = NULL;
}
else
{
while (temp1->next != NULL)
{
temp2 = temp1;
temp1 = temp1->next;
}
delete temp1;
temp2->next = NULL;
}
}
}


//**************************deleteSpecific*****************************//

void delete_spec()
{
char code[20],coda[40];
node *temp,*del;
temp=HEAD;
int type,x;

printf("Book code :");
gets(code);
printf("Title :");
gets(comp);
strupr(comp);

if(temp==NULL)
puts("The list is empty");
else
{
while(temp!=NULL)
{
strcpy(coda,temp->title);
x=strcmp(code,temp->code);

if(strstr (coda,comp)&&x==0)
{
type = 1;
puts("========book found=================");
cout << " TITLE : " << temp->title< cout << " WRITER: " << temp->writer< cout << " INFORMATION:"<info< cout << " STOCK : " << temp->stock< cout< puts("===================================");
printf("Delete this book list (Y/N) ?");
oyi=toupper(getche());
if(oyi=='Y')
{
if(temp->next==NULL)
{
del=temp;
temp=NULL;
printf("\n%s is being deleted\n",del->title);
delete del;
}
else if(temp->next!=NULL)
{
del = temp;
temp = temp->next;
del->next=NULL;
printf("\n%s is being deleted\n",del->title);
delete del;
}

}

}
temp=temp->next;
}
puts("");
if(type!=1)
{
puts("can not find the book ");
}
}
}






//************************display*************************************//

void display_list()
{
int num=1;
node *temp;
temp = HEAD;
cout << endl;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp != NULL )
{
// Display details for what temp points to
cout << num << ". ";
cout << " CODE : " << temp->code < cout << " TITLE : " << temp->title< cout << " WRITER :" << temp->writer< cout << " INFORMATION:"<info< cout << " STOCK :"<stock< cout< puts("===================================");
temp = temp->next;

num++;
}
puts("");
}

}


//=============================hapusALL============================
void Clear()
{
node *Temp, *Clear;
Temp = HEAD;
while(Temp!=NULL)
{
Clear = Temp;
Temp = Temp->next;
delete Clear;

}
}




//*********************************searchTitle**********************************************************//

void search_title()
{
int Y;
node *temp;
temp = HEAD;
cout << endl;
printf("insert the book title :");
gets(code);
strupr(code);
fflush(stdin);

if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp != NULL )
{
strcpy(comp,temp->title);
if(strstr(comp,code))
{
Y = 1;
// Display details for what temp points to

puts(">>>>>>>>The book was found<<<<<<<<<<");
cout << " TITLE : " << temp->title< cout << " CODE :"<code< cout << " WRITER :" << temp->writer< cout << " INFORMATION:"<info< cout << " STOCK :"<stock< cout< puts("====================================");
if(temp->stock>0)
{
printf("lend a book (y/n) :");
cin>>pin;
if(pin =='Y'||pin == 'y')
{
temp->stock--;
puts("Success");
}
}
}
temp = temp->next;
}
puts("");

if (Y != 1)
{
cout << " can't find the book or the title didn't correct..." < }
}
}


//**********************************searchWriter *********************************//

void search_writer()
{
int Y;
node *temp;
temp = HEAD;
cout << endl;
printf("insert the book writer :");
gets(code);
fflush(stdin);

if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp != NULL )
{
strcpy(comp,temp->writer);
if(strstr(comp,code))
{
Y = 1;
// Display details for what temp points to
puts(">>>>>>>The book was found<<<<<<<<<<");
cout << " TITLE : " << temp->title< cout << " WRITER: " << temp->writer< cout << " INFORMATION:"<info< cout << " STOCK : " << temp->stock< cout< puts("===================================");
if(temp->stock>0)
{
printf("lend a book (y/n) :");
cin>>pin;
if(pin =='Y'||pin == 'y')
{
temp->stock--;
puts("Success");
}
}
}
temp = temp->next;
}
puts("");

if (Y != 1)
{
cout << " can't find the code..." < }
}
}


//**********************************bookStock*************************************************************//

void add_stock()
{
char code[20],coda[40];
node *temp;//*help;
temp=HEAD;
int type,x,stck;

printf("Book code :");
gets(code);
printf("Title :");
gets(comp);
strupr(comp);

if(temp==NULL)
puts("The list is empty");
else
{
while(temp!=NULL)
{
strcpy(coda,temp->title);
x=strcmp(code,temp->code);

if(strstr (coda,comp)&&x==0)
{
type = 1;
puts("========book found=================");
cout << " TITLE : " << temp->title< cout << " WRITER: " << temp->writer< cout << " INFORMATION:"<info< cout << " STOCK : " << temp->stock< cout< puts("===================================");
printf("ADD book stock (Y/N) ?");
oyi=toupper(getche());
if(oyi=='Y')
{
printf("\nInsert book stock :");
cin>>stck;
temp->stock=temp->stock+stck;
puts("insert complete");
printf("The stock of %s now become %d \n",temp->title,temp->stock);
}

}
temp=temp->next;
}
puts("");
if(type!=1)
{
puts("can not find the book ");
}
}
}




//************************************** SAVE ***************************************************************//


void save()
{
node *temp;
temp=HEAD;
ofstream file_code("code.txt",ios::trunc);
ofstream file_title("title.txt",ios::trunc);
ofstream file_writer("writer.txt",ios::trunc);
ofstream file_info("info.txt",ios::trunc);
ofstream file_stock("stock.txt",ios::trunc);
if(temp==NULL)
{
puts("LIST IS EMPTY");
}
else
{
while(temp!=NULL)
{
file_code <code < file_title <title < file_writer <writer < file_info <info < file_stock <stock< temp=temp->next;
}
}
file_code.close();
file_title.close();
file_writer.close();
file_info.close();
file_stock.close();
puts("");
puts("saving complete");
}



//************************************** LOad ****************************************************************//


void load(){
node *temp,*temp2;
const int maks = 40;
char help1[maks];
char help2[maks];
char help[maks];
char help3[maks];
char help4[2];
int data;


ifstream in_code("code.txt");
ifstream in_title("title.txt");
ifstream in_writer("writer.txt");
ifstream in_info("info.txt");
ifstream in_stock("stock.txt");

while(! in_code.eof() || ! in_title.eof() || ! in_writer.eof() || ! in_info.eof())
{
in_code.getline(help,maks);
temp= new node;
strcpy(temp->code,help);

in_title.getline(help1,maks);
strcpy(temp->title,help1);

in_writer.getline(help2,maks);
strcpy(temp->writer,help2);

in_info.getline(help3,maks);
strcpy(temp->info,help3);

in_stock.getline(help4,maks);
data = atoi (help4);
temp->stock= data;


temp->next=NULL;

if (HEAD == NULL)
{
HEAD = temp;
}
else
{
temp2 = HEAD;

while (temp2->next != NULL)
{
temp2 = temp2->next;
}
temp2->next = temp;
}
}

delete_end_node();
in_code.close();
in_title.close();
in_writer.close();
in_info.close();
in_stock.close();
puts("load complete");

}







//*************************************** MAIN *************************************************************//

void main()
{
char lanjut;
HEAD = NULL;
char login[20]="GILANG";
char word[20]="g13g13";
char in[20];
char pass[20];
int x,y;

puts("LOAD previous SAVE (Y/N):");
pil=toupper(getch());
if(pil=='Y')
{
load();
goto LOGIN;
}
else
goto LOGIN;

LOGIN :

system("cls");
system("color B1");
cout< cout< puts("\n============================");
puts("=>>>>>>LOGIN MENU<<<<<<<<<<=");
puts("============================");
puts("=F.OFFICER =");
puts("=G.GUEST =");
puts("============================");
oyi=toupper(getch());
if(oyi=='F'||oyi=='G'||oyi=='0')
{

if(oyi=='F')
{
printf("NAME :");
gets(in);
strupr(in);
printf("PASSWORD:");
gets(pass);
x=strcmp(login,in);
y=strcmp(pass,word);
if(x==0&&y==0)
{
system("color F3");
system("cls");
puts("\nLOGIN SUCCESS");
goto START;
}
else
puts("\nLOGIN IS UNSUCCESSFULL");
getch();
}
else if(oyi=='G')
{
puts("WELCOME");
goto START_guest;
}
else if(oyi=='0')
{
puts("\n=====================================");
puts("= Thank you for using this program =");
puts("= Keep the world save =");
puts("= Fighting over poverty =");
puts("=====================================");
puts("=:-o :-o :-O :-O :-O :-O :-O :-O :-O=");
puts("=====================================");
goto END;
}

}goto LOGIN;






START_1st:
system("cls");
system("color 5E");
puts("\n=========================");
puts("=MAIN MENU : =");
puts("=========================");
puts("=0. Exit the program. =");
puts("=1. Add new data to list=");
puts("=9. About. =");
puts("=========================");
printf("Select the number >> ");
option = getche();
if(option == '0' || option == '1' || option == '9'||option == '8')
{
if(option == '0')
{

puts("\n=====================================");
puts("= Thank you for using this program =");
puts("= Keep the world save =");
puts("= Fighting over poverty =");
puts("=====================================");
puts("=:-o :-o :-O :-O :-O :-O :-O :-O :-O=");
puts("=====================================");
goto END;
}
goto Option;
}
goto START_1st;

START_guest:
system("cls");
system("color 5a");
puts("=========================");
puts("= MAIN MENU ==");
puts("=========================");
puts("=0.Exit the program. =");
puts("=1.Search book by title =");
puts("=2.Search book by writer=");
puts("=L.go to login menu. =");
puts("=A.About. =");
puts("=========================");
printf("Select the number >>");
pin=toupper(getch());
if(pin =='0'||pin == '1'||pin =='2'||pin=='A'||pin=='L')
{
if(pin == '0')
{
puts("\n=====================================");
puts("= Thank you for using this program =");
puts("= Keep the world save =");
puts("= Fighting over poverty =");
puts("=====================================");
puts("=:-o :-o :-O :-O :-O :-O :-O :-O :-O=");
puts("=====================================");
goto END;
}
switch (pin)
{
case '1' :

puts("\n******************************");
puts("*>>>>>>SEARCHING BOOK<<<<<<<<*");
puts("******************************");
search_title();
save();
puts("Press any key to continue...");
getch();
break;

case '2' :

puts("\n******************************");
puts("*>>>>>>SEARCHING BOOK<<<<<<<<*");
puts("******************************");
search_writer();
puts("Press any key to continue...");
save();
getch();
break;

case 'L' :
goto LOGIN;

case 'A' :
system("color 2c");
system("cls");
puts("\n=========================");
puts("=>THIS SOFTWARE IS FREE<=");
puts("=========================");
puts("=By GilaQ software corp.=");
puts("=========================");
puts("=Dedicated to : =");
puts("=========================");
puts("=-MY beloved family =");
puts("=-All of my best friend =");
puts("=========================");
puts("=>>>>>>>>THANK's<<<<<<<<=");
puts("=========================");
puts("");
puts("Press any key to continue...");
getch();
break;


}
}
goto START_guest;



START:
if(HEAD == NULL)
goto START_1st;
system("cls");
system("color 3f");
puts("\n==========================================");
puts("= Library MENU =");
puts("==========================================");
puts("=0. Exit the program. =");
puts("=1. Add new data to list. =");
puts("=2. Delete the start node from the list. =");
puts("=3. Delete the end node from the list. =");
puts("=4. Display book list =");
puts("=5. Search book by title =");
puts("=6. Search book by writer =");
puts("=7. add new book stock =");
// puts("=8. delete specific list =");
puts("=L. go to Login Menu =");
puts("=S. Save =");
puts("=A. About. =");
puts("==========================================");
printf("= >> ");
option=toupper(getche());


Option:
switch (option)
{
case '1' :
add_node_at_end();
break;

case '2' :
do
{
printf("\nAre you sure? [Y/N] : ");
lanjut = toupper(getche());
if(lanjut == 'N') goto START;
puts("");
}
while(lanjut != 'Y' && lanjut != 'N');

puts("");
delete_start_node();
puts("Press any key to continue...");
getch();
break;

case '3' :
do
{
printf("\nAre you sure? [Y/N] : ");
lanjut = toupper(getche());
if(lanjut == 'N') goto START;
puts("");
}
while(lanjut != 'Y' && lanjut != 'N');

delete_end_node();
puts("Press any key to continue...");
getch();
break;

case '4' :
system("cls");
system("color 5d");
display_list();
puts("Press any key to continue...");
getch();
break;


case '5' :
system("cls");
system("color a2");
puts("\n******************************");
puts("*>>>>>>SEARCHING BOOK<<<<<<<<*");
puts("******************************");
search_title();
save();
puts("Press any key to continue...");
getch();
break;

case '6' :
system("cls");
system("color a2");
puts("\n******************************");
puts("*>>>>>>SEARCHING BOOK<<<<<<<<*");
puts("******************************");
search_writer();
save();
puts("Press any key to continue...");
getch();
break;

case '7' :
system("cls");
system("color b4");
puts("\n******************************");
puts("*>>>>>>>>>ADD STOCK<<<<<<<<<<<*");
puts("*******************************");
add_stock();
save();
puts("Press any key to continue...");
getch();
break;

case '8' :
system("color 45");
system("cls");
puts("\n*****************************");
puts("*>>>DELETE SPECIFIC LIST<<<<<<*");
puts("*******************************");
delete_spec();
puts("Press any key to continue...");
getch();
break;


case 'S' :

puts("\n*****************************");
puts("*>>>>>>SAVING LIST <<<<<<<<<*");
puts("*****************************");
save();
puts("Press any key to continue...");
getch();
break;


case 'A' :
system("cls");
system("color 3a");
puts("\n=========================");
puts("=>THIS SOFTWARE IS FREE<=");
puts("=========================");
puts("=By GilaQ software corp.=");
puts("=========================");
puts("=Dedicated to : =");
puts("=========================");
puts("=-MY beloved family =");
puts("=-All of my best friend =");
puts("=========================");
puts("=>>>>>>>>THANK's<<<<<<<<=");
puts("=========================");
puts("Press any key to continue...");
getch();
break;

case 'L':
goto LOGIN;


}

if(option != '0')
{
goto START;
}

if (HEAD != NULL)
{
puts("\nAny unsaved data will be lost");
do
{
printf("continue? [Y/N]: ");
lanjut = toupper(getche());
if(lanjut == 'N') goto START;
puts("");
}
while(lanjut != 'Y' && lanjut != 'N');
}
system("cls");
system("color 4c");

puts("thank you ");
puts("=====================================");
puts("= Thank you for using this program =");
puts("= Save the BluE pRinT =");
puts("= Fighting over poverty =");
puts("=====================================");
puts("=:-o :-o :-O :-O :-O :-O :-O :-O :-O=");
puts("=====================================");
END:
Clear();
getche();

}


This program may be need modification to make better...

thank you...

give suggestion for me,please

Sunday, August 10, 2008

The Beginning

Posted by Gilang kurniaji

finally i can create the new blog...
In this site i want to share about my idea and opinion...
Enjoy it