| ITstudent (19) | |
|
#include <iostream.h> // execute input and outpu process. #include <cstring.h> // defines several functions to manipulate C strings and arrays. #include<conio.h> struct data { char name[30]; string id; data *next; // pointer next=point to next node. }; // declare operation of list. void insert(); void display(); data *head; // head is a pointer which will point to first node. main() { int p; char respond='Y'; while(respond == 'Y' || respond == 'y') { cout << " ============================ " << endl; cout << "\n TELEKOM MALAYSIA " << endl; cout << "\n CUSTOMER DATA SYSTEM " << endl; cout << "\n ..::STREAMYX::.. " << endl; cout << " ============================ " << endl <<endl; cout << "\n\t\ ..:: MENU ::.. " << endl; cout << " \n 1) INSERT CUSTOMER DATA " << endl; cout << " 2) DISPLAY CUSTOMER DATA " << endl; cout << " 3) EXIT " << endl; cout << " ============================ " << endl; cout << " CHOICE : "; cin >> p; // enter menu nu. clrscr(); if (p==1) { cout << " ..:: INSERT CUSTOMER DATA ::.. " << endl; cout << " ================================= " << endl; insert(); // call function insert. } else if (p==2) { cout << " ..:: DISPLAY CUSTOMER DATA ::.. " << endl; cout << " ================================= " << endl; display(); // call function display. } else (p==3) { cout << " ..:: EXIT ::.. " << endl; cout << " ============== " << endl; } cout << "\n\n RETURN TO MENU [Y/T] : "; cin >> respond; clrscr(); } } // function to insert data. void insert() { data *newptr; data *cur; // create new pointer for struct node. cur = head; // new value inserted (cur)-nilai head. newptr = new data; cin.ignore(); // assign value for node cout << " INSERT NAME : "; cin.getline (newptr -> name,30); // new pointer point to new value inserted (name). newptr -> next = NULL; // new value point to NULL. cout << " INSERT ID NO : "; cin >> newptr -> id; // new pointer point to new value inserted (id). 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 element which newptr point to. } else // or else, insert at front. { // move the cur 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. { 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. } } // funtion to display data in the list. void dislay() { data *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 << "\n CUSTOMER NAME : " <<cur -> name<< endl; //output cout << " CUSTOMER ID : " <<cur -> id << endl; cur = cur -> next; //current value point to next node. } } | |
|
Last edited on
|
|
| ITstudent (19) | |
|
when I compile & link my coding I get error Error E2379 streamyx.cpp 56: Statement missing ; in function main() | |
|
|
|
| NGen (630) | |
|
"main()" Should be int main ().Additionally, your definition for the display() function (towards the end) uses "dislay" instead. You forgot a P.
| |
|
Last edited on
|
|
| ITstudent (19) | |
|
thanks:: got it can you help me on http://www.cplusplus.com/forum/windows/86764/ this.. its my assignment about struct, array on subject.. i really need help | |
|
|
|
| ITstudent (19) | |
|
noted it.. thanks can you help me on this http://www.cplusplus.com/forum/windows/86764/ about struct n array on subject URGENT!! | |
|
|
|