Modify the Student Line Up program described in Programming Challenge #13 so tha
ID: 642048 • Letter: M
Question
Modify the Student Line Up program described in Programming Challenge #13 so that it gets the names from a data file. Names should be read in until there is no more data to read. Data to test your program can be found in the LineUp.txt file. #13-A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be at the front of the line and Yolanda will be at the end. Write a program that prompts the user to enter a number between 1 and 25 for the number of students in the class, then loops to read that many names. Once all the names have been read in it reports which student would be at the front of the line and which one would be at the end of the line. You may assume there are no two students the same name. LineUp.txt(data): This file needs to be placed in the main project folder. Jackie Sam Tom Bill Mary Paul Zev Barb JohnExplanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream names;
names.open("P25.txt");
string firstInFile;
string lastInFile;
int i = 0;
string students;
i++;
names >> firstInFile;
names.close();
names.open("P25.txt");
while(names >> lastInFile)
{
i++;
}
names.close();
cout << firstInFile << endl;
cout << lastInFile << endl;
cout << i << endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.