gpt4 book ai didi

c++ - 警告 C4700 : uninitialized local variable

转载 作者:太空宇宙 更新时间:2023-11-04 16:18:36 26 4
gpt4 key购买 nike

<分区>

当我编译时它说“警告 C4700:使用了未初始化的局部变量‘count’”。我不确定为什么要这样说,我没有来这里,所以有人可以做我的作业。只是寻求有关此错误的帮助,我知道它与函数定义 ReadStudentData 或 Main 中有关。

谢谢

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

struct StudentType
{string studentName;
int testScore;//Between 0 and 100
char grade;


}student[20];

void PrintNameHeader(ostream& out);
bool OpenInputFile(ifstream& inFile, string& infilename ); //OPEN input file
void Pause();// Pause
void ReadStudentData(ifstream& infile, StudentType student[], int& );// Read student infp including first and last name and test score
void AssignGrades(StudentType student[], int);//assign grades to each student
int HighestScore(const StudentType student[], int );//Get the highest scores
void PrintNamesWithHighestScore(const StudentType student[], int);//Print name with highest Scores
void DisplayAllStudents(const StudentType student[], int);//Display all students
void GetLowHighRangeValues(int& , int&);//for example a student types 50 100 , it will get all students within that range
void DisplayStudentsInRange(const StudentType student[], int, int, int);// display students in that range
void SortStudentsByName(StudentType student[], int);// sort students by name
void SortStudentsByScore(StudentType student[], int);// sort students by test score highest to lowest


const int NUM_STUDENTS = 20;

int main()
{

ifstream infile;
string inFilename;

int count = 0;

StudentType student[NUM_STUDENTS];

int numStudents;


PrintNameHeader(cout);

OpenInputFile(infile,inFilename);

ReadStudentData(infile, student, numStudents);

AssignGrades(student, numStudents);

return 0;
}

//Function definitions

void PrintNameHeader(ostream& out)
{
//Display name header on screen
cout << "name" << endl;



}
bool OpenInputFile(ifstream& inFile, string& infilename)
{



cout << "Enter the name of the .txt file that you want to open for input.\n";
cout << "Do not put spaces in the file name ";
cin >> infilename;
cout << endl;


inFile.open(infilename.c_str());
if (inFile.fail())
{
cout << "Sorry, the input file " << infilename <<" was not found"<< endl;\
return false;
}

cout << "Input file " << infilename << " is open for reading.\n\n";
return true;
}

void Pause()
{
cout << endl;

cin.ignore(80, '\n');

cout<<"Please hit the enter key to continue...\n";

cin.get();

}

void ReadStudentData(ifstream& infile, StudentType student[], int& numstudents)
{
string firstName,
LastName,
testScore;

int count = 0;


if( infile)

for (int count; count < NUM_STUDENTS; count++)
{
cin >> firstName[count] >> LastName[count] >> testScore[count];

student[count].studentName = firstName + ", " + LastName;

}




numstudents = count;
cout << numstudents << endl;




}
void AssignGrades(StudentType student[], int numstudents)
{

int i;
for(i=0;i< NUM_STUDENTS;i++)
switch((int)(student[i].testScore/10))
{case 10:
case 9: student[i].grade='A';
break;
case 8: student[i].grade='B';
break;
case 7: student[i].grade='C';
break;
case 6: student[i].grade='D';
break;
default: student[i].grade='F';
break;
}

}
int HighestScore(const StudentType student[], int numstudents)
{
int max=0,i;

for(i=1;i<numstudents;i++)
{
if(student[i].testScore>student[max].testScore)
max=i;
}

return max;

}
void PrintNamesWithHighestScore(const StudentType student[], int numstudents)
{

}
void DisplayAllStudents(const StudentType student[], int numstudents)
{

}
void GetLowHighRangeValues(int& lowRange, int& highRange)
{

}

void DisplayStudentsInRange(const StudentType student[], int numStudents, int lownum, int highNum)
{

}

void SortStudentsByName(StudentType student[], int numStudents)
{

}

void SortStudentsByScore(StudentType student[], int numstudents)
{

}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com