-4
これはユーザーがテストスコアを入力して昇順にソートするプログラムです。しかし、配列記法をポインタ記法に変更するように求めています。以下は私のコードです。それは実行されますが、すべての配列の表記法を持っています。助けてください!このテストスコアプログラムでは配列表記の代わりにポインタ表記を使用しようとしていますが、私は固執しています
#include <iostream> //libraries
#include <iomanip>
using namespace std; //standard
void arrSelectSort(double*, int); //prototypes
void showArr(double* arr, int size) //array
{
for(int i = 0; i < size; ++i)
cout << setw(8) << arr[i];
}
int main() //main function No array boxes allowed
{
int numTests; //declare variable
cout << "How many test scores would you like to enter? " << endl; //ask user how many test scores they want to enter
cin >> numTests; //user input
cin.sync();
double* testScores = new double[numTests]; //pointer?
cout << "Enter the test scores below:" << endl; //ask user to input test scores
double sumTestScores = 0.0; //declare variable
for(int super = 0; super < numTests; ++super) //super is inheritance
{
cout << "Test Score " << (super + 1) //inheritance
<< ": " << endl;
cin >> testScores[super]; //Need to rid of this array notation
cin.sync();
sumTestScores += testScores[super]; //need to get rid of the array notation
}
cout << "You entered testScores: " << endl; //show results
cout << fixed << showpoint << setprecision(2); //show results
showArr(testScores, numTests);
cout << "The test scores sorted in ascending order are: " << endl; //show tests in ascending order
arrSelectSort(testScores, numTests); // show ascending
showArr(testScores, numTests);
cout << "The average score is " << sumTestScores/numTests << endl; //show average test score
delete [] testScores; // free memory
testScores = 0; // make testScores point to null
char c; //safe exit
cout << "Please hit any key and <ENTER> to continue..." << endl;
cin >> c; //user input
return 0; //exit
}
void arrSelectSort(double* arr, int size) //ascending order sort
{
int startScan; //declare variables
double minIndex; // declare variables
double minElem; // declare variables
for (startScan = 0; startScan < (size - 1); startScan++) //loop for scores
{
minIndex = startScan; //pointer?
minElem = arr[startScan]; //no array
for(int index = startScan + 1; index < size; index++) //ascending loop sort
{
if (arr[index] < minElem) //
{
minElem = arr[index]; //
minIndex = index; //
}
}
arr[(int)minIndex] = arr[startScan]; //
arr[startScan] = minElem;//
}
}
は//私は、配列を宣言し、ポインタにそれらを変更しようとしたが、それは //このプログラムの実行を実行しませんが、
'arr [i]'は '*(arr + i)'と同等です。 – Charles
トピック: 'double minIndex'には' int'sだけが割り当てられ、それが使われる唯一の時間にintにキャストされます。なぜこれは「ダブル」ですか?と 'int startScan; // declare variables'を実行すると、コメントに「No <削除済み>、Sherlock」が表示されます。応答。それは価値のあるものを加えず、実際にあなたは愚かに見えます。私は残忍な明白なものにコメントしないことをお勧めします。 – user4581301
"スーパーは継承"、errr ...、今何? – George