Need help with input/output files and binary and linear searches, as well as selection sorts.

Just three questions, I have to input a binary, linear and selections sorts correctly. I have the format but I'm totally lost on what to do next.

1.) I have the input/output files there, but for some reason the file doesn't appear on the window search bar.

2.) I have the binary, linear, and selection sorts format, but after that I'm completely lost in what i have to do.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream> 
#include <string> 
#include <fstream> 
using namespace std;

int main()
{
	string payrate, name, hours, wages;
	string inputfile, outputfile;
	int empID;


	cout << "Enter the name of the input file. ";
	cin >> inputfile;
	cout << "Enter the name of the output file. ";
	cin >> outputfile;
	// open the input and output files

	cout << "Enter an employee number for your search. " << endl;
	cin >> empID;
	while (empID <= 0)
	{   //  Not valid
		cout << " Sorry, The number you entered is not valid " << endl;
		cin >> empID;
	}
	//  Initialize hours, payrate and wages     
	cout << "Employee " << empID << " worked " << hours << " hours " << " at " << payrate << " per hour and earned " << wages << endl;
	cout << "Processing completed. " << endl;

}
	
int searchList(const int list[], int numElems, int value)
{
	int index = 0;
	int position = 1;
	bool found = false;

	while (index < numElems && !found)
	{
		if (list[index] == value)
		{
			found = true;
			position = index;
		}
		index++;
	}
	return position;
}



	int binarySearch(const int array[], int size, int value);
	
	{	
		int first = 0,
			last = size - 1; 
			middle,
			position = -1,
			bool found = false;

		while (!found && first <= last)
		{
			middle = (first + last) / 2)
			if (array[middle] == value)

void selectionSort(int array[], int size)
			{
				int startScan, minIndex, minValue;
				for (startScarn = 0; startScan < (size - 1; startScarn++)
				{
					minIndex = startScan;
						minValue = array[startScan];
						for (int index = startScan + 1; index < size; index++)



			
	
		
	
1
2
3
4
cout << "Enter the name of the input file. ";
        cin >> inputfile;
        cout << "Enter the name of the output file. ";
        cin >> outputfile;

I stopped reading right here, use getline() for strings
The program still runs without it, i'm having issues with the input and output not opening from the window file onto note pad.
Hello Hen52,

i'm having issues with the input and output not opening from the window file onto note pad.
If I understand this correctly NO the program will not work directly with note pad. Now in the code you have not made any attempt to open the input or output files or the program to use. Line 17 has a comment of where to do this.

1.) I have the input/output files there, but for some reason the file doesn't appear on the window search bar.
Not sure what you mean here, but I can see no reason that the input/output files should be anywhere other than the directory that the program would be looking in to ind these files. That would be the same directory that the ".cpp" files are in.

Some hints to work on. You need code to open the input/output files, read the input file and some more variables defined in main when reading the input file. "searchList" is receiving an array that is not defined in main.

In "binarySearch" in the definition of the "int" variables you have a ";" where you need a "," and a "," where you need a ";".

The "selectionSort" is missing an opening { and several closing }s. Along with some code for the inner "for" loop.

Since your functions follow the main function prototypes are needed before main.

If you would post a sample, or if it is short the whole file, of your input file so everyone looking at these post know what you are working with. Otherwise it is just a guess at what is missing or not working with the progrm.

Hope that helps,

Andy
Topic archived. No new replies allowed.