Write a program to accomplish the following tasks:
- Generate arbitrary number of random integer numbers between [0-100]
- Save or load the numbers from/to a text file based on user option
- Search the generated list for an arbitrary number entered by a user
- Use Linear and Binary search algorithms based on a user option
- Computes CPU time used by either search algorithm
- Use menu-based interaction with the user
MY WORK
Program Description: Arrays
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int max, random_number, x;
max= 100;
for (x=0; x<=1000, x=x+1) {
srand(time (0));
random_number = (ran () % max) + 1;
cout << random_number << endl;
}
sytem ("pause")
{
string file;
ifstream fin;
int SaveNumbers= n1 , n2;
do
{
fin.clear();
cout << "enter name of file to connect to: ";
cin >> file;
fin.open (file.c str());
} while(!fin);
string line = "---------------------------------------n"
string msg1 = " Please enter two numbers n1 n2"
string msg2 = " Please select an option from the above menu --> ";
string menu = " [0,9] Quit n"
" [1] Confirm input n"
" [2] Add n"
" [3] Subtract n"
" [4] Multiply n"
" [5] Divide n"
cout << msq1;
cin >> n1 >> n2;
count << "nn"
cout << menu1 << "nn" msg 2;
cin >> op1;
cout << line;
for menu1 switch( op1 )
}
{
Case 0:
case 9: return 0; break
case 1: cout << n1 << " " << n2 << endl; break;
case 2: cout << n1 + n2 << endl; break;
case 3: cout << n1 - n2 << endl; break;
case 4: cout << n1 * n2 << endl; break;
case 5: cout << n1 / n2 << endl; break;
default: cout << "indvalid option...n" break;
}
cout << "nn";
cout << meanu << "nn" << msg2;
char op2;
char op2;
cout << line;
for menu2 switch ( op2 )
{
case 'x' :
case 'X' :
case 'q' :
case 'Q' : return 0; break;
case '!' :
case '?' : cout << n1 << " " << n2 << endl; break;
case '+' : cout << n1 + n2 << endl; break;
case '-' : cout << n1 - n2 << endl; break;
case '*' : cout << n1 * n2 << endl; break;
case '' :
case '/' : cout << n1 / n2 << endl; break;
default: cout "invalid option...n"; break;
}
return 0;
}
bool SaveNumbers( const char* pszFilename, int* piNumbers, int iSize )
{
string file;
ifstream fin;
int n1, n2;
fin >> n1;
fin >> n2;
fin.close();
}