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
|
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#define endi cin.sync();cin.ignore();return 0
using namespace std;
int main(){
double nelm,telm,plus,times,percentage;
char c;
cout<<"NELM : ";
cin>>nelm;
cout<<"TELM : ";
cin>>telm;
plus=telm-nelm;
times=telm/nelm;
percentage=((100*telm)/nelm)-100;
cout<<endl<<endl;
cout<<"TELM = "<<plus<<" + NELM("<<nelm<<")"<<endl;
cout<<"TELM = "<<times<<" * NELM("<<nelm<<")"<<endl;
cout<<"TELM = "<<percentage<<"% + NELM("<<nelm<<")"<<endl;
fstream file("lm.txt",ios::in|ios::out|ios::app&ios::_Nocreate);
if(!file.is_open()){
cout<<"No file, create and add entry ? (Y/N) : ";
cin>>c;
if(c!='Y'&&c!='y'){
endi;
}
else{
fstream file("lm.txt",ios::out);
file<<nelm<<" "<<telm<<endl;
cout<<"Added.";
endi;
}
}
string str;
int i=0;
double avNelm=0,avTelm=0,tempNelm,tempTelm;
getline(file,str);
if(!str.empty() && isdigit(str.at(0))){
file.seekg(0,ios::beg);
}
while(file>>tempNelm && file>>tempTelm){
avNelm+=tempNelm;
avTelm+=tempTelm;
i++;
}
cout<<endl<<endl;
if(i==0){
cout<<"No or unvalid entries, add entry ? (Y/N) : ";
cin>>c;
if(c=='Y'|c=='y'){
file.clear();
file<<nelm<<" "<<telm<<endl;
cout<<"Added.";
}
endi;
}
cout<<"-------------------------------------------------------------------------------"<<endl<<endl<<endl;
avNelm/=i;
avTelm/=i;
cout<<"Averaga NELM = "<<avNelm<<endl;
cout<<"Average TELM = "<<avTelm<<endl<<endl;
double avPlus,avTimes,avPercentage;
avPlus=avTelm-avNelm;
avTimes=avTelm/avNelm;
avPercentage=((100*avTelm)/avNelm)-100;
cout<<"AvTELM = "<<avPlus<<" + AvNELM("<<avNelm<<")"<<endl;
cout<<"AvTELM = "<<avTimes<<" * AvNELM("<<avNelm<<")"<<endl;
cout<<"AvTELM = "<<avPercentage<<"% + AvNELM("<<avNelm<<")"<<endl;
cout<<endl<<endl<<"Add entry ? (Y/N) : ";
cin>>c;
if(c=='Y' || c=='y'){
file.clear();
file<<nelm<<" "<<telm<<endl;
cout<<"Added.";
}
cin.sync();
cin.ignore();
return 0;
}
|