Skip to content

Commit

Permalink
20-12-23
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-stepien-dev committed Jan 3, 2024
1 parent 94b2d90 commit 7b686f3
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 20-12-23 /dane.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lkdfjiosadfa
fjkafijdaof
fjasifhusai
20 changes: 20 additions & 0 deletions 20-12-23 /ex.1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
fstream file("./dane.txt", ios::in | ios::out | ios::app);
if (!file.is_open()) {
cout << "Nie udalo sie otworzyc pliku" << endl;
return 1;
}

string line;
while (getline(file, line)) {
cout << line << endl;
}

file.close();
}
27 changes: 27 additions & 0 deletions 20-12-23 /ex.2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

int main() {
fstream file("imona_nazwisko.txt", ios::in | ios::out | ios::app);
if (!file.is_open()) {
cout << "Błąd otwarcia pliku" << endl;
return 1;
}

vector<string> first_names;
vector<string> last_names;
string firstName, last_name;

while (file >> firstName >> last_name) {
first_names.push_back(firstName);
last_names.push_back(last_name);
}

for (int i = 0; i < first_names.size(); i++) {
cout << first_names[i] << " " << last_names[i] << endl;
}
}
35 changes: 35 additions & 0 deletions 20-12-23 /ex.3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

int main() {
fstream file("imona_nazwisko.txt", ios::in | ios::out | ios::app);
if (!file.is_open()) {
cout << "Błąd otwarcia pliku" << endl;
return 1;
}

vector<string> first_names;
vector<string> last_names;
vector<string> grades;
string firstName, last_name, grade;

while (file >> firstName >> last_name >> grade) {
first_names.push_back(firstName);
last_names.push_back(last_name);
grades.push_back(grade);
}

float sum = 0;
for (int i = 0; i < first_names.size(); i++) {
cout << first_names[i] << " " << last_names[i] << " " << grades[i] << endl;
sum += stof(grades[i]);
}
cout << "Średnia: " << sum / grades.size() << endl;

file.close();
return 0;
}
4 changes: 4 additions & 0 deletions 20-12-23 /imona_nazwisko.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Anna Nowak
Jan Kowalski
Maria Wiśniewska
Piotr Kwiatkowski

0 comments on commit 7b686f3

Please sign in to comment.