이것은 내 CS1337 클래스 용이므로 주 기능 내에서 작업해야합니다. if/else 및 switch 문을 사용하여 루프 만 사용할 수는 없습니다.학생을위한 파일 사용 up-class 숙제
메모장에 읽을 이름 목록이 있어야하는 Lines.txt 파일을 만들었습니다. 최종 결과는 모든 이름을 읽고 콘솔 출력에 메시지를 표시해야합니다. 어떤 도움을 크게 감상 할 수 Question about my design for my C++ homework
:
나는 내가 온라인 여기 이전 항목 떨어져 내 코드를 기반으로.Lines.txt
Leslie
Ron
Tom
Gerry
Donna
Andy
April
Chris
Ben
Mark
콘솔 창 출력 :
Andy should be at the head of the line.
Tom should be at the end of the line.
내 코드 :
int main()
{
ifstream inputFile;
string filename;
string front, back, student;
int students = 10;
// Get the filename from the user.
cout << "Enter the filename: ";
cin >> filename;
// Open the file.
inputFile.open(filename.c_str());
// If the file successfully opened, process it.
if (inputFile)
{
/* A formula the sets each name entered to
the variables front and back*/
front = back = student;
// Read the numbers from the file and
// display them.
while (inputFile >> student)
{
for (int count = 1; count <= students; ++count)
{
// Create an if/else statement that decides which
// student name is alphabetically first and last
if (student < front)
front = student;
else if (student >= back)
back = student;
}
// Display the message showing which name is alphabetically first and last name
}
cout << endl
<< front << " should be at the head of the line." << endl
<< back << " should be at the end of the line." << endl;
// Close the file.
inputFile.close();
}
else
{
// Display an error message.
cout << "Error opening the file.\n";
}
return 0;
}
이 질문은 codereview.stackexchange.com에 – AShelly
AShelly의 권리를 속하기 때문에 오프 주제로 표시 그렇지 않으면 코드 검토가 퇴색합니다. –