
-Write a C++ program with the following functions, with the correct number of arguments for each function, as well as any other functions used in class.
- void fillUpArray ( argument1, argument2) This function should read in a text file called "theVillagers.txt" (You may download it on Canvas). "theVillagers.txt" is a text file of numbers in ascending order, ranging anywhere from 1 to 2500, nonrepeating. Each number is separated by a new line character. The very first number in the text file is a number that refers to how many entries are in the rest of the text file. This function should populate an array with all the remaining entries in the text file, but it should NOT declare any arrays itself and it should not reference any global variables.
- void getInput(argument1, argument2) This function should read in a text file of the user's choosing into a given array. It should discard excess input. You may assume that there are always 2000 entries in this text file being entered.
- void processOne(argument1, argument2, argument3, argument4) This function should use one array as input and perform that many search queries on the other array using sequential search. Nothing is done with the results.
- void processTwo(argument1, argument2, argument3, argument4) This function should use one array as input and perform that many search queries on the other array using binary search. Nothing is done with the results.
- void printArray (argument1, argument2) This function should print out the contents of an array, with a space between each item.
- You should use the concept of partially filled arrays by declaring an array of some arbitrarily large size, and having a variable "numberUsed" that will eventually store the number of values in the array. Do this in the main function, and then make the appropriate function calls to accomplish the following task:
- After the array is populated, the program should then output the array and make the appropriate calls to get input from the user, and test the input array on both sequential and binary search. You should use the chrono library features as discussed in a previous lecture to time how long each process takes.
- Make sure your program runs at least twice, to see if there are fluctuations in time.
Example Output:
Here are the array contents:
1 2 3 4 5 6 7 8 9 25 40 55 (…)
Enter a text file for input: input.txt
Sequential Search took 2.345 seconds.
Binary Search took 1.231 seconds.
I have done half. I need help with 2,3,and 4. I do not know what it means.Thank you!
#include <iostream>
#include <string>
#include <fstream>
#include <chrono>
using namespace std;
//FUNCTION DECLARATIONS:
void fillUpArrayV(int theArrayV[],int &NumberUsed);
void getInputV(int inputArray[],int &inputNumberUsed);
void printArray(int theArray[],int NumberUsed);
void processOne(int theArray[], int NumberUsed, int inputArray[], int inputNumberUsed);
int sequentialSearch(int theArray_V[],int NumberUsed,int input_Array_V[]);
int binarySearch(int theArrayV[],int NumberUsed,int input_Array[]);
int main()
{
int theArray[2500];
int NumberUsed=0;
int inputArray[2000];
int inputNumberUsed=0;
fillUpArrayV(theArray,NumberUsed);
printArray(theArray,NumberUsed);
getInputV(inputArray,inputNumberUsed);
sequentialSearch(theArray,inputNumberUsed,inputArray);
processOne(theArray,NumberUsed,inputArray,inputNumberUsed);
return 0;
}
void fillUpArrayV(int theArray[],int &NumberUsed)
{
ifstream inputFile ("theVillagers.txt");
if (inputFile.is_open())
{
inputFile>> NumberUsed ;
for(int i=0;i<NumberUsed;i++)
{
if ( i == NumberUsed )
break ;
inputFile>> theArray[i];
}
}
else if (inputFile.fail())
{
cout << "Cannot open file.\n";
exit(1);
}
}
void printArray(int theArray[],int NumberUsed)
{
{
cout << "Here are the array contents: ";
for(int i = 0 ; i < NumberUsed ; i++ )
cout << theArray[i] << " ";
cout<<endl<<endl;
}
}
void getInputV(int inputArray[],int &inputNumberUsed)
{
string input_file_string;
ifstream input_file;
cout<<"Enter a text file for input: ";
cin>>input_file_string;
if(input_file_string=="theVillagers.txt")
{
input_file.open("theVillagers.txt");
{
cout<<"YAY OPENED!"<<endl;
input_file>> inputNumberUsed ;
for(int i=0;i<inputNumberUsed;i++)
{
if ( i == inputNumberUsed )
break ;
input_file>> inputArray[i];
}
}
}
if(input_file.fail())
{
cout<<"Unable to open file."<<endl;
exit(1);
}
}
void processOne(int theArray[], int NumberUsed, int inputArray[], int inputNumberUsed) {
for (int c = 0;
c < 3; c++) //repeating the queries 3 times (or even more) can help with processors that are too fast
{
for (int i = 0; i < inputNumberUsed; i++) {
int index = sequentialSearch(theArray,NumberUsed,inputArray[]);
if (index == -1); //do nothing with the output
}
}
}
int sequentialSearch(int theArray_V[],int NumberUsed,int input_Array_V[])
{
for(int i=0;i<NumberUsed;i++)
{
if(theArray_V[i]==input_Array_V[i])
{
cout<<"Sequential Search: ";
return i;
}
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps

- JAVA PROGRAM Chapter 4. Homework Assignment (read instructions carefully) Write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage PLEASE FIX AND MODIFY THIS JAVA SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL TEST CASSES PLEASES. RIGHT NOW IT SAYS 0 OUT 3 PASSED. THE PICTURES THAT I PROVIDED PROOF THAT WHEN I UPLOAD IT TO HYPERGRADES IT FAILS TEST CASSES. THANK YOU. import java.io.*;import java.util.Scanner;public class FileTotalAndAverage { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Please enter the file name: "); while (true) { String fileName = scanner.nextLine(); File file = new File(fileName); if (file.exists() &&…arrow_forwardIn Python, Create a program that will write 100 integers created randomly in a file. The integers will be separated by a space in the file. Read the data back from the file, and display the sorted data. The program should prompt the user to enter a file name. Utilize the following function headers for this problem: Main() WriteNumbers(filename) ReadNumbers(filename) The main function will first prompt the user to enter the filename. Then the main function calls WriteNumbers-then ReadNumbers. The WriteNumbers function opens an output file and writes 100 random numbers as long a large string text. Do not use lists for this problem- please just write a random number followed by a space 100 times. The ReadNumbers function will then read the text file and display the numbers sorted. In order to sort the numbers, read the big string and then split it into a list. Now convert them into integers by using list comprehension and then sort the list. Loop through the list and print each…arrow_forwardJAVA PROGRAM Chapter 4. Homework Assignment (read instructions carefully) Write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage PLEASE FIX AND MODIFY THIS JAVA SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL TEST CASSES PLEASES. RIGHT NOW IT SAYS 0 OUT 3 PASSED. THE PICTURES THAT I PROVIDED PROOF THAT WHEN I UPLOAD IT TO HYPERGRADES IT FAILS TEST CASSES. THANK YOU. import java.io.*;import java.util.Scanner;public class FileTotalAndAverage { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Please enter the file name: "); while (true) { String fileName = scanner.nextLine(); File file = new File(fileName); if (file.exists() &&…arrow_forward
- A file named data.txt contains an unknown number of lines, each consisting of a single integer. Write a program that creates the following three files: dataplus.txt dataminus.txt zeros.txt The program should read each line of the data.txt file and perform the following: If the line contains a positive number, that number should be written to the dataplus.txt file. If the line contains a negative number, that number should be written to the dataminus.txt file. If the line contains the value 0, do not write the value to a file. Instead, keep a count of the number of times 0 is read from the data.txt file. After all the lines have been read from the data.txt file, the program should write the count of zeros to the zeros.txt file.arrow_forwardAs soon as you link up a pointer to another variable, you can work the other value by the pointer. Inemels dereferencing recording listing duplicating a. b. С. d. rigirl hon ent abnd andionut O gniowallot e Topalni aon aarrow_forward9b_act2. Please help me answer this in python programming.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





