| | |
help me with this....
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 4
Reputation:
Solved Threads: 0
The problem:
Given a list of imployees, create a simple program that allows the user to insert, delete, display and search an employee. The prog. shall display 10 imployees as default. Also a list of menu should be display. The menu names are insert, delete, dsplay and search.
My questions are:
1. what syntax should i use to insert character that allows 'space'?
2. is there a syntax that can 'search' name within a list,,, what is it?
*ideally, it should delete the list or name with a 'current node'.
*the bold part of the prog. is my problem....'searchng to a list'.
i created this prog. guided by the notes given to me.
Sir/madam, i'm new in making c++ program...hope you can help me with this... thank you..God bless..
Given a list of imployees, create a simple program that allows the user to insert, delete, display and search an employee. The prog. shall display 10 imployees as default. Also a list of menu should be display. The menu names are insert, delete, dsplay and search.
My questions are:
1. what syntax should i use to insert character that allows 'space'?
2. is there a syntax that can 'search' name within a list,,, what is it?
*ideally, it should delete the list or name with a 'current node'.
*the bold part of the prog. is my problem....'searchng to a list'.
i created this prog. guided by the notes given to me.
C++ Syntax (Toggle Plain Text)
#include <iostream.h> struct node { char name[50], search[50]; node *nxt; }; node *strtPtr = NULL; node *current; int choice; void insert() { node *emp,*emp1; emp=new node; cout<<"Name of Employee:\n"; cin>>emp->name; emp->nxt=NULL; if(strtPtr==NULL) { strtPtr=emp; current=strtPtr; } else { emp1= strtPtr; while(emp1->nxt != NULL) { emp1=emp1->nxt; } emp1->nxt = emp; current=emp; } cout<<"\n\n"; } void display() { node *emp; emp=strtPtr; cout<<"\nList of the Employees: \n"; if(emp==NULL) cout<<"List is empty\a\a\n\n"; else { while(emp!=NULL) { cout<<emp->name; if(emp==current) cout<<" <---"; cout<<endl; emp=emp->nxt; } cout<<"\nEnd of List\n\n\n"; } } void del() { node *emp, *emp1; current=strtPtr; if(strtPtr==NULL) cout<<"The List is empty\a\a\n"; else { emp=strtPtr; if(emp->nxt==NULL) { delete emp; strtPtr=NULL; } else { while(emp->nxt!=NULL) { emp1=emp; emp=emp->nxt; } delete emp; emp1->nxt=NULL; } } } void search() { node *emp,*emp1; emp=strtPtr; if(emp==NULL) { cout<<"List is empty\a\a\n\n"; } else { emp1=new node; cout<<"Search (name): "; cin>>emp1->search; cout<<endl; if(emp==emp1) { emp=current; } else { while(emp!=emp1) { emp=emp->nxt; emp->nxt=emp1; current=emp; } } } } void main() { strtPtr=NULL; do { cout<<"Select your option\n" <<"[0] Exit\n" <<"[1] Insert new employee\n" <<"[2] Display list of employees\n" <<"[3] Delete employee\n" <<"[4] Search employee\n\n>>"; cin>>choice; cout<<"\n"; switch(choice) { case 1: insert(); break; case 2: display(); break; case 3: del(); break; case 4: search(); break; } } while(choice != 0); }
Sir/madam, i'm new in making c++ program...hope you can help me with this... thank you..God bless..
>1. what syntax should i use to insert character that allows 'space'?
cin.getline:
>2. is there a syntax that can 'search' name within a list,,, what is it?
It's called a loop:
And if I may be so bold, is there a shortage of vowels on your system? nxt and strtPtr are exceptionally annoying to type and read.
cin.getline:
C++ Syntax (Toggle Plain Text)
cin.getline ( emp->name, 50 );
It's called a loop:
C++ Syntax (Toggle Plain Text)
node *it = strtPtr; while ( it != 0 ) { if ( strcmp ( it->name, key ) == 0 ) break; it = it->nxt; } if ( it != 0 ) cout<<"Found '"<< it->name <<"'\n";
In case you were wondering, yes, I do hate you.
•
•
•
•
1. what syntax should i use to insert character that allows 'space'?
string Name; and if u gona accept it from the user u can achieve that by this getline(cin, Name) or if u just want to right u can also use getline() methodgeline(Name);
•
•
•
•
2. is there a syntax that can 'search' name within a list,,, what is it?
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Reading in C++ code at runtime?
- Next Thread: Urgent: How to read a file again uisng c++
Views: 488 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm array arrays assignment basic beginner binary c++ c/c++ calculator char class classes client code compile compiler constructor conversion convert count delete dll dynamic encryption error file files form fstream function functions game givemetehcodez graph graphics gui homework iamthwee ifstream input int lazy link linker list loop loops map math matrix member memory newbie number object objects opengl output parameter pointer pointers problem program programming project python random read reading recursion recursive reference search sockets sort spoonfeeding string strings struct student studio template templates text time tree url variable vc++ vector video visual win32 window windows winsock wordfrequency wxwidgets






