私のC++クラスの課題を終了しようとしています。私は授業が私のために完了するのを探していませんが、私は難局に達しています。私の教授は電子メールに返信するのが最善ではありません。彼女は多くのことが続いているので理解できる。2つの並列配列を使用するC++
入力ファイルからデータを読み取るプログラムを作成しています。データには、従業員の姓、勤務時間数、1時間当たりの賃金率が含まれます。私の問題は、この情報を2つの並列配列に配置する必要があることです。私は自分自身で課題を終えることができる方法を見つけ出すことができれば、文字通りGoogleで検索し、見つけることができたが役に立たないすべての動画を見ました。
Here is the input data:
Smith 40 10.00
Jackson 25 8.00
Hill 35 10.00
Withers 28 7.25
Mills 32 7.55
Myers 50 10.25
Johnson 45 10.50
Mcclure 38 9.50
Miller 42 8.75
Mullins 40 10.75
更新:私のコードを編集し、私のプロジェクトの次のステップに進むために必要な結果に近づいています。私が持っているファイルからデータを読み込んで初期化する方法を編集しました。しかし、私の列の間には、奇妙な数列があります。
Smith
-9.25596e+61
-9.25596e+61
-9.25596e+61
40
-9.25596e+61
-9.25596e+61
-9.25596e+61
10.00
-9.25596e+61
-9.25596e+61
-9.25596e+61
Jackson
-9.25596e+61
7.25
-9.25596e+61
25
-9.25596e+61
-9.25596e+61
-9.25596e+61
8.00
-9.25596e+61
-9.25596e+61
-9.25596e+61
Hill
-9.25596e+61
-9.25596e+61
-9.25596e+61
35
-9.25596e+61
-9.25596e+61
-9.25596e+61
10.00
-9.25596e+61
-9.25596e+61
-9.25596e+61
私の改訂コードは以下のとおりです。
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
const int NOFROWS = 10;
const int NOFCOLS = 3;
void readFile(ifstream& infile, string X[], double y[][NOFCOLS]);
void print(ifstream&infile,ofstream& outfile, string x[], double y[] [NOFCOLS]);
int main()
{
//variables
string names[20];
double wages[NOFROWS][NOFCOLS];
ifstream incode;
ofstream outcode;
incode.open("employeeinformation.txt");
outcode.open("results.txt");
if (!incode)
{
cout << "No data" << endl;
system("pause");
return 1; //if loop to terminate program if unable to open file
}
cout << fixed << showpoint << setprecision(2) << endl;
readFile(incode, names, wages); //calls function readFile
print(incode,outcode, names, wages);
incode.close();
outcode.close();
system("pause");
return 0;
}
//Function to read file and input information into array.
void readFile(ifstream& infile, string x[], double y[][NOFCOLS])
{
//local variables, used as counters for while loop.
int r = 0;
int c = 0;
for (r = 0; r < NOFROWS; r++)
infile >> x[r]; // gets information from file for position
infile >> y[r][c];
//r++; //counter to increase position value
for (c = 0; c < NOFCOLS; c++)
{
infile >> y[c][r];
}
}
void print(ifstream&infile, ofstream& outfile, string x[], double y[] [NOFCOLS])
{
cout << setw(10) << "Names" << setw(10) << "hours" << setw(10) << "wages";
for (int r = 0; r < NOFROWS; r++) {
outfile << x[r] << " " << endl;
for (int c = 0; c < NOFCOLS; c++)
{
outfile << setw(10) << y[r][c] << " " << endl;
}
}
}
私はそれを撃つでしょう。フィードバックいただきありがとうございます。 – Dustin