• Announcements

    • Peraturan Umum, Sila baca !

      1) Perbincangan illegal , seperti download , provide link muat turun, lanun sebagainya ditegah dan akan dipadam tanpa notis. Sila ambil perhatian , sebarang perbincangan mengenai download men-download, sharing link yang berkait kepada illegal material: - akan dipadam serta merta - tiada kompromi, user akan diberi warn jika melakukan kesalahan sama Contoh related : - " aku tengah sedut ni.. sejam lagi siap.. " - " kat mana ko dload laju gile.. aku lagi 14 hari nk siap" 2) Spamming, double pos, smiley semata-mata adalah satu kesalahan besar, elakkan membuat susulan pos dibawah susulan sendiri. Warning tanpa notis akan diberikan. 3) Elakkan drama fanboyism , samada berkait dengan konsol, permainan pc dan sebagainya 4) Perbincangan private server tidak dibenarkan, namun multiplayer via hamachi group dibenarkan. 5) Cheat codes dibenarkan, tetapi tidak kepada [email protected] 6) Screenshot seeloknya bersaiz 640 x 480 ke bawah, sila gunakan code spoiler sekiranya tidak resize pic anda. 7) One line posting (susulan satu baris) tanpa menjawab persoalan dan tidak memberi apa-apa manfaat dikira sebagai SPAM. SILA GUNAKAN FUNGSI REPORT JIKA TERDAPAT USER/TOPIK YANG MELANGGAR PERATURAN DI ATAS. ____________________________________________________________ _______________________________ .::. Kegagalan mematuhi terma dan syarat boleh mengakibatkan posting anda di padam dan anda mendapat warn level secara percuma .::. ____________________________________________________________ _______________________________
Sign in to follow this  
Followers 0

Menu Menggunakan Struktur Data.

5 posts in this topic

Posted · Report post

Salam 1 Malaysia, coding ini berkenaan dengan menu masukkan data, hapuskan data, membuat carian data, dan paparkan data. Tetapi apabila coding diljalankan, pemilihan menu tidak boleh dibuat, coding ini hanya dapat paparkan menu sahaja. Saya tidak pasti masalahnya dimana. Minta jasa baik member-mamber tolong semakkan dan beritahu saya masalahnya di mana. terima kasih. :D

[CODE]
#include <iostream.h>
using namespace std;
struct abc
{ string name,ic,dte_b;
abc *next; //pointer next=point to next node.
};
void insert();
void remove();
void search();
void display();// declare operation of list
abc *head; //head is a pointer which will point to first node.

main()
{
int p;
char respond;
cout<<"________________________________________________"<<endl;
cout<<"\n\nCUSTOMER INFORMATION SYSTEM OF ABC COMPANY "<<endl;
cout<<"________________________________________________"<<endl;
cout<<"\n\nMENU"<<endl;;
cout<<"\n1) CUSTOMER DATA INPUT"<<endl;
cout<<"2) CUSTOMER DATA DELETE"<<endl;
cout<<"3) CUSTOMER DATA SEARCH"<<endl;
cout<<"4) CUSTOMER DATA DISPLAY"<<endl;
cout<<"5) EXIT "<<endl;
while(respond == 'Y' || respond == 'y')
{
cout<<"CHOICE : ";
cin>>p; //enter no. of menu chosen.

if (p==1)
{
cout<<"-----------------------------------"<<endl;
cout<<"CUSTOMER DATA INPUT"<<endl;
cout<<"-----------------------------------"<<endl;
insert();//call function insert.
}

else if (p==2)
{
cout<<"-----------------------------------"<<endl;
cout<<"CUSTOMER DATA DELETE"<<endl;
cout<<"-----------------------------------"<<endl;
remove();//call function delete.
}
else if (p==3)
{
cout<<"-----------------------------------"<<endl;
cout<<"CUSTOMER DATA SEARCH"<<endl;
cout<<"-----------------------------------"<<endl;
search();//call function search.
}
else if (p==4)
{
cout<<"-----------------------------------"<<endl;
cout<<"CUSTOMER DATA DISPLAY"<<endl;
cout<<"-----------------------------------"<<endl;
display();//call function display.
}
else
{
cout<<"-----------------------------------"<<endl;
cout<<"EXIT"<<endl;
cout<<"-----------------------------------"<<endl;
}
cout<<"BACK TO MENU [Y/T] :";
cin>>respond;
}
}

//function for insert data into list
void insert()
{
abc *newptr; abc *cur , *prev; // create new pointer for struct node
cur = head; //new value inserted (cur) = niai head
prev = NULL; //last value or before (prev)=nilai NULL
newptr = new abc; //create new node to be insert.
//assign value for node
cout<<"ENTER NAME : ";
cin>>newptr->name; //new pointer point to new value inserted (name).
newptr->next = NULL; //new value point to NULL.
cout<<"ENTER IC NUMBER : ";
cin>>newptr->ic; //new pointer point to new value inserted (ic).
newptr->next = NULL; //new value point to NULL.
cout<<"ENTER DATE OF BIRTH : ";
cin>>newptr->dte_b; //new pointer point to new value inserted (date of birth).
newptr->next = NULL; //new value point to NULL.
//link and head
if (head == NULL) // first, if list is empty,
{
head = newptr ; //head will point to newptr
}
else // or else insert at front.
{
//move the cur dan prev pointer
while(cur!= NULL && newptr->name > cur->name)//when cur is not NULL, new pointer which point
//to nama value will give current pointer to move the nama value.
{
prev = cur; //previous value equal to current value
cur = cur->next; //current value point to next node.
}
// insert at front
newptr->next = head; //new pointer point to next node and equal to head.
head = newptr; //the value of head is equal to value of new pointer.

}
}
//function to delete the data
void remove()
{
string ic;
abc *prev;
abc *cur;
cout<<"ENTER IC NUMBER OF CUSTOMER DATA TO BE DELETED : ";
cin>>ic;
prev = NULL; cur = head;
if(head == NULL) // start with empty list.
cout<<"SORRY, NO DATA FOUND IN THE LIST:";
else //if list has a data,can be delete.
{
while(cur != NULL && ic!= cur->ic) //move the pointer of cur and prev
{
prev = cur;
cur = cur->next;
}
if(prev == NULL) //remove from front.
{
head = head->next; // or head = cur->next
delete cur ; //atau free(cur);
}
else if (cur == NULL) //if no elemen in the list
{
cout<<"SORRY, NO DATA TO BE DELETED IN THE LIST.";
}
else //remove from center or back.
{
prev->next = cur->next;
delete cur;
}
}
}

//function untuk search data.
void search()
{
string ic;
abc *cur;
cur = head;
cout<<"ENTER IC NUMBER :"; //enter ic no. of customer you search for.
cin>>ic;
while(cur != NULL && ic != cur->ic)
{
cur = cur->next; //cur move to next nod.
}
if(cur == NULL)
cout<<"SORRY, NO DATA FOUND IN THE LIST:-";
else
cout<<"DATA FOUND :- ";
}

//function to display data in the list.
void display()
{
abc *cur; //declare cur pointer
cur = head ; //new value inserted (cur) is equal to value of head
while(cur != NULL) //while current is not NULL, the loop will print value
{
cout<<"\nNAME :"<<cur->name<<endl; //output
cur = cur->next; //new value inserted will place at front of value inserted before.
cout<<"IC NUMBER :"<<cur->ic<<endl;
cur = cur->next;
cout<<"DATE OF BIRTH :"<<cur->dte_b<<endl;
cur = cur->next;
}

}

[/CODE]

Share this post


Link to post
Share on other sites

Posted · Report post

awak tak initialize variable respond.
bile gune while loop..condition pada while always false..so, dia tidak akan masuk dalam while loop untuk check input kepada respond dan terus keluar dari while loop.

Share this post


Link to post
Share on other sites

Posted · Report post

Betul3. Must be initilized to 'Y'.

char respond = 'Y';

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

[CODE]
while(respond == 'Y' || respond == 'y')
[/CODE]

Kesilapan pertama, while ada syarat terlebih dahulu.... Jadi cara lain maybe leh wat cam gini

[CODE]
char respond = 'Y';
while(respond == 'Y' || respond == 'y')
{
bla bla bla....
}
[/CODE]

Happy Programming....;) Edited by Chuki2

Share this post


Link to post
Share on other sites

Posted · Report post

terima kasih sudi membantu :35:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0