Question

In: Computer Science

c++ language Create a file program that reads an int type Array size 10; the array...

c++ language

Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.

Solutions

Expert Solution

So I have implemented the required code, please read all the comments carefully, every bit of line is explained using comments because if I try to explain as a whole then possibly it will become difficult for you to understand.
Let me tell you the main algorithm I have followed

Step 1: I have extracted the values from the text file using the syntax as the C++ rules

Step 2 : Created array of 5 slots bigger and copied the values and took input for remaining 5 values.

Step 3 : User input for the element to be searched and called binary search function thereafter.

In the last add cout if you want to print the result of binarySearch function.

Below is the output :

first line shows numbers read from .txt file, second is input for 5 extra slots, third is the element to be searched and final fourth is the location of the element which is searched


Related Solutions

IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The program then calls the foo function. The function will modify the array x of size n by doubling any values in x that are less than the threshold. The function will count how many values were changed and how many were not changed via two reference parameters. The function signature is: void foo(int n, int x[], int threshold, int *pChanged, int *pUnchanged); The function...
Convert the following C++ statements to an ARM assembly language program: const int size = 10;...
Convert the following C++ statements to an ARM assembly language program: const int size = 10; int x[size] = {8, 2, 9, 6, 7, 0, 1, 3, 5, 4}; int y[size] = {399, -87, 12, 0, 42, -367, 57, 92, -1000, 25}; for i = 0; i < size; i++) if (x([ i ] > y[ i ]) z[ i ] = 0 else z[ i ] = 1;
This is C++ Create a program that reads an HTML file and converts it to plain...
This is C++ Create a program that reads an HTML file and converts it to plain text. Console: HTML Converter Grocery List * Eggs * Milk * Butter Specifications: The HTML file named groceries.html contains these HTML tags: <h1>Grocery List</h1> <ul> <li>Eggs</li> <li>Milk</li> <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add asterisks (*) before the list items, and display the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the range of 0 to 100. There may be repeats. The numbers must not be ordered/sorted. The task is to find and print the two smallest numbers. You must accomplish this task without sorting the file and without using arrays for any purpose. It is possible that the smallest numbers are repeated – you should print the number of occurrences of the two smallest numbers....
How to do in C++ HTML Converter Create a program that reads an HTML file and...
How to do in C++ HTML Converter Create a program that reads an HTML file and converts it to plain text. Console HTML Converter Grocery List * Eggs * Milk * Butter Specifications Your instructor should provide an HTML file named groceries.html that contains these HTML tags: <h1>Grocery List</h1> <ul>     <li>Eggs</li>     <li>Milk</li>     <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add...
Create a C Program that reads a file and replaces every other letter with an asterisk....
Create a C Program that reads a file and replaces every other letter with an asterisk. The first integer 'num' is the number of lines. Include an "Error" Message and exit the program if:    The wrong name for the input/output file is given    The input/output file can not be opened input.txt 7 Never Have We Ever Played A Game output.txt 7 N*v*r *a*e W* *v*r *l*y*d * G*m*
Write a program in c++ that reads x[4]. Then create the array y[6||6], such that the...
Write a program in c++ that reads x[4]. Then create the array y[6||6], such that the first quarter of y consists of the value of the first element of x. The second quarter of y consists of the value of the second element of x. The third quarter of y consists of the value of the third element of x. The fourth quarter of y consists of the value of the fourth element of x?
Write C++ program to do the following: 1. Create integer array size of 10 2. Ask...
Write C++ program to do the following: 1. Create integer array size of 10 2. Ask user input the values of the array's element using for loop 3. pass the array to void function. in void function do the following: a. Find the maximum of the array. b. Compute the element average c. Find out how many numbers are above the average d. Find out and print how many numbers are below the average e. find out how many numbers...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT