Hi guys i'm new in C++..:icon_wink:
I have a homework that i need to pass soon and i need help because i only have 1 error and i'm staring at it for 2 hours:icon_cry: going back and forth to my book and came up with no solution:icon_sad:.
ok so heres the direction:).. (i need to follow those)
Q: did my codes follow the direction:?:?
if not then how can i fix it..
Thank you in advance for your help guys:icon_biggrin:
1) Use the following numbers as your input file.
5658845
4520125
7895122
8777541
8451277
1302850
8080152
4562555
5552012
5050552
7825877
1250255
1005231
6545231
3852085
7576651
7881200
4581002
-1these numbers should be read by your program and stored in a single dimention array of type long. assume there will be no more than 20 numbers, but your code should check that the user doesnt attempt to enter more. If an attemp is made to enter 21, print an error message on the screen and process only 20.
2) Print an appropriate program purpose and labels on the both screen output and file out put. Print the unsorted file, four number per file line.
3) Print sorted array on the output file, four numbers per line.
4) The user should enter a number from keyboard. Your program shoudk print a message on the screen saying whether or not the number is in the list. The binary search should be use to determine if the number is valid.
5) your design should include at least four functions in addition to the main func. The selection sort code and the code to perform a binary search should be two of the function.
6) Your name as a programmer should appear on the output file and on the screen
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int getinput(); //Function prototype
int binarySearch(long aray[], int, int); //function prototype
void selectionSort(ofstream & , char[] , long aray[], int); //Fuction prototype
void showarray(long aray[], int); //Function prototype
int main()
{
ifstream infile;
ofstream outfile;
char fileName[20]; //contains the filename on the storage device
char fileName1[20]; //contains filename of the output
int loop = 0;
const int SIZE = 20;
//int Arraysize[SIZE];
long singleary;
int count = 0, size2 = 0;
int number;
long aray[SIZE];
//Print program purpose
cout << "Process the Charged Account Numbers"<<endl<<endl;
//Print the name of the input from the file
cout << "Enter the name of the input file: ";
cin >> fileName;
infile.open(fileName);
//get files
infile >> singleary;
while(singleary != -1 && loop < SIZE)
{
count++;
aray[count -1] = singleary;
infile >> singleary;
}
//display the sorted numbers to the outfile
selectionSort(outfile, fileName, aray,loop);
//display unsorted array
showarray(aray, loop);
//enter a number from keyboard
number = getinput();
//display the result
if (number == -1)
{
cout << "That number doesnt exist" << endl;
}
else
cout << "That number is on the list" << endl;
//account number search
selectionSort( outfile, fileName, aray , loop);
for ( int i = 0; i < SIZE; i++)
outfile << aray[i];
//print programmer's name
cout << "Programmer:trowa\n";
//Close the files
infile.close();
outfile.close();
return 0;
}
//function 1
int getinput()
{
int numBer;
int count = 0;
int SIZE = 20;
cout << "Please enter a number to search: " <<endl;
cin >> numBer;
return numBer;
}
//function 2
void selectionSort(ofstream & outfile, char fileName1[20], long aray[], int loop)
{
cout << "Enter the name of the output file: ";
cin >> fileName1;
outfile.open(fileName1);
outfile << "The sorted Numbers" <<endl << endl;
{
int startScan, minIndex, minValue;
for(startScan = 0; startScan < loop; startScan++)
{
minIndex = startScan;
minValue = aray[startScan];
for (int index = startScan + 1; index < loop; index++)
{
if (aray[index] < minValue)
{
minValue = aray[index];
minIndex = index;
}
}
aray[minIndex] = aray[startScan];
aray[startScan]= minValue;
}
}
//print programmer's name
outfile << "\n\nProgrammer: trowa\n";
outfile.close();
}
Ok heres the error i'm getting for 2 hours :confused:
error C2109: subscript requires array or pointer type
it says its this one
selectionSort(outfile, fileName,aray[20],loop[20]); (in my codes) please take a look at my codes