1 answer

C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains...

Question:

C++ code

The assignment has two input files:
• LSStandard.txt
• LSTest.txt
The LSStandard.txt file contains integer values against which we are searching. There will be no more than
100 of these. The LSTest.txt file contains a set of numbers that we are trying to locate within the standard data
set. There will be no more than 50 of these.
Read both files into two separate arrays.
Your program should then close both input files.
All subsequent processing will be done on the arrays only.
Use each number in the search value array from the LSTTest.txt file as a search value to search over the standard
array that contains the data set from the LSStandard data file. This search is accomplished by a function using a
Linear Search algorithm on the array that contains the standard data set.

Have your program display out a report to the console that indicates whether the number was found or not.
Your output should look something like:
Number 1 ( 79) was located at index 44.
Number 2 ( 74) was not in the file.
Number 3 ( 56) was not in the file.
Number 4 (103) was located at index 75.
etc.
Note that the number for which we searched is indicated in parenthesis in the display report. The index number refers to the index of the element within the stdList array data where the search value was found.
Your function header for the Linear Search function should look like:
int searchList(int stdList [], int numElems, int searchValue)
You’ll notice that this function accepts an array as input parameter. That array, called stdList in the parameter list, will be the array that contains the standard data set. The parameter numElems is the number of elements in that array, and the parameter searchValue is the element that we are searching for.
Your function should search for searchValue within the stdList array and return one of two answers:
• a -1 if value is not in stdList array
• if searchValue is in stdList, the index position of searchValue within the stdList array.
This should be a number between 0 and numElems-1.
Your program should then use this result to determine what should be displayed in the report.
Note that some of the numbers in LSTest appear more than once in LSStandard. This Linear Search algorithm will return the first found instance.

Thank you


Answers

Program code to copy:-

#include <iostream>   //Used for standard input/output
#include <cstdlib>   //used for exit() function
#include <fstream>   //used for input file stream

using namespace std;

//Function prototype
int searchList(int stdList [], int numElems, int searchValue);

int main()
{
   //Decalring array to store data set read from standard file
    int stdArray[100];
    //Decalring array to store data set read from test file
    int testArray[50];

    //Decalring input file stream object
    ifstream stdFile, testFile;
   
   //Open the standard file for reading
    stdFile.open("LSStandard.txt");
    //Checking whether the file is opened successfully or not
    if(!stdFile)
   {
   cout << "LSStandard.txt file can not opened for reading" << endl;
    exit(0);
    }
   
    int i=0;
    //Loop will be executed till end of file
   while(!stdFile.eof())
    {
    //Reading each number from standard file into array
stdFile >> stdArray[i];
i++;
    }
   //Closing standard file
   stdFile.close();
   //Storing total numbers read from standard file
   int numElemsStd = i;
   
  
   //Open the test file for reading
    testFile.open("LSTest.txt");
    //Checking whether the file is opened successfully or not
    if(!testFile)
   {
   cout << "LSTest.txt file can not opened for reading" << endl;
    exit(0);
    }
   
    i=0;
    //Loop will be executed till end of file
   while(!testFile.eof())
    {
    //Reading each number from test file into array
testFile >> testArray[i];
i++;
    }
   //Closing test file
   testFile.close();
   //Storing total numbers read from test file
   int numElemsTest = i;
  
  
int index;
for(int i=0; i<numElemsTest; i++)
{
//Calling function for each element of test array to search it in standard array
index = searchList(stdArray, numElemsStd, testArray[i]);
  
if(index != -1)
{
//Display details of each number of test array if found in an standard array
cout << "Number " << (i+1) << " " << "(" << testArray[i] << ")"
<< " was located at index " << index << endl;
}
else
{
//Display details of each number of test array if not found in an standard array
cout << "Number " << (i+1) << " " << "(" << testArray[i] << ")"
<< " was not in the file" << endl;
}
  
}
  
return 0;
}

//Function search for searchValue within the stdList array and
//return one of two answers: -1 if value is not in stdList array or
//if searchValue is in stdList, the index position of searchValue within the stdList array.
//Function accepts three parameters:-
//1. An array that contains the standard data set.
//2. The parameter numElems is the number of elements in that array.
//3. The parameter searchValue is the element that we are searching for.
int searchList(int stdList[], int numElems, int searchValue)
{
for(int i=0; i<numElems; i++)
{
if(stdList[i]==searchValue)
//Returns index value of number if found in standard array
return i;
}
//Returns -1 if not found in standard array
return -1;
}

Screenshot of output:-

Number 1 (33) was located at index 2 Number 2 (16) was not in the file Number 3 (40) was located at index 5 Number 4 (76) was

Screenshot of content of file named "LSStandard.txt" used in the program:-

LSStandard - Notepad File Edit Format View Help 44 78 33 10 20 40 100 110 70 45 19 51 23 37 97 82 88 77 11 5

Screenshot of content of file named "LSTest.txt" used in the program:-

LSTest - Notepad File Edit Format View Help 33 16 40 76 45 51 37 82 77 39

.

Similar Solved Questions

1 answer
What's the integral of #int (tanx)*(e^x)dx#?
What's the integral of #int (tanx)*(e^x)dx#?...
1 answer
The March Madness Company (MMC) converted an account receivable into a 90-day note on 10/15. The...
The March Madness Company (MMC) converted an account receivable into a 90-day note on 10/15. The face amount of the note was $10,000. The interest rate was 10% (annual rate). On 11/24 MMC discounted the note at the Big TenBank the discount rate was 12%. Determine the cash proceeds received from the ...
1 answer
Is my solution correct? 3.15. Given the following data, calculate the projected available balance and the...
is my solution correct? 3.15. Given the following data, calculate the projected available balance and the planned MPS receipts. The lot size is 100. The demand time fence is 2 weeks. 4 2 3 Week 50 50 50 50 Forecast 25 30 65 60 Customer Orders 60 Projected Available Balance MPS 312 3. 15 demand time ...
1 answer
How do i calculate my % yield LLLLLLLS LLLL LL LLLLLLL % Yield Table 2. Starting...
how do i calculate my % yield LLLLLLLS LLLL LL LLLLLLL % Yield Table 2. Starting Amount, Final Amount, and % Yield Starting Amount of Starting Amount of Final Amount benzaldehyde (carbethoxymethylene) triphenylphosphorane 0.057 g 0.203 g | 0.038 g...
1 answer
Is it possible to have a factorial within-subjects design? If so, give an example. If not,...
Is it possible to have a factorial within-subjects design? If so, give an example. If not, explain. Researchers must be careful to minimize progressive error in any within-subjects design. Explain what is "progressive" about progressive error and why it is considered an "error."...
1 answer
"Full employment output" means that the unemployment rate is equal to: Question 7 options: the long-run...
"Full employment output" means that the unemployment rate is equal to: Question 7 options: the long-run unemployment rate the short-run unemployment rate zero the short run + long-run unemployment rate...
1 answer
How do you solve #6x - 5 < 6/x#?
How do you solve #6x - 5 < 6/x#?...
1 answer
1) When a T account has several amounts on both the debit and credit sides, the...
1) When a T account has several amounts on both the debit and credit sides, the balance of the account is written a- on the side with the largest number of item amounts b- on the side with the smallest number of item amounts c- on the side with the larger total d-on the side with the smaller total 2...
1 answer
Іго, Electrochemistry Wolleet 1. Assign oxidation numbers to each element in the following compounds: a. VOCI...
Іго, Electrochemistry Wolleet 1. Assign oxidation numbers to each element in the following compounds: a. VOCI b. Cuso c. CHOH). d. Mno, e. SO, 2. Given the following half reactions and their standard reduction potentials, i. Cl (g) + 2e- - 2 CI (aq) E' =+ 1.36 V ii. Niº (a...
1 answer
When clothes have stains, bleach may be added to the wash to react with the soil...
when clothes have stains, bleach may be added to the wash to react with the soil and make the stains colorless. the bleach solution is prepared by bubbling chlorine gas into a solution of sodium hydroxide to produce a soultion of sodium hypochlorite, sodium chloide and water. one brand of bleach con...
1 answer
Question 1-4 facts – use the following balance sheet and cash flow data to respond to...
Question 1-4 facts – use the following balance sheet and cash flow data to respond to Questions 1-4. NOTE: Reference financial progress ratios on page 78 of your text. Short-term debt = $5,500 Mortgage debt (30 yr.) = $170,000 Liquid assets = $10,000 Home value = $210,000 Invest...
1 answer
If a 100 mL sample of sodium oxalate (Na2OOCCOO (aq)) has a pH of 9.23 at...
If a 100 mL sample of sodium oxalate (Na2OOCCOO (aq)) has a pH of 9.23 at 25.0 °C, the initial concentration of the sample of sodium oxalate is [1] mol/L....
1 answer
Compute the future values of the following annuities first assuming that payments are made on the...
Compute the future values of the following annuities first assuming that payments are made on the last day of the period and then assuming payments are made on the first day of the period: (Do not round intermediate calculations. Round your answers to 2 decimal places. (e.g., 32.16)) Paymen...
1 answer
Question 3 0.83 pts Write balanced nuclear equations for the following: Input numbers for mass numbers...
Question 3 0.83 pts Write balanced nuclear equations for the following: Input numbers for mass numbers or charges and symbols for the elements. a. B-decay of silicon-32: 3214Si → 0.13 + 15 b. d-decay of polonium-218: 21834Po → 82 + a 110 491n: c. Electron capture by 110 110 °4919 + 0 1...
1 answer
Required information Problem 25-2A Analysis and computation of payback period, accounting rate of return, and net...
Required information Problem 25-2A Analysis and computation of payback period, accounting rate of return, and net present value LO P1, P2, P3 [The following information applies to the questions displayed below.]    Most Company has an opportunity to invest in one of two new projects. Proje...