Skip to content

Instantly share code, notes, and snippets.

@mbszarek
Created June 12, 2017 11:13
Show Gist options
  • Save mbszarek/5632f7c73ff4f54dd6e4a090e2f48089 to your computer and use it in GitHub Desktop.
Save mbszarek/5632f7c73ff4f54dd6e4a090e2f48089 to your computer and use it in GitHub Desktop.
#include <fstream>
#include <iostream>
using namespace std;
int main(){
ifstream inputfile;
inputfile.open("dane.bin");
int students=0;
double math,cs;
math=cs=0.0;
string tmp;
while(!inputfile.eof()){
inputfile>>tmp;
inputfile>>tmp;
double a;
inputfile>>a;
cs+=a;
inputfile>>a;
math+=a;
getline(inputfile,tmp);
students++;
}
math/=students;
cs/=students;
inputfile.close();
inputfile.open("dane.bin");
ofstream outputfile;
outputfile.open("prymusi.txt");
string firstname,lastname;
double currcs,currmath;
while(!inputfile.eof()){
inputfile>>firstname>>lastname>>currcs>>currmath;
if(currcs>(1.2*cs) && currmath>(1.2*math)){
outputfile<<firstname<<" "<<lastname<<" "<<currcs<<" "<<currmath<<endl;
}
getline(inputfile,tmp);
}
outputfile.close();
inputfile.close();
inputfile.open("dane.bin");
int n;
cin>>n;
int i=0;
while(!inputfile.eof() && i<=n){
i++;
if(i==n){
inputfile>>firstname>>lastname>>currcs>>currmath;
}
getline(inputfile,tmp);
}
cout<<firstname<<" "<<lastname<<", CS Grade: "<<currcs<<", Math Grade: "<<currmath<<endl;
inputfile.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment