C++ 文件无法将准确数据写入文本文件 //我叫克里斯·萨拉扎,这是作业7。本课程是升级的分级课程 #包括 #包括 #包括 #包括 使用名称空间std; 康斯特国际学生=100; 结构studentType { 字符串fname; 字符串名称; int test1; int test2; int test3; int test4; 双倍平均; 煤焦品位; }; 无效记录(studentType students[]); int readData(studentType students[]); 双getStudentAverageGrade(studentType aStudent); 煤质等级(双倍平均); 无效sortRecords(studentType students[],int totalStudents); 无效记录(studentType和aStudent、studentType和Btudent); 无效书面记录(studentType students[],int totalStudents); 空抽绳(流和流、字符、内部宽度); 无效检查记录(studentType students[],int totalStudents); int findMax(int,int); int findMin(int,int); int main(int argc,字符**argv) { 学生总数=0; 学生型学生[学生]; 教育记录(学生); totalStudents=读取数据(学生); 检查记录(学生、学生总数); 分类记录(学生、学生总数); cout>students[i].test1>>students[i].test2>>students[i].test3>>students[i].test4; 如果(!fin) 打破 学生[i]。平均值=getStudentAverageGrade(学生[i]); 学生[i]。成绩=getGrade(学生[i]。平均分); i+=1; } fin.close(); 返回i; } 无效书面记录(studentType students[],int totalStudents) { 字符串文件名; int i=0; 流式流量计; cout文件名; fout.open(文件名); while(fout&i
您的函数声明:C++ 文件无法将准确数据写入文本文件 //我叫克里斯·萨拉扎,这是作业7。本课程是升级的分级课程 #包括 #包括 #包括 #包括 使用名称空间std; 康斯特国际学生=100; 结构studentType { 字符串fname; 字符串名称; int test1; int test2; int test3; int test4; 双倍平均; 煤焦品位; }; 无效记录(studentType students[]); int readData(studentType students[]); 双getStudentAverageGrade(studentType aStudent); 煤质等级(双倍平均); 无效sortRecords(studentType students[],int totalStudents); 无效记录(studentType和aStudent、studentType和Btudent); 无效书面记录(studentType students[],int totalStudents); 空抽绳(流和流、字符、内部宽度); 无效检查记录(studentType students[],int totalStudents); int findMax(int,int); int findMin(int,int); int main(int argc,字符**argv) { 学生总数=0; 学生型学生[学生]; 教育记录(学生); totalStudents=读取数据(学生); 检查记录(学生、学生总数); 分类记录(学生、学生总数); cout>students[i].test1>>students[i].test2>>students[i].test3>>students[i].test4; 如果(!fin) 打破 学生[i]。平均值=getStudentAverageGrade(学生[i]); 学生[i]。成绩=getGrade(学生[i]。平均分); i+=1; } fin.close(); 返回i; } 无效书面记录(studentType students[],int totalStudents) { 字符串文件名; int i=0; 流式流量计; cout文件名; fout.open(文件名); while(fout&i,c++,unresolved-external,C++,Unresolved External,您的函数声明: //My name is Chris Salazar and this is Assignment 7. This program is an upgraded grading program #include <iostream> #include <fstream> #include <string> #include <iomanip> using namesp
//My name is Chris Salazar and this is Assignment 7. This program is an upgraded grading program
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int STUDENTS = 100;
struct studentType
{
string fname;
string lname;
int test1;
int test2;
int test3;
int test4;
double average;
char grade;
};
void initRecords(studentType students[]);
int readData(studentType students[]);
double getStudentAverageGrade(studentType aStudent);
char getGrade(double average);
void sortRecords(studentType students[], int totalStudents);
void swapRecords(studentType& aStudent, studentType& bStudent);
void writeRecords(studentType students[], int totalStudents);
void drawLine(ofstream& fout, char ch, int width);
void checkRecords(studentType students[], int totalStudents);
int findMax(int, int);
int findMin(int, int);
int main(int argc,char** argv)
{
int totalStudents = 0;
studentType students[STUDENTS];
initRecords(students);
totalStudents = readData(students);
checkRecords(students, totalStudents);
sortRecords(students, totalStudents);
cout << "after sorting..." << endl;
checkRecords(students, totalStudents);
writeRecords(students, totalStudents);
cout << "Done!" << endl;
system("pause");
return 0;
}
int readData(studentType students[])
{
ifstream fin;
string fileName;
int i;
cout << "Enter filename: ";
cin >> fileName;
fin.open(fileName);
//if (!fin)
//{
// cout << "FILE NOT PRESENT" << endl;
// cin.get();
// cin.get();
// exit(0);
//}
i = 0;
while (fin && i < STUDENTS)
{
fin >> students[i].fname >> students[i].lname >> students[i].test1 >> students[i].test2 >> students[i].test3 >> students[i].test4;
if (!fin)
break;
students[i].average = getStudentAverageGrade(students[i]);
students[i].grade = getGrade(students[i].average);
i += 1;
}
fin.close();
return i;
}
void writeRecords(studentType students[], int totalStudents)
{
string fileName;
int i = 0;
ofstream fout;
cout << "Enter a file name to write to: " << endl;
getline(cin, fileName);
cin >> fileName;
fout.open(fileName);
while (fout && i < STUDENTS)
{
fout << STUDENTS << students[11].fname << " ";
fout << STUDENTS << students[11].lname << " ";
fout << STUDENTS << students[11].test1 << " ";
fout << STUDENTS << students[11].test2 << " ";
fout << STUDENTS << students[11].test3 << " ";
fout << STUDENTS << students[11].test4 << " ";
//<< students[i].lname << students[i].test1 << students[i].test2 << students[i].test3 << students[i].test4;
i += 1;
}
}
与您的函数定义不匹配:
void sortRecords(studentType students[], int totalStudents);
谢谢,我真不敢相信我没听清楚。可能是重复的
void sortRecords(studentType students, int totalStudents[])