我需要编写一个程序来清理两个有12个分数的数组并摆脱“分数”(分母为0)。我已经看过类似的问题了,但是我处于这样一个问题,即有三个主要问题似乎没有人或者没有得到解决。第一个是在main中声明新的(不是奖励)数组时,它要求我输入一个常量值;必须更改数组的大小才能使clean_data函数正常工作。 第二个是在main中调用clean_data时将“deno”和“num”标记为错误,表示“int *类型的参数与int **类型的参数不兼容”,最后一个表示函数clean_data不能将参数1从int [12]转换为int * []。 我一直在盯着这段代码3天,看着我教授的笔记和教科书,找不到解决方法。请帮忙。
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
//prototypes for functions
void read_data(int nume[], int deno[], int size);
void report_data(int nume[], int deno[], int size);
void report_overall_grade(int nume[], int deno[], int size);
//Data cleanup
void clean_data(int *nume[], int *deno[], int size, int *notBonusNum[], int *notBonusDen[], int &newSize);
int main()
{
//declare constat, arrays, and variables;
const int NUM_GRADES = 12;
int nume[NUM_GRADES];
int deno[NUM_GRADES];
int newSize = 12;
int notBonusNum[newSize];
int notBonusDen[newSize];
//call functions
read_data(nume, deno, 12);
cout << "Original scores: " << endl;
cout << fixed << showpoint << setprecision(1);
report_data(nume, deno, 12);
system("pause");
system("cls");
report_overall_grade(nume, deno, 12);
//Data cleanup
clean_data(nume, deno, 12, notBonusNum, notBonusDen, newSize);
cout << "There are " << newSize << " scores that aren't bonuses:" << endl;
report_data(notBonusNum, notBonusDen, newSize);
system("pause");
return 0;
}
//function definitions
void read_data(int nume[], int deno[], int size)
{
//open file
ifstream inputFile;
inputFile.open("scores.txt");
if (inputFile.fail())
{
cout << "File does not exist." << endl;
system("pause");
exit(1);
}
//read data
int count;
for (count = 0; count < size; count++)
{
inputFile >> nume[count];
inputFile >> deno[count];
}
inputFile.close();
}
void report_data(int nume[], int deno[], int size)
{
int count;
int number = 1;
for (count = 0; count < size; count++)
{
if (deno[count] > 0)
{
int numerator = nume[count];
int denominator = deno[count];
double percent = (double)numerator / denominator * 100;
cout << "Score " << number << " is " << numerator << " / " << denominator << " = " << percent << "%." << endl;
}
else
{
cout << "Score " << number << " is " << nume[count] << " / " << deno[count] << " = Bonus Points!" << endl;
}
number++;
}
}
void report_overall_grade(int nume[], int deno[], int size)
{
int count;
int totalNum = 0;
int totalDeno = 0;
double overallGrade;
for (count = 0; count < size; count++)
{
totalNum += nume[count];
totalDeno += deno[count];
}
cout << "Total points earned: " << totalNum << endl;
cout << "Total points possible: " << totalDeno << endl;
overallGrade = (double)totalNum / totalDeno * 100;
cout << "Overall grade: " << overallGrade << endl;
}
//Data cleanup
void clean_data(int *nume[], int *deno[], int size, int *notBonusNum[], int *notBonusDen[], int &newSize)
{
int count;
for (count = 0; count < size; count++)
{
int count2 = 0;
if (deno[count] != 0)
{
notBonusNum[count2] = nume[count];
notBonusDen[count2] = deno[count];
newSize--;
count2++;
}
}
}