Loop with multiple input to single output

I have to condense this list of 20 inFile.txt files to 1 output file. How do I do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 #include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

const double Homework_Weight = .55 ;
const double Midterm_Weight = .20;
const double Final_Weight  = .25;
const string Fill = "==========";
const string Ruler = "1234567890";

int main()
{

    ifstream inFile;
    ofstream outFile;

    string firstName, lastName, level;
    double homework1, homework2, homework3, homework4, homework5, homework6, homework7,   homework8 , homework9, homework10, homeworkAVG, midterm, finalExamGrade, finalGrade;

    string rulerLine = Ruler + Ruler + Ruler + Ruler + Ruler + Ruler ; 
    string fillLine = Fill + Fill + Fill + Fill + Fill + Fill;

    int absent , present; 

    
    

     inFile.open("inData.txt");
     inFile.open("inData2.txt");
     inFile.open("inData3.txt");
     inFile.open("inData4.txt");
     inFile.open("inData5.txt");
     inFile.open("inData6.txt");
     inFile.open("inData7.txt");
     inFile.open("inData8.txt");
     inFile.open("inData9.txt");
     inFile.open("inData10.txt");
     inFile.open("inData11.txt");
     inFile.open("inData12.txt");
     inFile.open("inData13.txt");
     inFile.open("inData14.txt");
     inFile.open("inData15.txt");
     inFile.open("inData16.txt");
     inFile.open("inData17.txt");
     inFile.open("inData18.txt");
     inFile.open("inData19.txt");
     inFile.open("inData20.txt");
     
     //outFile.open
     outFile.open("outData.txt");
    
    
     
    outFile << fixed << showpoint << setprecision(2);

    inFile >> firstName >> lastName >> level >> homework1 >> homework2 >> homework3 >> homework4 >> homework5 >> homework6 >> homework7 >> homework8 >> homework9 >> homework10 >> midterm >> finalExamGrade >> present >> absent;

    //algorithms;
    homeworkAVG = (homework1 + homework2 + homework3 + homework4 + homework5 + homework6 + homework7 + homework8 + homework9 + homework10) / 10;

    finalGrade = (homeworkAVG * Homework_Weight) + (midterm * Midterm_Weight) + (finalExamGrade * Final_Weight) ;

    //outputs;
    outFile << left;
    outFile << rulerLine << endl << endl;
    outFile << fillLine << endl;
    outFile << "|" << setw(10) << " Student" << "| " << setw(20) << lastName + "," + " "+ firstName;
    outFile << "|" << setw(13) << " Grade Level" << "| " << setw(10) << level << "|" << endl;

    outFile << fillLine << endl;

    outFile << "|" << left << setw(10) << " Present" << "|" <<
    setw(4) << right << setw(7) << present <<  " " << "-" << setw(6) <<
    (static_cast<double>(present) / static_cast<double>(present + absent)) * 100 << "% ";


    outFile << "|" << left << setw(10) << " Absent" << "|" << setw(4) << right << setw(8) << absent << " " << "-" << setw(6) <<
    (static_cast<double>(absent) / static_cast<double>(present + absent)) * 100 << "% | " << endl;

    outFile << fillLine << endl;
    outFile << "|" << setw(25) << left << " Homework" << setw(20)  << "| Average" << "|" << setw(12) << right << homeworkAVG << "|" << endl;
    outFile << fillLine << endl;
    outFile << "|" << setw(25) << left << " Assignment 1" << "|" << setw(19)  << right << homework1 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 2" << "|" << setw(19)  << right << homework2 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 3" << "|" << setw(19)  << right << homework3 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 4" << "|" << setw(19)  << right << homework4 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 5" << "|" << setw(19)  << right << homework5 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 6" << "|" << setw(19)  << right << homework6 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 7" << "|" << setw(19)  << right << homework7 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 8" << "|" << setw(19)  << right << homework8 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 9" << "|" << setw(19)  << right << homework9 << "|" << setw(13) << "|" << endl;
    outFile << "|" << setw(25) << left << " Assignment 10" << "|" << setw(19)  << right << homework10 << "|" << setw(13) << "|" << endl;

    outFile << fillLine << endl;
    outFile << "|" << setw(25) << left << " Midterm Grade:" << setw(20) << "|" << "|" << setw(12) << right << midterm << "|" << endl;

    outFile << fillLine << endl;
    outFile << "|" << setw(25) << left << " Final Exam Grade:" << setw(20) << "|" << "|" << setw(12) << right << finalExamGrade << "|" << endl;    
    
    outFile << fillLine << endl;
    outFile << "|" << setw(25) << left << " Course Grade:" << setw(20) << "|" << "|" << setw(12) << right << finalGrade << "|" << endl;

    outFile << fillLine << endl;

    // Close
    inFile.close();
    outFile.close();

    cout << "Progressing Complete!!!!!" << endl;

    return 0;
    
   
} 
You can't open all the input files at the same time, especially using only one ifstream variable. Instead, use a loop to process the files one at a time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
    const string outFileName = "outData.txt";

    // Open output file
    ofstream outFile(outFileName);
    if (!outFile)
    {
        cerr << "Can't open " << outFileName << '\n';
        return 1;
    }

    for (int i = 1; i <= 20; ++i)
    {
        // Build input filename
        string inFileName = "inData";
        if (i > 1) inFileName += to_string(i);
        inFileName += ".txt";

        // Open input file
        ifstream inFile(inFileName);
        if (!inFile)
        {
            cerr << "*** Can't open " << inFileName << '\n';
            return 1;
        }

        // Copy input file to output file
        for (string line; getline(inFile, line); )
            outFile << line << '\n';
    }
}

Whenever you find yourself creating a bunch of numbered variable names (like your homework variables), consider an array or vector. Remember that these need to be processed with a loop.
Hello Sunshine1209,

As I look over the code.

Lines 31 - 50 will not work the way that you are using them. Only 1 file can be associated with a file stream at a time. Line 31 will open the first file and lines 32 - 50 will be a problem when you try to use the same file stream.

You could start with:
1
2
3
4
5
std::string fileNames[]
{
    "inData.txt",
    "inData2.txt",
    // The rest of the file names. 


At the moment I am thinking about a while loop starting at line 58.

When you enter the while loop you could do: inFile(fileNames[idx]);, where "idx" is defined outside of the while loop, followed by checking that the file stream is open and ready, if (!inFile).
The next while loop would start at line 59 as: while(inFile >> firstName >> lastName >> level).

Since there are several homework grades I thinking about a for loop. Where you could read the "homework" grades, save them to the variables, and add them to a total to later compute the average then read the last fields in the file before any output to a new file.

For the output file is it for display or do you intend to use it as an input file later? It makes a difference on how you write to the file.

Here is a tip to makes things shorter:
1
2
3
4
5
6
7
8
9
const string Fill = "==========";

// followed by

string fillLine = Fill + Fill + Fill + Fill + Fill + Fill;

// Can be written as:

std::string fillLine(60, '=');

Much cleaner than all that extra work. This uses the fill constructor of "std::string". It comes in really handy.

When opening an input or output file stream always check that it is open:
1
2
3
4
5
    if (!inFile)
    {
         //return std::cerr << "\n\n     File " << std::quoted(inFileName) << " did not open.\n", 1;
        return std::cerr << "\n\n     File \"" << fileNames[idx] << "\" did not open.\n", 1;
    }


I do not know how easy it would be to post the input files, but it would help if you would post a sample of each file. This could be done in 1 group with something to show separation between the files. Or at least 1 or 2 files to work with. It is a great help when people do not have to guess at what the file might be.

Andy
Last edited on
Here is three of the inFiles

*inData.txt*
Peter Parker Senior 100 100 100 100 100 100 100 100 100 100
100.0
100
26
0


*inData2.txt*
Wade Wilson Junior 50 45 0 75 35 1 55 23 17 0
56
20
3
23


*inData3.txt*

Bruce Banner Senior 100 100 100 100 100 100 100 100 100 100
100
100
26
0


Hello Sunshine1209,

Thank you for the input files. Enough for testing.

dutch has a very nice approach for building the file names. Sorry I got my brain stuck on a different way before I saw it.

Have a look at this and see what you think:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <iomanip>
#include <string>

#include <fstream>

using namespace std;  // <--- Best not to use.

const double HOMEWORK_WEIGHT{ 0.55 };
const double MIDTERM_WEIGHT{ 0.20 };
const double FINAL_WEIGHT{ 0.25 };
const string FILL_LINE(60, '=');
const string RULER{ "1234567890" };

int main()
{
    int unsigned index{};

    const std::string fileNames[]
    {
        "inData.txt",   "inData2.txt",  "inData3.txt",  "inData4.txt",
        "inData5.txt",  "inData6.txt",  "inData7.txt",  "inData8.txt",
        "inData9.txt",  "inData10.txt", "inData11.txt", "inData12.txt",
        "inData13.txt", "inData14.txt", "inData15.txt", "inData16.txt",
        "inData17.txt", "inData18.txt", "inData19.txt", "inData20.txt"
    };

    ifstream inFile;
    ofstream outFile("outData.txt");

    if (!outFile)
    {
        return std::cerr<< "\n\n     File \"outData.txt\" did not open.\n", 1;
    }

    outFile << fixed << /*showpoint <<*/ setprecision(2);  // <--- Not required, but OK if you leave

    string firstName, lastName, level;
    double homeworkAVG{}, finalGrade{};  // <--- ALWAYS initialize all your variables.

    string rulerLine = RULER + RULER + RULER + RULER + RULER + RULER;
    //string fillLine = Fill + Fill + Fill + Fill + Fill + Fill;

    int absent{}, present{};  // <--- ALWAYS initialize all your variables.

    while (true)
    {
        ifstream inFile(fileNames[index]);

        if (!inFile)
        {
            std::cerr << "\n\n     File "<<std::quoted(fileNames[index]) <<" did not open. Or does not exist.\n\n";

            break;
        }

        while (inFile >> firstName >> lastName >> level)
        {
            double grades[14]{}, totalgrades{};

            for (unsigned idx = 0; idx < 14 && inFile >> grades[idx]; idx++)
            {
                if (idx < 9)
                {
                    totalgrades += grades[idx];
                }

            }
            //inFile >> grades[]1 >> grades[]2 >> grades[]3 >> grades[]4 >> grades[]5 >> grades[]6
            //    >> grades[]7 >> grades[]8 >> grades[]9 >> grades[]10 >> midterm >> finalExamGrade
            //    >> present >> absent;

            //algorithms;
            homeworkAVG = totalgrades / 10.0;
            //grades[]AVG = (grades[]1 + grades[]2 + grades[]3 + grades[]4 + grades[]5 + grades[]6 + grades[]7 + grades[]8 + grades[]9 + grades[]10) / 10;

            finalGrade = (homeworkAVG * HOMEWORK_WEIGHT) + (grades[10] * MIDTERM_WEIGHT) + (grades[11] * FINAL_WEIGHT);

            //finalGrade = (grades[]AVG * grades[]_Weight) + (midterm * MIDTERM_WEIGHT) + (finalExamGrade * FINAL_WEIGHT);

            //outputs;
            outFile
                << left
                << rulerLine << "  // <--- Is this really needed?\n"  // <--- Is this really needed?
                << FILL_LINE << "\n"
                << "|" << setw(10) << " Student" << "| " << setw(20) << lastName + "," + " " + firstName
                << "|" << setw(13) << " Grade Level" << "| " << setw(10) << level << "|" << endl
                << FILL_LINE << "\n"
                << "|" << left << setw(10) << " Present" << "|" <<
                setw(4) << right << setw(7) << grades[12] << " " << "-" << setw(6) <<
                (grades[12] / grades[12] + grades[13]) * 100.0 << "% ";


            outFile << "|" << left << setw(10) << " Absent" << "|" << setw(4) << right << setw(8) << grades[13] << " " << "-" << setw(6) <<
                (grades[13] / grades[12] + grades[13]) * 100.0 << "% | " << endl;

            outFile << FILL_LINE << endl;
            outFile << "|" << setw(25) << left << " Homework" << setw(20) << "| Average" << "|" << setw(12) << right << homeworkAVG << "|" << endl;
            outFile << FILL_LINE << endl;
            outFile << "|" << setw(25) << left << " Assignment 1" << "|" << setw(19) << right << grades[0] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 2" << "|" << setw(19) << right << grades[1] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 3" << "|" << setw(19) << right << grades[2] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 4" << "|" << setw(19) << right << grades[3] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 5" << "|" << setw(19) << right << grades[4] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 6" << "|" << setw(19) << right << grades[5] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 7" << "|" << setw(19) << right << grades[6] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 8" << "|" << setw(19) << right << grades[7] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 9" << "|" << setw(19) << right << grades[8] << "|" << setw(13) << "|" << endl;
            outFile << "|" << setw(25) << left << " Assignment 10" << "|" << setw(19) << right << grades[9] << "|" << setw(13) << "|" << endl;

            outFile << FILL_LINE << endl;
            outFile << "|" << setw(25) << left << " Midterm Grade:" << setw(20) << "|" << "|" << setw(12) << right << grades[10] << "|" << endl;

            outFile << FILL_LINE << endl;
            outFile << "|" << setw(25) << left << " Final Exam Grade:" << setw(20) << "|" << "|" << setw(12) << right << grades[11] << "|" << endl;

            outFile << FILL_LINE << endl;
            outFile << "|" << setw(25) << left << " Course Grade:" << setw(20) << "|" << "|" << setw(12) << right << finalGrade << "|\n";

            outFile << FILL_LINE << "\n\n";

        }

        // Close
        inFile.close();  // <--- This is required here.

        index++;
    }    
    
    //outFile.close();  // <--- Not required as the dtor will close the file when the function looses scope.

    cout << "Progressing Complete!!!!!" << endl;

    return 0;  // <--- Not required, but makes a good break point for testing.
}

I did not have a chance to change everything, but most if not all the "endl" can be replaced with the new line (\n) or save the "endl" for the very end.

Whether it is "cout" or "outFile" you do not need a "cout" or "outFile" and "endl" for each line. As I did with some of the code the insertion operator (<<) can chain together much of the information. And when several lines of text are in double quotes it is considered just 1 big string.

After reading "level" I created an array to hold all the numeric variables left. You do not have to take it as far as I did. You can make the array large enough for just the homework grades.

When you create a constant variable it does help to use all capital letters for the name, but it is not required.

If there is anything that you do not understand let me know.

Andy
Hello Sunshine1209,

The output the program produces is:

123456789012345678901234567890123456789012345678901234567890  // <--- Is this really needed?
============================================================
| Student  | Parker, Peter       | Grade Level | Senior    |
============================================================
| Present  |  26.00 -100.00% | Absent   |    0.00 -  0.00% | 
============================================================
| Homework                | Average           |       90.00|
============================================================
| Assignment 1            |             100.00|            |
| Assignment 2            |             100.00|            |
| Assignment 3            |             100.00|            |
| Assignment 4            |             100.00|            |
| Assignment 5            |             100.00|            |
| Assignment 6            |             100.00|            |
| Assignment 7            |             100.00|            |
| Assignment 8            |             100.00|            |
| Assignment 9            |             100.00|            |
| Assignment 10           |             100.00|            |
============================================================
| Midterm Grade:          |                   |      100.00|
============================================================
| Final Exam Grade:       |                   |      100.00|
============================================================
| Course Grade:           |                   |       94.50|
============================================================

123456789012345678901234567890123456789012345678901234567890  // <--- Is this really needed?
============================================================
| Student  | Navarre, Etienne    | Grade Level | 1         |
============================================================
| Present  |  25.00 -600.00% | Absent   |    5.00 -520.00% | 
============================================================
| Homework                | Average           |       80.30|
============================================================
| Assignment 1            |              90.00|            |
| Assignment 2            |              89.00|            |
| Assignment 3            |              95.00|            |
| Assignment 4            |              85.00|            |
| Assignment 5            |              88.00|            |
| Assignment 6            |              80.00|            |
| Assignment 7            |              90.00|            |
| Assignment 8            |              92.00|            |
| Assignment 9            |              94.00|            |
| Assignment 10           |             100.00|            |
============================================================
| Midterm Grade:          |                   |       98.00|
============================================================
| Final Exam Grade:       |                   |       99.00|
============================================================
| Course Grade:           |                   |       88.52|
============================================================

123456789012345678901234567890123456789012345678901234567890  // <--- Is this really needed?
============================================================
| Student  | Wilson, Wade        | Grade Level | Junior    |
============================================================
| Present  |   3.00 -2400.00% | Absent   |   23.00 -3066.67% | 
============================================================
| Homework                | Average           |       30.10|
============================================================
| Assignment 1            |              50.00|            |
| Assignment 2            |              45.00|            |
| Assignment 3            |               0.00|            |
| Assignment 4            |              75.00|            |
| Assignment 5            |              35.00|            |
| Assignment 6            |               1.00|            |
| Assignment 7            |              55.00|            |
| Assignment 8            |              23.00|            |
| Assignment 9            |              17.00|            |
| Assignment 10           |               0.00|            |
============================================================
| Midterm Grade:          |                   |       56.00|
============================================================
| Final Exam Grade:       |                   |       20.00|
============================================================
| Course Grade:           |                   |       32.76|
============================================================

123456789012345678901234567890123456789012345678901234567890  // <--- Is this really needed?
============================================================
| Student  | Dragon, Saphira     | Grade Level | Senior    |
============================================================
| Present  |  27.00 -400.00% | Absent   |    3.00 -311.11% | 
============================================================
| Homework                | Average           |       81.90|
============================================================
| Assignment 1            |              92.00|            |
| Assignment 2            |              91.00|            |
| Assignment 3            |              97.00|            |
| Assignment 4            |              87.00|            |
| Assignment 5            |              90.00|            |
| Assignment 6            |              82.00|            |
| Assignment 7            |              92.00|            |
| Assignment 8            |              92.00|            |
| Assignment 9            |              96.00|            |
| Assignment 10           |             100.00|            |
============================================================
| Midterm Grade:          |                   |       97.00|
============================================================
| Final Exam Grade:       |                   |       98.00|
============================================================
| Course Grade:           |                   |       88.95|
============================================================

123456789012345678901234567890123456789012345678901234567890  // <--- Is this really needed?
============================================================
| Student  | Banner, Bruce       | Grade Level | Senior    |
============================================================
| Present  |  26.00 -100.00% | Absent   |    0.00 -  0.00% | 
============================================================
| Homework                | Average           |       90.00|
============================================================
| Assignment 1            |             100.00|            |
| Assignment 2            |             100.00|            |
| Assignment 3            |             100.00|            |
| Assignment 4            |             100.00|            |
| Assignment 5            |             100.00|            |
| Assignment 6            |             100.00|            |
| Assignment 7            |             100.00|            |
| Assignment 8            |             100.00|            |
| Assignment 9            |             100.00|            |
| Assignment 10           |             100.00|            |
============================================================
| Midterm Grade:          |                   |      100.00|
============================================================
| Final Exam Grade:       |                   |      100.00|
============================================================
| Course Grade:           |                   |       94.50|
============================================================

L46. There is no loop termination other than failing to open a file. Hence index could exceed the bound of fileNames. This loop could be based upon the size of fileNames.

Is L63 correct?

L91
(grades[12] / grades[12] + grades[13]) * 100.0

Do you mean 1 + grades[13]? or
(grades[12] / (grades[12] + grades[13])) * 100.0

L100-109 could be a loop.

Another way to deal with the file names would be use c++17 std::filesystem to iterate all filenames with the format inData*.txt

Perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

const double HOMEWORK_WEIGHT {0.55};
const double MIDTERM_WEIGHT {0.20};
const double FINAL_WEIGHT {0.25};
const std::string FILL_LINE(60, '=');
const std::string RULER {"1234567890"};
const std::string rulerLine {RULER + RULER + RULER + RULER + RULER + RULER};

const std::string fileNames[] {
	"inData.txt",   "inData2.txt",  "inData3.txt",  "inData4.txt",
	"inData5.txt",  "inData6.txt",  "inData7.txt",  "inData8.txt",
	"inData9.txt",  "inData10.txt", "inData11.txt", "inData12.txt",
	"inData13.txt", "inData14.txt", "inData15.txt", "inData16.txt",
	"inData17.txt", "inData18.txt", "inData19.txt", "inData20.txt"
};

int main()
{
	std::ofstream outFile("outData.txt");

	if (!outFile)
		return std::cerr << "\n\n     File \"outData.txt\" did not open.\n", 1;

	outFile << std::fixed << std::setprecision(2);

	for (size_t index {}; index < std::size(fileNames); ++index) {
		std::ifstream inFile(fileNames[index]);

		if (!inFile) {
			std::cerr << "\nFile " << std::quoted(fileNames[index]) << " did not open. Or does not exist.\n";
			continue;
		}

		std::string firstName, lastName, level;

		while (inFile >> firstName >> lastName >> level) {
			double grades[14] {}, totalgrades {};

			for (unsigned idx = 0; idx < 14 && inFile >> grades[idx]; ++idx)
				if (idx < 10)
					totalgrades += grades[idx];

			const auto homeworkAVG {totalgrades / 10.0};
			const auto finalGrade {(homeworkAVG * HOMEWORK_WEIGHT) + (grades[10] * MIDTERM_WEIGHT) + (grades[11] * FINAL_WEIGHT)};

			outFile
				<< std::left
				<< rulerLine << '\n'	// <--- Is this really needed?
				<< FILL_LINE << "\n"
				<< "|" << std::setw(10) << " Student" << "| " << std::setw(20) << lastName + ", " + firstName
				<< "|" << std::setw(13) << " Grade Level" << "| " << std::setw(10) << level << "|\n"
				<< FILL_LINE << "\n"
				<< "|" << std::left << std::setw(10) << " Present" << "|"
				<< std::setw(4) << std::right << std::setw(7) << grades[12] << " -" << std::setw(8) <<
				(grades[12] / (grades[12] + grades[13])) * 100.0 << "% ";

			outFile << "|" << std::left << std::setw(8) << " Absent" << "|" << std::setw(4) << std::right << std::setw(8) << grades[13] << " -" << std::setw(6) <<
				(grades[13] / (grades[12] + grades[13])) * 100.0 << "% | \n";

			outFile << FILL_LINE << '\n';
			outFile << "|" << std::setw(25) << std::left << " Homework" << "|" << std::setw(19) << std::right << "Average" << "|" << std::setw(12) << std::right << homeworkAVG << "|\n";
			outFile << FILL_LINE << '\n';

			for (size_t a = 1; a <= 10; ++a)
				outFile << "|" << " Assignment " << std::setw(13) << std::left << a << "|" << std::setw(19) << std::right << grades[a - 1] << "|" << std::setw(13) << "|" << '\n';

			outFile << FILL_LINE << '\n';
			outFile << "|" << std::setw(25) << std::left << " Midterm Grade:" << std::setw(20) << "|" << "|" << std::setw(12) << std::right << grades[10] << "|\n";

			outFile << FILL_LINE << '\n';
			outFile << "|" << std::setw(25) << std::left << " Final Exam Grade:" << std::setw(20) << "|" << "|" << std::setw(12) << std::right << grades[11] << "|\n";

			outFile << FILL_LINE << '\n';
			outFile << "|" << std::setw(25) << std::left << " Course Grade:" << std::setw(20) << "|" << "|" << std::setw(12) << std::right << finalGrade << "|\n";

			outFile << FILL_LINE << "\n\n";
		}
	}

	std::cout << "Progressing Complete!!!!!\n";
}


PS. This is why I don't like stream insertion formatting! Oh to use C++20 format!
Last edited on
Topic archived. No new replies allowed.