Issue with file reader(reads correctly from one file, but not the other.)

So for this code I have to set it up so that it reads the first ten lines from a file, the last ten lines from a file, and then displays all lines from a file 10 at a time. My issue is that the first text document it's reading from has 26 lines and the second text document only has 8. The second text document displays correctly with no issue but with the first one it only displays all lines from the file 10 at a time. I'll provide the code below:
.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;
class Assignment11_FileReader
{
private:
	string filename;
	int numrecords;

public:
	void setFilename(string _filename);
	void displayFirst10records();
	void displayLast10records();
	void displayAllRecords();
	int getNumRrecords();
};


.cpp file
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
136
137
138
139
140
141
142
143
144
145
146
  #include "Assignment11_FileReader.h"

void Assignment11_FileReader::setFilename(string _name)
{
	numrecords = 0;
	string oneRec;
	filename = _name;
	ifstream ifile(_name);

	if (!ifile)
	{
		cout << "File open failed..program terminating..\n";
		system("pause");
		exit(0);
	}
	getline(ifile, oneRec);
	while (!ifile.eof())
	{
		numrecords++;
		getline(ifile, oneRec);
	}
	ifile.close();
}
int Assignment11_FileReader::getNumRrecords()
{
	return numrecords;
}
void Assignment11_FileReader::displayFirst10records()
{

	ifstream ifile(filename);
	int lines = 0;
	string arec;

	getline(ifile, arec);

	//Check if numrecords are less than 10
	//Then print total lines to console
	if (numrecords<10)
	{
		cout << "\n" << filename
			<< " ----- First 10 records in file -----\n";
		while (!ifile.eof())
		{
			cout << arec << endl;
			getline(ifile, arec);
		}
		cout << "The file has been displyed\n";
	}
	else
	{
		//Check if numrecords are more than 10
		//Then pause the program output on concosle
		//and pause the output on for each 10 lines
		lines = 0;
		while (!ifile.eof())
		{
			//reset lines to zero for lines=10
			if (lines == 10)
			{
				cout << endl;
				//pause the output on for each 10 lines
				system("pause");
				lines = 0;
			}
			cout << arec << endl;
			lines++;
			getline(ifile, arec);
		}
	}
	cout << "\n----------------------------------\n";
	ifile.close();

}
void Assignment11_FileReader::displayLast10records()
{

	ifstream ifile(filename/*.c_str()*/);
	int lines = 0;
	string arec;

	getline(ifile, arec);

	//Check if numrecords are less than 10
	//Then print total lines to console
	if (numrecords<10)
	{
		cout << "\n" << filename
			<< " ----- Last 10 records in file -----\n";
		while (!ifile.eof())
		{
			cout << arec << endl;
			getline(ifile, arec);
		}
		cout << "The file has been displyed\n";
	}
	else
	{
		//Check if numrecords are more than 10
		//Then pause the program output on concosle
		//and pause the output on for each 10 lines
		lines = 0;
		while (!ifile.eof())
		{
			//reset lines to zero for lines=10
			if (lines == 10)     
			{
				cout << endl;
				//pause the output on for each 10 lines
				system("pause");
				lines = 0;
			}
			cout << arec << endl;
			lines++;
			getline(ifile, arec);
		}
	}
	cout << "\n----------------------------------\n";
	ifile.close();

}
void Assignment11_FileReader::displayAllRecords()
{
	ifstream ifile(filename);
	int lines = 0;
	string arec;

	cout << filename << "----- All records in file ------\n\n";

	getline(ifile, arec);
	while (!ifile.eof())
	{
		if (lines >= 19)
		{
			cout << endl;
			system("pause");
			lines = 0;
		}
		cout << arec << endl;
		lines++;
		getline(ifile, arec);
	}

	cout << "\n----------------------------------\n";
	ifile.close();
}



and finally, the tester
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
  #include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
#include "Assignment11_FileReader.h"
void display_file(string fname);
int main()
{
	display_file("assignment11_A.txt");
	display_file("assignment11_B.txt");

	system("pause");
	return 0;
}
void display_file(string fname)
{
	Assignment11_FileReader myfile;

	myfile.setFilename(fname);
	cout << "\n" << fname << " :  # of records in file = "
		<< myfile.getNumRrecords() << "\n";

	myfile.displayFirst10records();

	myfile.displayLast10records();

	myfile.displayAllRecords();
}


This is what it should output:

Assignment11_A.txt : # of records in file = 26

Assignment11_A.txt: FIRST 10 records in file

A programming language is an artificial language designed
to communicate instructions to a machine, particularly
a computer. Programming languages can be used to create
programs that control the behavior of a machine and/or to
express algorithms precisely.
The earliest programming languages predate the invention
of the computer, and were used to direct the behavior of
machines such as Jacquard looms and player pianos.
Thousands of different programming languages have been
created, mainly in the computer field, with many being

-------------


Assignment11_A.txt: LAST 10 records in file

into the two components of syntax (form) and semantics (meaning).
Some languages are defined by a specification document (for example,
the C programming language is specified by an ISO Standard),
while other languages, such as Perl 5 and earlier, have a
dominant implementation that is used as a reference.
The term computer language is sometimes used interchangeably
with programming language.However, the usage of both
terms varies among authors, including the exact scope of each.
One usage describes programming languages as a subset
of computer languages.

-------


Assignment11_A.txt: ALL records in the file

A programming language is an artificial language designed
to communicate instructions to a machine, particularly
a computer. Programming languages can be used to create
programs that control the behavior of a machine and/or to
express algorithms precisely.
The earliest programming languages predate the invention
of the computer, and were used to direct the behavior of
machines such as Jacquard looms and player pianos.
Thousands of different programming languages have been
created, mainly in the computer field, with many being

Press any key to continue . . .ENTER
created every year. Most programming languages describe
computation in an imperative style, i.e., as a sequence
of commands, although some languages, such as those that
support functional programming or logic programming, use
alternative forms of description.
The description of a programming language is usually split
into the two components of syntax (form) and semantics (meaning).
Some languages are defined by a specification document (for example,
the C programming language is specified by an ISO Standard),
while other languages, such as Perl 5 and earlier, have a

Press any key to continue . . .ENTER
dominant implementation that is used as a reference.
The term computer language is sometimes used interchangeably
with programming language.However, the usage of both
terms varies among authors, including the exact scope of each.
One usage describes programming languages as a subset
of computer languages.

-----


Assignment11_B.txt : # of records in file = 8

Assignment11_B.txt: FIRST 10 records in file

This introductory course in C++ programming
includes object-oriented, event-driven,
interactive programming techniques. Topics include
data types, pointers, arrays, stacks, recursion,
string processing, searching and sorting
algorithms, classes and objects, references
and memory addresses, scope, streams and files,
and graphics.

-------


Assignment11_B.txt: LAST 10 records in file

This introductory course in C++ programming
includes object-oriented, event-driven,
interactive programming techniques. Topics include
data types, pointers, arrays, stacks, recursion,
string processing, searching and sorting
algorithms, classes and objects, references
and memory addresses, scope, streams and files,
and graphics.

-------


Assignment11_B.txt: ALL records in the file with line numbers

This introductory course in C++ programming
includes object-oriented, event-driven,
interactive programming techniques. Topics include
data types, pointers, arrays, stacks, recursion,
string processing, searching and sorting
algorithms, classes and objects, references
and memory addresses, scope, streams and files,
and graphics.



Like I said above, the Assignment11_B works with no issue, it's the Assignment11_A that has issues.
Topic archived. No new replies allowed.