Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

quick question... 5. count the number of lines (test for the end of line charact

ID: 3624082 • Letter: Q

Question

quick question...

5. count the number of lines (test for the end of line character)
6. count the number of symbols in the file – a symbol is white space, letters, digits, punctuation, end of line characters – any symbol that appears in the file


I can not test this two help me..

end of line character keep say it is 0 and also isn't number 6 should be the same????


/*Modify the program to:
1. count the number of white space characters (isspace)
2. count the number of letters (isalpha)
3. count the number of punctuations (ispunct)
4. count the number of digits (isdigit)
5. count the number of lines (test for the end of line character)
6. count the number of symbols in the file – a symbol is white space, letters, digits, punctuation, end of line characters – any symbol that appears in the file
7. write the counts as formatted output to an outut file
8. use multi-way if statements; do not use one-way if statements.
9. add the number of white space, letters, punctuations, digits and new line characters and compare this number to the number of symbols in the file. Are the 2 numbers equal?
*/


#include "stdafx.h"
#include
#include
#include
#include
#include
#include
using namespace std;

int main()
{

//read file name
const string prompt = "Enter file name: ";
cout << prompt;
string file_name;

//count the number of letters in a file

getline(cin, file_name, ' ');
assert(file_name.length() > 0);

ifstream input;
input.open(file_name.c_str());
assert(input.good());
ofstream write;
write.open("value.txt",ios::out); //Must create a data in note pad and save it valu.txt
int white=0,let=0,pun=0,dgts=0,enlin=0,symbl=0,cmpr=0;
char c;
input.get(c);
while(!input.eof())
{
if(isspace(c)!=0)
white++;
else if(isalpha(c)!=0)
let++;
else if(ispunct(c)!=0)
pun++;
else if(isdigit(c)!=0)
dgts++;


else if(int(c)==13)                       //can't test
enlin++;
else                                               // is this correct??
symbl++;
input.get(c);
}

write << " the number of white space characters: "<< white<
write << " the number of letters characters: "<< let <
write << " the number of punctuations characters: "<
write << " the number of digits characters: "<< dgts <
write << " the number of end of line characters: "<< enlin <
write << " the number of symbols in the file: "<< symbl<< endl;


cmpr=white+let+pun+dgts+enlin;
if(cmpr==symbl)
cout<<" Two numbers are same"<< " "<< "beacause "<< symbl << " = "< else
cout<<" The two numbers are not equal"<< " "<< "beacause "<< symbl << " "<
system ("pause");
return 0;
}

Explanation / Answer

please rate - thanks

some of your code was destroyed by the CRAMSTER editor. I used DEV C++ so commented out stdafx, you may need to add it. I made a variety of changes, tried to highlight them all in red

do you really want some output to go to the file, and some to the screen?

//#include "stdafx.h"
//#include
//#include
//#include
//#include
#include <iostream>
#include <fstream>
using namespace std;

int main()
{

//read file name
const string prompt = "Enter file name: ";
cout << prompt;
string file_name;

//count the number of letters in a file

getline(cin, file_name, ' ');
assert(file_name.length() > 0);

ifstream input;
input.open(file_name.c_str());
assert(input.good());
ofstream write;
write.open("value.txt",ios::out); //Must create a data in note pad and save it valu.txt
int white=0,let=0,pun=0,dgts=0,enlin=0,symbl=0,cmpr=0,total=0;
char c;
input.get(c);
while(!input.eof())
{total++;
if(isspace(c))
    {if(c==' ')                       //can't test
         enlin++;
      else
          white++;
         }
else if(isalpha(c))
    let++;
else if(ispunct(c))
    pun++;
else if(isdigit(c))
    dgts++;
else                                               // is this correct??
   symbl++;
input.get(c);
}

write << " the number of white space characters: "<< white<<endl;
write << " the number of letters characters: "<< let <<endl;
write << " the number of punctuations characters: "<<pun<<endl;
write << " the number of digits characters: "<< dgts <<endl;
write << " the number of end of line characters: "<< enlin <
write << " the number of symbols in the file: "<< symbl<< endl;


cmpr=white+let+pun+dgts+enlin+symbl;
if(cmpr==total)
cout<<" Two numbers are same"<< " "<< "beacause "<< total << " = "<<cmpr<<endl;
else
   cout<<" The two numbers are not equal"<< " "<< "beacause "<< total<< " ? "
     <<cmpr<<endl;
system ("pause");
return 0;
}