Write a program which generates randomly some numbers (integer) say 20 numbers
between 1 and 100 and send it to an output file called randOutput.txt. Next your program
should open this file (randOutput.txt) and check whether the numbers are ordered either
ascending (or descending) or not. So you should have a ‘Check function’ which returns 1
if it is ordered in ascending order, 0 if it is not ordered and -1 if it is ordered in
descending order.
If it is not sorted your program should make use of ‘linear search’ to look for three
numbers (Key1, key2 & key3) in the list. You can either ask the user to enter these keys
at the command line or you can read them from another input file (inputKeys.txt).
Next your program should sort the list using ‘bubble sort’ and display the ordered list
both on screen and to an output file (orderedList.txt).
Finally the program should implement a ‘binary search’ to look for three keys mentioned
above after the list has been sorted.
The keys can be sent separately one by one through the search algorithm or as array
parameters to a ‘search function’.

#include <stdlib.h>
#include <iostream>
#include <fstream>

using namespace std;

void open()
{
       char data1[50];
  ifstream myfile ("randOutput.txt");
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      myfile.getline (data1, 100);
      cout << data1 << endl;
    }
    myfile.close();
     }
    else cout << "Unable to open file"; 
  system("pause");  
}
void gen_rand()
{
   int  i, seed;
   cout << "\nPlease any integer to Generate Random Numbers: ";
   cin >> seed;     // Reads an integer.
   cin.ignore();
   srand( seed);     
   cout << "\n\n            "
           "RANDOM NUMBERS\n\n";
   std::ofstream cout("randOutput.txt");
   for( i = 1 ; i <= 20 ; ++i)
      cout <<(rand() % 100+1) << endl;
}

int main()
{
    int num;
    cout<<" \n\tPress 1"" For Random Numbers option. \n"
          " \n\tPress 2"" To Show the generated Random Numbers. "
          "\n\n\tOption (1-2): ";
    cin>> num;
    cin.ignore();    
    if(num==1){
               system("cls");
               gen_rand(); // Calling the gen_rand() function
               }
	if(num==2){
               system("cls");
               open();
              }
    if(num==0){   
                  cout << "\n\tERROR!  Please Select An Appropriate Options";
              }
    if(num>=3){    
                  cout <<"\n\tERROR!  Please Select An Appropriate Options";
                }                
    cin.get();
	return 0;
}

Sorry dude, we're not going to do your homework. I hope you don't think we're dumb enough to fall for the "this is a challenge for everyone!" trick.

This article has been dead for over six months. Start a new discussion instead.