chore: Lab06
This commit is contained in:
36
lab06/01.cpp
Normal file
36
lab06/01.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
|
||||
fstream f;
|
||||
|
||||
f.open("examene.txt", ios_base::in);
|
||||
|
||||
if(!f.is_open()){
|
||||
cout<<"Error: file does not exist";
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sum=0;
|
||||
for(int i=0; i<6; i++){
|
||||
int buff;
|
||||
f>>buff;
|
||||
sum+=buff;
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
f.open("media.txt", ios_base::out);
|
||||
|
||||
double avg = (double)sum / 6;
|
||||
|
||||
f<<avg;
|
||||
|
||||
f.close();
|
||||
|
||||
return 0;
|
||||
}
|
66
lab06/02.cpp
Normal file
66
lab06/02.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
class Student{
|
||||
public:
|
||||
string nume, prenume, grupa;
|
||||
string stringify(){
|
||||
return nume+" "+prenume+" "+grupa;
|
||||
}
|
||||
};
|
||||
|
||||
bool studentCompare(const Student a, const Student b){
|
||||
if(a.nume == b.nume){
|
||||
if(a.prenume <= b.prenume){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(a.nume <= b.nume){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
|
||||
fstream f;
|
||||
|
||||
f.open("an.txt", ios_base::in);
|
||||
if(!f.is_open()){
|
||||
cout<<"Error: file does not exist";
|
||||
return 1;
|
||||
}
|
||||
|
||||
vector<Student> v;
|
||||
|
||||
string buff;
|
||||
while(f>>buff){
|
||||
Student tmp;
|
||||
tmp.nume = buff;
|
||||
f>>tmp.prenume;
|
||||
f>>tmp.grupa;
|
||||
v.push_back(tmp);
|
||||
}
|
||||
f.close();
|
||||
|
||||
sort(v.begin(), v.end(), studentCompare);
|
||||
|
||||
f.open("an_sort.txt", ios_base::out);
|
||||
for(vector<Student>::iterator it = v.begin(); it < v.end(); it++){
|
||||
f<<it->stringify();
|
||||
f<<"\n";
|
||||
}
|
||||
f.close();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user