MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / F_Third_Program

Function F_Third_Program

Lab_19/main.cpp:144–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void F_Third_Program()
145{
146
147 for (int k = 0; k < 1000; k++)
148 {
149 system("cls");
150 cout << "S E A R C H I N G F O R N U M B E R \n"
151 << "------------------------------------\n"
152 << "1. Add numbers\n"
153 << "2. Search for number\n"
154 << "0. Back\n"
155 << "Your choice: \n";
156
157 ofstream out_numbers("numbers.txt", ios::app); // the list could be contiunied after the program execution
158
159 int numbers;
160
161 switch (_getch())
162 {
163 case 49:
164 {
165 system("cls");
166 cout << "ENYER NUMBERS\n";
167
168 // inputing numbers
169 for (int i = 1; i <= 20; i++)
170 {
171 cout << "[ " << i << " ] -> ";
172 cin >> numbers;
173 out_numbers << numbers << endl;
174 }
175 out_numbers.close(); // closing the file
176
177 system("pause");
178 }
179 break;
180
181 case 50:
182 {
183 system("cls");
184 ifstream in_numbers("numbers.txt");
185
186 cout << "SEARCHING A NUMBER\n";
187
188 int search_number;
189 bool isAnswerHere = 0; // for finding the searching number from available list
190 cout << "Enter the number to search: ";
191 cin >> search_number;
192
193 while (in_numbers)
194 {
195 in_numbers >> numbers;
196 if (search_number == numbers)
197 isAnswerHere = 1;
198 } // while loop
199
200 if (isAnswerHere == 1)
201 cout << "\nThe number is available in list.\n\n";

Callers 1

mainFunction · 0.85

Calls 1

mainFunction · 0.70

Tested by

no test coverage detected