Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit6f3051e2f5fe34de52b9e98c60128d18257a3b30 (patch)
Author
 Angel Dimitriev <angel_dimitriev@abv.bg>
2022-05-11 09:52:56 -0400
Committer
 GitHub <noreply@github.com>
2022-05-11 09:52:56 -0400
Filese425d554f74b49f4c3f1a306a77666d708285c88
Object-oriented_programming_FMI-6f3051e2f5fe34de52b9e98c60128d18257a3b30.tar
Object-oriented_programming_FMI-6f3051e2f5fe34de52b9e98c60128d18257a3b30.tar.gz
Object-oriented_programming_FMI-6f3051e2f5fe34de52b9e98c60128d18257a3b30.zip
Parent51e70a50eea68f12b70ddc7bdb3d74c79c59d7a6 (diff)
Update task3_not_done.cpp
1 files changed, 7 insertions, 11 deletions
-rw-r--r--Sem. 02/task3_not_done.cpp18
diff --git a/Sem. 02/task3_not_done.cpp b/Sem. 02/task3_not_done.cpp
index 481f989..0389268 100644
--- a/Sem. 02/task3_not_done.cpp
+++ b/Sem. 02/task3_not_done.cpp
@@ -33,13 +33,8 @@ struct StudentCollection
size_t studentsCount;
};
-size_t getLinesCount(const char* fileName)
+size_t getLinesCount(ifstream& file)
{
- ifstream file(fileName);
-
- if (!file.is_open())
- return 0;
-
size_t count = 0;
while (!file.eof())
@@ -48,8 +43,8 @@ size_t getLinesCount(const char* fileName)
file.getline(buff, capacity);
count++;
}
-
- file.close();
+
+ file.seekg(0, ios::beg); //resets the stream's get position.
return count;
@@ -105,9 +100,6 @@ void printStudent(const StudentRecord& st)
void initStudentCollection(StudentCollection& collection, const char* fileName)
{
- size_t linesCount = getLinesCount(fileName);
-
- size_t studentsCount = linesCount - 1;
ifstream file(fileName);
if (studentsCount == 0 || !file.is_open())
@@ -119,6 +111,10 @@ void initStudentCollection(StudentCollection& collection, const char* fileName)
return;
}
+ size_t linesCount = getLinesCount(fileName);
+
+ size_t studentsCount = linesCount - 1;
+
collection.data = new StudentRecord[studentsCount];
collection.studentsCount = studentsCount;