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

write program a class named textFile. an object of type textFile counts characte

ID: 674652 • Letter: W

Question

write program a class named textFile. an object of type textFile counts characters, and lines in a text file. The text file is assumed to encode each character in a single byte, using the normal ASCII/UTF-8 standard.

You will need to use FileInputStream for read the text file

Your textFile class must implement exactly the public constructors(textFile) and methods (getCharCount,getLineCount,toString) to implement.

Carefully note this sentence in the constructor's description: All file I/O is complete once this constructor returns.

Your class definition will begin something like this…

public class TextFileAnalyzer {

// You'll probably want some private fields

/** * Constructs a new TextFileAnalyzer that reads from the given file. All file

* I/O is complete once this constructor returns.

* @param filePath a path to the file

* @throws Exception if any errors are generated by the Java API while reading

* from the file */

public TextFileAnalyzer(String filePath) throws Exception {

// This is your job... }

/**

* Returns the number of single-byte characters in the file, including whitespace.

* * @return the number of characters in the file */

public int getCharCount() { // This is your job too... } // and more ...

Explanation / Answer

#include<stdio.h>
#include<conio.h>
void main()
{
int noc=0,now=0,nol=0;
FILE *fw,*fr;
char fname[20],ch;
clrscr();
printf(" enter the source file name");
gets(fname);
fr=fopen(fname,"r");

if(fr==NULL)
{
printf(" error ");
exit(0);
}
ch=fgetc(fr);
while(ch!=EOF)
{
noc++;

if(ch==' ');
now++;
if(ch==' ')
{
nol++;
now++;
}

ch=fgetc(fr);
}
fclose(fr);
printf(" total no of character=%d",noc);
printf(" total no of words=%d",now);
printf(" total no of lines=%d",nol);
getch();
}