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

SIDE NOTE: C++ LANGUAGE PLEASE Write a program that reads in an unknown number o

ID: 3738758 • Letter: S

Question

SIDE NOTE: C++ LANGUAGE PLEASE

Write a program that reads in an unknown number of characters from a file (A3Q1.dat) and then outputs to the screen. Haney's Character Counte the characters read displayed 10 per line with 2 spaces in between them. the total number of characters read from file the number of digits read and the % of the total characters read this represents the number of uppercase letters read and the % of the total characters read this represents the number of lower case letters read and the % of the total characters read this - - he file exieted but a eauty Strange.. hank you For using the Character Maniulater Figure 2 File eaists but is empty -the number of spaces read and the % of the total characters read this represents -the number of the remaining characters and the % of the total characters read this represents Naney"s Character Counter You need to account for the possibility that the file does not exist (Figure 1) and the file is empty (Figure 2) fron fila are Figures 1 to 4 show you a sample outputs. Your output does not have to be identical to these but must contain the same information. ota112 aharoctero in te a ner of dpetca Nancys Character Counter tho data f file r s-@-+-?-/-)-??--[-]-(-)-,-- lett"to pt tetal characters) orry! Could not open file. Progran ending. oner *«i3. b eetas toro hank yea for ?"ig the Character Manipulator Nancy's Chorac ter Counter cters read Fron ile are: here i -fi total of 18 characters in the data, filo" Nunher of digits; 7?78.ggoe ef total characters) 30.0 of tetal charactera) e For usiy the Character Hanipulator.. Figure4-Example 2 of file with data

Explanation / Answer

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char** argv) {
    ifstream file;
    file.open("A3Q1.dat",ios::in);
    if(!file.is_open()){
        cout<<"Sorry could not open the given file ";
        return 1;
    }
    char ch;
    file.get(ch);/*we can use file>>ch too but we can't read space in such cases*/
    if(file.eof()){
        cout<<"Sorry the given file is empty ";
        return 1;
    }
    int intCount = 0,upperCaseCount = 0,lowerCaseCount = 0,otherChar = 0,total = 0,spaceCount = 0;
    for(int count = 0;!file.eof();++count){
        cout<<ch<<" ";
        if( (ch>='a')&&(ch<='z') ){
            lowerCaseCount++;
        }else if( (ch>='A')&&(ch<='Z') ){
            upperCaseCount++;
        }else if( (ch>='0')&&(ch<='9') ){
            intCount++;
        }else if(isspace(ch)){/*raw comparision like ch == ' ' does not works */
            spaceCount++;
        }else{
            otherChar++;
        }
        file.get(ch);
        if(count == 9){
            cout<<endl;
            count = 0;
        }
    }
    total = intCount+upperCaseCount+lowerCaseCount+otherChar;
    cout<<"There is a total of "<<total<<" charecters present in the data file. ";
    cout<<"Here is the breakdown: ";
    cout<<" Numer of digits: "<<intCount<<"("<<(double)(100*intCount)/total<<" of total charecters)"<<endl;
    cout<<" Number of uppercase letters: "<<upperCaseCount<<"("<<(double)(100*upperCaseCount)/total<<" of total charecters)"<<endl;
    cout<<" Number of lower case letters: "<<lowerCaseCount<<"("<<(double)(100*lowerCaseCount)/total<<" of total charecters)"<<endl;
    cout<<" Number of space: "<<spaceCount<<"("<<(double)(100*spaceCount)/total<<" of total charecters)"<<endl;
    cout<<" Number of other charecters: "<<otherChar<<"("<<(double)(100*otherChar)/total<<" of total charecters)"<<endl;
    cout<<"Thank you for using charecter manuplater ";

    return 0;
}


/*sample input file*/

/*Hello world!I'm code number 31 its a software world, That's it for now ,Shall meet later, bye!!*/

/*output*/

/*

H e l l o     w o r l
d ! I ' m     c o d
e     n u m b e r   
3 1     i t s     a   
s o f t w a r e   
w o r l d ,     T h
a t ' s     i t     f
o r     n o w     , S
h a l l     m e e t
   l a t e r ,     b
y e ! !
There is a total of 79 charecters present in the data file.
Here is the breakdown:
        Numer of digits: 2(2.53165 of total charecters)
        Number of uppercase letters: 4(5.06329 of total charecters)
        Number of lower case letters: 65(82.2785 of total charecters)
        Number of space: 17(21.519 of total charecters)
        Number of other charecters: 8(10.1266 of total charecters)
Thank you for using charecter manuplater


*/