#include <iostream> #include <fstream> #include <cstdlib> using namespace std; /
ID: 3618969 • Letter: #
Question
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
//These functions explained below
void spaces();
int main()
{
ifstream infile;
ofstream outfile;
char response;
do
{
infile.open("infile.txt");
if(infile.fail())
{
cout << "I could not open thatfile.";
exit(1);
}
outfile.open("output.txt");
if(outfile.fail())
{
cout << "I could not open thatfile.";
exit(1);
}
char next;
int letters=0,total=0,non=0;
infile.get(next);
while(!infile.eof())
{
if(isalpha(next))
{
letters++;
}
if(!isalpha(next) &&!isspace(next))
{
non++;
}
total++;
infile.get(next);
}
cout << letters <<"letters " << endl << total<< " characters total " << endl
<< non << " non white spacecharacters" << endl;
outfile << letters <<"letters " << total<< " total " <<non << " non white spacecharacters";
infile.close();
infile.clear();
outfile.close();
//Asks the user he would like to go again anything other than (Y ory) the program ends
cout << "Would you like to go again (Yor y): ";
cin >> response;
cout << endl;
}while(response == 'Y' || response== 'y');
system("pause");
return 0;
}
//This void function is for 2 statement spaces betweensentences
void spaces()
{
cout << endl << endl;
}
Explanation / Answer
please rate - thanks I would read the file names rather then hard coding them. Thereason is, if you repeat the code, you are doing it with the samefiles #include #include #include using namespace std; // These functions explained below void spaces(); int main() { ifstream infile; ofstream outfile; intletterCount[26],i; char response; for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.