Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <vector> #include <string> #include <algorithm> #in

ID: 3542953 • Letter: #

Question


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <fstream> //to read and write file
#include <cctype>

using namespace std;



int main()
{

    ifstream inputFile;    
    string password;
    string studentList;
    int i, index;
    vector<string> vectStudentList;    

            cout << "Please enter the password for the text file: ";
            getline (cin, password);
            
            inputFile.open(password.c_str());
            if (inputFile.fail())
            {
                cout << " Error for Opening File. " << endl;
                cout << "You have up to 03 times to enter the right password!" << endl;
                                 
                for (i = 1; i < 4; i++)
                {
                    cout << " Please enter the password for the text file again: ";
                    getline (cin, password); //validation 2- loop that allows user 3 times to enter password
                }
                exit (0);
             }
            while (inputFile >> (studentList))
            {
             vectStudentList.push_back (studentList);
            }
            cout << " The External Student List has the size of: " << vectStudentList.size() / 4 << endl << endl;

            cout << left << setw (20) << "First Name" << setw (20) << "Last Name" << setw (20) << "ID" << setw (20) << "Enrolled Class" << endl << endl;
            cout << "---------------------------------------------------------------------------" << endl;

                for (int index = 0; index < vectStudentList.size(); index++)
                {    
                    cout << left << setw (20) << vectStudentList[index] << setw (20) << setw (20) << setw (20);
                }      

    return 0;
        

Explanation / Answer

u should include a loop for displaying the student info ......i am displaying it in comment where u should include that loop ...


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <fstream> //to read and write file
#include <cctype>

using namespace std;



int main()
{

ifstream inputFile;
string password;
string studentList;
int i, index;
vector<string> vectStudentList;

cout << "Please enter the password for the text file: ";
getline (cin, password);

inputFile.open(password.c_str( ));
if (inputFile.fail())
{
cout << " Error for Opening File. " << endl;
cout << "You have up to 03 times to enter the right password!" << endl;

for (i = 1; i < 4; i++)
{
cout << " Please enter the password for the text file again: ";
getline (cin, password); //validation 2- loop that allows user 3 times to enter password
}
exit (0);
}
while (inputFile >> (studentList))
{
vectStudentList.push_back (studentList);
}


cout << " The External Student List has the size of: " << vectStudentList.size() / 4 << endl << endl;
// PLZ INSERT A LOOP TO DISPLAY EACH NAME IN STUDENT LIST
cout << left << setw (20) << "First Name" << setw (20) << "Last Name" << setw (20) << "ID" << setw (20) << "Enrolled Class" << endl << endl;
cout << "----------------------------- ------------------------------ ----------------" << endl;

//END OF LOOP

for (int index = 0; index < vectStudentList.size(); index++)
{
cout << left << setw (20) << vectStudentList[index] << setw (20) << setw (20) << setw (20);
}