Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cctype>
- #include <iomanip>
- using namespace std;
- string& RaiseItToUpperCase(string& w)
- {
- int len = w.length();
- for (int index =0; index <len; index++)
- w[index]= toupper(w[index]);
- return w;
- }
- void LoadData()
- {
- string filename;
- while(true)
- {
- cout<<"Enter Data file:";
- cin>>filename;
- cout<<"Filename entered"<<filename<<endl;
- ifstream myfile(filename.c_str());
- if(!myfile.good())
- {
- cout<<"Please Enter a Valid text File"<<endl;
- continue;
- }
- static std::string const targetExtension ("txt");
- if (!(filename.size() >= targetExtension.size()
- && std::equal (filename.end() - targetExtension.size(),
- filename.end(),
- targetExtension.begin() ) ))
- {
- cout<<"File is not txt"<<endl;
- continue;
- }
- break;
- }
- string i = filename;
- string o;
- cout<<"Enter an output file name:"<< endl;
- cin>>o;
- ofstream output;
- ifstream input(filename);
- output.open(o.c_str());
- int charc =0;
- int numw =0;
- int longl =0;
- int shortl =10000;
- while (input>>1)
- {
- numw++;
- charc = charc + i.length() +1;
- if (i.length() > longl)
- {
- longl = i.length();
- }
- if (i.length() < shortl)
- {
- i =RaiseItToUpperCase(i);
- output << i;
- if(input.get() ==32)
- {
- output<<" ";
- }
- else
- {
- output<<"n";
- }
- }
- charc = charc - 1;
- output<<"nWord Counter Summaryn"<<endl;
- output<<"Total Number of Words:"<<numw<<endl;
- output<<"Total Number of Characters:"<<charc<<endl;
- output<<" Largest Word Size:"<<longl<<endl;
- output<<" Smallest Word Size"<<shortl<<endl;
- }
- }
- int main ()
- {
- LoadData();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement