I am having two problems with my school project. I am writing it using VIM in UNIX on the school server.
First problem:
my menu is doing this:
Code:
MENU
(I)nsert new record
(L)ast name search
(S)ave database to a file
(R)ead database from a file
(Q)uit
Enter choice: i
Insert new record selected
Please enter employee's Last Name:
Please enter employee's First Name:
It is skipping ahead of Last Name!
Do I need to add cout.flush() somewhere? When I add cout.flush() right under the last name section I get this error:
Code:
unixapps1:Lab1> make
g++ -o LSL lab1.cpp Employee.cpp
lab1.cpp: In function âEmployee createRecord()â:
lab1.cpp:41: error: âstruct std::istreamâ has no member named âflushâ
My menu code in my is this:
Code:
160 int main() {
161
162 cout << "\n"
163 << "************************************************************\n"
164 << "Remember: Search for TODO's in VI before submitting project!\n"
165 << "************************************************************\n\n";
166
167 char menu_choice;
168 string fileName;
169
170 // Create a database
171 LinkedSortedList<Employee> database;
172
173 while (true) {
174 // Display menu
175 cout << "MENU\n"
176 << "(I)nsert new record\n"
177 << "(L)ast name search\n"
178 << "(S)ave database to a file\n"
179 << "(R)ead database from a file\n"
180 << "(Q)uit\n\n";
181
182 cout << "Enter choice: ";
183 cin >> menu_choice;
184 cout << endl;
185
186 switch (toupper(menu_choice)) {
187
188 case 'I':
189 cout << "Insert new record selected\n\n";
190 {database.insert(createRecord());}
191 break;
192
193 case 'L':
194 cout << "Last name search selected\n\n";
195 // TODO call function to search by last name
196 // TODO call search for Last Name
197 // TODO Print all matches found
198 {string searchVal = "";
199 database.find(searchVal);}
200 break;
201
202 case 'S':
203 cout << "Save database to a file selected\n\n";
204 // TODO call function to save database to file
205 // File I/O Save to file
206 cout << "Please enter a file name: " << endl;
207 cin >> fileName;
208 {char* file = (char*) fileName.c_str();
209 writeFile(file, database);}
210 break;
211
212 case 'R':
213 cout << "Read database from a file selected\n\n";
214 // TODO call function to read database from file
215 // File I/O Read file
216 cout << "Please enter a file name: " << endl;
217 cin >> fileName;
218 {char* file = (char*) fileName.c_str();
219 readFile(file, database);}
220 break;
221
222 case 'Q':
223 exit(EXIT_SUCCESS);
224
225 // default case:
226 default:
227 cout << "Invalid choice!\n\n"
228 << "##### Please try again #####\n\n";
229 break;
230
231 cin >> menu_choice;
232 }
233 }
234 return 0;
235 }
236
My createRecord() function is this:
Code:
29 // Create the record to be inserted into the employee database
30 Employee createRecord() {
31 // Temporary variables for getting input from user
32 string stringInput = "";
33 int intInput = 0;
34
35 Employee newEmployee;
36
37 cout << "Please enter employee's Last Name: " << endl;
38 getline(cin, stringInput);
39 newEmployee.setLastName(stringInput);
40
41 cout << "Please enter employee's First Name: " << endl;
42 getline(cin, stringInput);
43 newEmployee.setFirstName(stringInput);
44
45 cout << "Please enter employee's ID: ";
46 getline(cin, stringInput);
47 stringstream myStream(stringInput);
48 myStream >> intInput;
49 newEmployee.setId(intInput);
50
51 cout << "Please enter employee's Salary: ";
52 getline(cin, stringInput);
53 myStream >> intInput;
54 newEmployee.setSalary(intInput);
55
56 cout << "Please enter employee's Department: ";
57 getline(cin, stringInput);
58 newEmployee.setDepartment(stringInput);
59
60 cout << "Please enter employee's Phone Number: ";
61 getline(cin, stringInput);
62 newEmployee.setPhoneNumber(stringInput);
63
64 cout << "Please enter employee's Address: ";
65 getline(cin, stringInput);
66 newEmployee.setAddress(stringInput);
67
68 cout << "Please enter employee's Hire Date: ";
69 getline(cin, stringInput);
70 newEmployee.setHireDate(stringInput);
Second problem:
I am getting the following build error:
Code:
unixserver:Lab1> make
g++ -o LSL lab1.cpp Employee.cpp
lab1.cpp: In function âint main()â:
lab1.cpp:199: error: no matching function for call to âLinkedSortedList<Employee>::find(std::string&)â
LinkedSortedList.cpp:137: note: candidates are: bool LinkedSortedList<Elem>::find(Elem) const [with Elem = Employee]
make: *** [main] Error 1
Here is my find function:
Code:
132 // Check to see if "value" is in the list. If it is found in the list,
133 // return true, otherwise return false. Like print(), this function is
134 // declared with the "const" keyword, and so cannot change the contents
135 // of the list.
136 template<class Elem>
137 bool LinkedSortedList<Elem>::find(Elem searchvalue) const {
138 if (head == NULL) {
139 return false;
140 } else {
141 while (head != NULL) {
142 LinkedNode<Elem>* pointer;
143 for (pointer = head; pointer != NULL; pointer = pointer->next) {
144 if (pointer->value == searchvalue) {
145 return true;
146 }
147 }
148 }
149 return false;
150 }
151 }
And this is in my LinkedSortedList.h file under the "public:" section:
Code:
33 bool find(Elem searchvalue) const;
Also, if anyone could give me hints on using gdb in Unix that would be helpful...
Thanks in advance!