请帮助,如果我可以做一些更改,但仍然坚持显示输出最终成绩:(对不起,我没有发布确切的问题(现在我做了)。 这是作业: 老师需要输入成绩并获得最终成绩
#include<iostream>
#include<iomanip>
using namespace std;
double FinalGrade;
const int students=3;
const int grades=5;
void FillGrades(int[][grades],int,int);
void PrintGrades(int[][grades],int,int);
void GetFinal(int[][grades],int,int);
int main()
{
double FinalGrade=0.0;
int CSC212[students][grades];
FillGrades(CSC212,students,grades);
PrintGrades(CSC212,students,grades);
double FinalValue[] = {0.05,0.1,0.2,0.25,0.4};
GetFinal(CSC212,students,grades);
system("pause");
return 0;
}
void FillGrades(int setofgrades[][grades],int pupils,int tests)
{
cout<<"Please enter grades for student 1 :"<<endl;
do{cout<<"Enter Grade 1 :"<<' '; cin>>setofgrades[0][0];}while(setofgrades[0][0]<0||setofgrades[0][0]>100);
do{cout<<"Enter Grade 2 :"<<' '; cin>>setofgrades[0][1];}while(setofgrades[0][1]<0||setofgrades[0][1]>100);
do{cout<<"Enter Grade 3 :"<<' '; cin>>setofgrades[0][2];}while(setofgrades[0][2]<0||setofgrades[0][2]>100);
do{cout<<"Enter Grade 4 :"<<' '; cin>>setofgrades[0][3];}while(setofgrades[0][3]<0||setofgrades[0][3]>100);
do{cout<<"Enter Grade 5 :"<<' '; cin>>setofgrades[0][4];}while(setofgrades[0][4]<0||setofgrades[0][4]>100);
cout<<"Please enter grades for student 2 :"<<endl;
do{cout<<"Enter Grade 1 :"<<' '; cin>>setofgrades[1][0];}while(setofgrades[1][0]<0||setofgrades[1][0]>100);
do{cout<<"Enter Grade 2 :"<<' '; cin>>setofgrades[1][1];}while(setofgrades[1][1]<0||setofgrades[1][1]>100);
do{cout<<"Enter Grade 3 :"<<' '; cin>>setofgrades[1][2];}while(setofgrades[1][2]<0||setofgrades[1][2]>100);
do{cout<<"Enter Grade 4 :"<<' '; cin>>setofgrades[1][3];}while(setofgrades[1][3]<0||setofgrades[1][3]>100);
do{cout<<"Enter Grade 5 :"<<' '; cin>>setofgrades[1][4];}while(setofgrades[1][4]<0||setofgrades[1][4]>100);
cout<<"Please enter grades for student 3 :"<<endl;
do{cout<<"Enter Grade 1 :"<<' '; cin>>setofgrades[2][0];}while(setofgrades[2][0]<0||setofgrades[2][0]>100);
do{cout<<"Enter Grade 2 :"<<' '; cin>>setofgrades[2][1];}while(setofgrades[2][1]<0||setofgrades[2][1]>100);
do{cout<<"Enter Grade 3 :"<<' '; cin>>setofgrades[2][2];}while(setofgrades[2][2]<0||setofgrades[2][2]>100);
do{cout<<"Enter Grade 4 :"<<' '; cin>>setofgrades[2][3];}while(setofgrades[2][3]<0||setofgrades[2][3]>100);
do{cout<<"Enter Grade 5 :"<<' '; cin>>setofgrades[2][4];}while(setofgrades[2][4]<0||setofgrades[2][4]>100);
}
void PrintGrades(int setofgrades[][grades],int pupils,int tests)
{
cout<<"Std"<<setw(5)<<"Att"<<setw(14)<<"Ass"<<setw(14)<<"EI"<<setw(14)<<"EII"<<setw(12)<<"FE"<<endl;
for(int i=0;i<pupils;i++){
cout<<i+1;
for(int j=0;j<tests;j++){
cout<<" "<<setofgrades[i][j]<<" ";
}
cout<<endl;
}
}
void GetFinal(int setofgrades[][grades],int pupils,int tests)
{
double a[] = {0.05,0.1,0.2,0.25,0.4};
for(int i=0;i<pupils;i++){
for(int j=0;j<tests;j++){
double FinalGrade=0.0;
FinalGrade+=setofgrades[i][j]*a[j];
}
}
cout<<"Std"<<setw(5)<<" Final Grade "<<endl;
for(int i=0;i<pupils;i++){
cout<<i+1;
double FinalGrade;
cout<<" "<<FinalGrade<<endl;
}
}
答案 0 :(得分:1)
尝试添加此行:
void GetFinal(int setofgrades[][grades],int pupils,int tests)
{
for(int i=0;i<pupils;i++){
for(int j=0;j<tests;j++)
double FinalGrade=(setofgrades[i][j]*0.05)
+(setofgrades[i][j]*0.1)
+(setofgrades[i][j]*0.2)
+(setofgrades[i][j]*0.25)
+(setofgrades[i][j]*0.4);
/* --> */ cout << "Final grade: " << FinalGrade << "\n";
}
}
您没有显示最终成绩,因为没有输出语句显示最终成绩变量的内容。
我不确定你是否想在循环中使用cout
。计算是针对每个循环执行的,但不会存储在任何地方。
循环内部看起来像:
void GetFinal(int setofgrades[][grades],int pupils,int tests)
{
for(int i=0;i<pupils;i++){
for(int j=0;j<tests;j++)
{
double FinalGrade=(setofgrades[i][j]*0.05)
+(setofgrades[i][j]*0.1)
+(setofgrades[i][j]*0.2)
+(setofgrades[i][j]*0.25)
+(setofgrades[i][j]*0.4);
/* --> */ cout << "Final grade: " << FinalGrade << "\n";
}
}
}
答案 1 :(得分:0)
我更改了一些代码,并添加了最终成绩计算的功能。有许多改进(从传递给函数的参数开始),但至少现在它可以工作。
$day = $timeCollection["mday"]; //day
$month = $timeCollection["mon"]; // month
$year = $timeCollection["year"]; // year
$hour = $timeCollection["hours"]; // hours
$minute = $timeCollection["minutes"]; // minutes
$seconds = $timeCollection["seconds"]; // seconds