I just need the following cases only and I have added my co
I just need the following cases only ! and I have added my code to save your time... so I just need few modifications
the following test cases will be due and must pass:
- Compile
- Count lines, words and characters in one file
- Correctly handle the file not found error case
- Detect poorly formed arguments
- Detect unrecognized arguments
My Code
-----------------------------
#include<iostream>
 #include<string>
 #include<fstream>
 #include<cstring>
 #include <iomanip>
 using namespace std;
int main(int argc, char* argv[])
 {
 if (argc > 1)
 {
 }
 else
 {
 cout << \"File anInvalidFileName is not found\" << endl;
 return -1;
 }
 ifstream infile(argv[1]); //open the file
 if (infile.is_open() && infile.good())
 {
 string line = \"\";
 int countline = 0;
 int charcount = 0;
 char space;
 int countspace = 0;
 int empty = 0;
 while (getline(infile, line))
 {
 if (line.empty())
 {
 empty++;
 }
 countline++;
 charcount += line.length()+1;
 for (int i = 0; i < line.length(); i++)
 {
 if (line[i] == \' \')
 countspace++;
 }
 }
 countspace = (countline-empty) + countspace ;
 cout << setw (12) << countline ;
 cout << setw(12) << countspace ;
 cout << setw(12) << charcount << \" \" ;
 cout << argv[1] << endl;
 }
 else if (argv[1] == \"-thisisunkown=5\")
 {
 cout << \"File \" << argv[1] << \" is not found\" << endl;
 return 0;
 }
 else if (argv[1] == \"-findword\")
 {
 cout << \"Argument \" << argv[1] << \" is poorly formed\" << endl;
 return 0;
 }
 else
 {
 cout << \"Argument \" << argv[1] << \" is not recognized\" << endl;
 }
 return 0;
 }
-------------------------------------------------------------------------------
This assignment involves writing a C++ program to identify and count lines, words, and characters. For the purpose of this assignment, we define a \"word\" as a sequence of characters that are not whitespace characters. Words are delimited by one or more whitespace characters. A whitespace character, such as a space, tab, or newline, is any character for which theSolution
#includ<iostream>
#include<fstream>
#include<string>
#include<conio.h>
using namespace std;
int main()
{
string filename;
cout<<\"please enter the filename\";
cin>filename;
ifstream infile(filename,std::ifstream::in);
if(!infile)
{cout<<\"cannot open file for reading\";
_getch();
return 1;
}
char ch,c;
int count=1;
int i=0;
int count1=1;
while(infile.het(ch))
{
cout<<ch;
if(ch=\'\')
{count++;
count1++;
}else if(ch==\'\')
count1++;
i=i-1;}
count<<\"\";
cout<<\"\ number of charcters: \"<<i-(count-1+count1-1)<<\"\";
cout<<\"\ number of words:\"<<count1<<\"\":
count<<\"\ number of lines\"<<count<<\"\";
infile.close();
_getch();
return 0;
}



