T
titan0111
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
float in;
float totalsfin;
char date[6];
static int validcount;
static int invalidcount;
public:
void readdata(ifstream& infile)
{
infile>> ft >> in >> date;
}
void writedata(ofstream& outfile)
{
outfile<< ft << in << date;
}
void updatevalidcount()
{
validcount++;
}
void updateinvalidcount()
{
invalidcount++;
}
void calctotalsf()
{
totalsfin += float(ft)*12 + in;
}
int getft()
{return ft;}
float getin()
{return in;}
char* getdate()
{return date;}
int getvalidcount()
{return validcount;}
int getinvalidcount()
{return invalidcount;}
int operator == (char[]);
char datavalid();
void writetotalsf(ofstream& outfile);
};
int snowfall:perator == (char sf[])
{
return (strcmp(date, sf) == 0) ? 1 : 0;
}
char snowfall::datavalid()
{
char valid;
if ((ft >= 0) && (in >= 0.0f))
valid = 'T';
else
valid = 'F';
return valid;
}
void snowfall::writetotalsf(ofstream& outfile)
{
int totalsfft = 0;
if (totalsfin >= 12.0f)
while (totalsfin <= 11.0f)
{
totalsfft++;
totalsfin -= 12.0f;
}
outfile<< "/nThe total amount of snowfalls: " << totalsfft
<< " feet " << totalsfin << " inches.\n";
}
void main()
{
snowfall sf[10];
snowfall validsf[10];
snowfall invalidsf[10];
void writetitle(ofstream&);
void writeheadings(ofstream&);
void sortsf(snowfall);
void writevalidsf(snowfall, ofstream&);
void writeinvalidsf(snowfall, ofstream&);
ifstream infile;
ofstream outfile;
infile.open("c:\\downloads\\input.txt");
outfile.open("c:\\downloads\\output.txt");
if (infile && outfile)
{
int j = 0;
int k = 0;
writetitle(outfile);
for (int i = 0; i <= 10; i++)
{
sf.readdata(infile);
if (sf.getdate() == "00/00")
i = 10;
else
{
if (sf.datavalid() == 'T')
{
validsf[j] = sf;
sf.updatevalidcount();
sf.calctotalsf();
j++;
}
else
{
invalidsf[k] = sf;
sf.updateinvalidcount();
k++;
}
}
}
sortsf();
writeheadings(outfile);
writevalidsf(outfile);
writeinvalidsf(outfile);
validsf.writetotalsf(outfile);
}
else
{
if (!infile)
cout<< "Unable to open file input.txt.\n";
if (!outfile)
cout<< "Unable to open file output.txt.\n";
}
}
void writetitle(ofstream& outfile)
{
outfile<< "Title\n\n";
}
void writeheading(ofstream& outfile)
{
outfile<< "Headings\n\n";
}
void sortsf(snowfall validsf[])
{
snowfall temp;
for (int i; i = validsf.getvalidcount(); i++)
for (int j; j = i + 1; j++)
if ((float(validsf.getft()) * 12 + validsf.getin()) >
(float(validsf[j].getft()) * 12 + validsf[j].getin()))
{
temp = validsf;
validsf = validsf[j];
validsf[j] = temp;
}
}
void writevalidsf(snowfall validsf[], ofstream& outfile)
{
for (int i=0; i = validsf.getvalidcount(); i++)
validsf.writedata(outfile);
}
void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
{
if (invalidsf[0].getinvalidcount() != 0)
for (int i = 0; i = invalidsf.getinvalidcount(); i++)
outfile<< "Invalid amount of snowfall for the date, "
<< invalidsf.getdate() << endl;
}
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
float in;
float totalsfin;
char date[6];
static int validcount;
static int invalidcount;
public:
void readdata(ifstream& infile)
{
infile>> ft >> in >> date;
}
void writedata(ofstream& outfile)
{
outfile<< ft << in << date;
}
void updatevalidcount()
{
validcount++;
}
void updateinvalidcount()
{
invalidcount++;
}
void calctotalsf()
{
totalsfin += float(ft)*12 + in;
}
int getft()
{return ft;}
float getin()
{return in;}
char* getdate()
{return date;}
int getvalidcount()
{return validcount;}
int getinvalidcount()
{return invalidcount;}
int operator == (char[]);
char datavalid();
void writetotalsf(ofstream& outfile);
};
int snowfall:perator == (char sf[])
{
return (strcmp(date, sf) == 0) ? 1 : 0;
}
char snowfall::datavalid()
{
char valid;
if ((ft >= 0) && (in >= 0.0f))
valid = 'T';
else
valid = 'F';
return valid;
}
void snowfall::writetotalsf(ofstream& outfile)
{
int totalsfft = 0;
if (totalsfin >= 12.0f)
while (totalsfin <= 11.0f)
{
totalsfft++;
totalsfin -= 12.0f;
}
outfile<< "/nThe total amount of snowfalls: " << totalsfft
<< " feet " << totalsfin << " inches.\n";
}
void main()
{
snowfall sf[10];
snowfall validsf[10];
snowfall invalidsf[10];
void writetitle(ofstream&);
void writeheadings(ofstream&);
void sortsf(snowfall);
void writevalidsf(snowfall, ofstream&);
void writeinvalidsf(snowfall, ofstream&);
ifstream infile;
ofstream outfile;
infile.open("c:\\downloads\\input.txt");
outfile.open("c:\\downloads\\output.txt");
if (infile && outfile)
{
int j = 0;
int k = 0;
writetitle(outfile);
for (int i = 0; i <= 10; i++)
{
sf.readdata(infile);
if (sf.getdate() == "00/00")
i = 10;
else
{
if (sf.datavalid() == 'T')
{
validsf[j] = sf;
sf.updatevalidcount();
sf.calctotalsf();
j++;
}
else
{
invalidsf[k] = sf;
sf.updateinvalidcount();
k++;
}
}
}
sortsf();
writeheadings(outfile);
writevalidsf(outfile);
writeinvalidsf(outfile);
validsf.writetotalsf(outfile);
}
else
{
if (!infile)
cout<< "Unable to open file input.txt.\n";
if (!outfile)
cout<< "Unable to open file output.txt.\n";
}
}
void writetitle(ofstream& outfile)
{
outfile<< "Title\n\n";
}
void writeheading(ofstream& outfile)
{
outfile<< "Headings\n\n";
}
void sortsf(snowfall validsf[])
{
snowfall temp;
for (int i; i = validsf.getvalidcount(); i++)
for (int j; j = i + 1; j++)
if ((float(validsf.getft()) * 12 + validsf.getin()) >
(float(validsf[j].getft()) * 12 + validsf[j].getin()))
{
temp = validsf;
validsf = validsf[j];
validsf[j] = temp;
}
}
void writevalidsf(snowfall validsf[], ofstream& outfile)
{
for (int i=0; i = validsf.getvalidcount(); i++)
validsf.writedata(outfile);
}
void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
{
if (invalidsf[0].getinvalidcount() != 0)
for (int i = 0; i = invalidsf.getinvalidcount(); i++)
outfile<< "Invalid amount of snowfall for the date, "
<< invalidsf.getdate() << endl;
}