Analyze and visualize text files: Count characters, spaces, and display ASCII values of characters in text file.
This is a C++ program to count the number of characters and spaces in a file, and print the ASCII values of all characters in the file.
each and every letter has different ASCII value
The program first defines a class called take
with three public methods: abhi()
, count()
, and ascii()
.
The abhi()
method simply prints the contents of the file abhi.txt
to the console.
The count()
method counts the number of characters and spaces in the file abhi.txt
. It does this by iterating over the file character by character and checking if each character is a letter or a space. If the character is a letter, the count()
method increments the character count. If the character is a space, the count()
method increments the space count. After iterating over the entire file, the count()
method prints the number of characters and spaces to the console.
The ascii()
method prints the ASCII values of all characters in the file abhi.txt
to the console. It does this by iterating over the file character by character and casting each character to an integer. The ASCII value of a character is simply its integer value. After iterating over the entire file, the ascii()
method prints the ASCII values of all characters to the console.
The main function in the program simply creates an instance of the take
class and calls the abhi()
, count()
, and ascii()
methods on the object.
Here is an example of the output of the program:
smaple output:
this is the output in this file = | this is the first line of the file | this is the output in this file = | this is the second line of the file | No. of Characters in a File : 28 Space between the Words : 6 Character: t, ASCII Value: 116 Character: h, ASCII Value: 104 Character: i, ASCII Value: 105 Character: s, ASCII Value: 115 Character: , ASCII Value: 32 Character: i, ASCII Value: 105 Character: s, ASCII Value: 115 Character: , ASCII Value: 32 Character: t, ASCII Value: 116 Character: h, ASCII Value: 104 Character: e, ASCII Value: 101 Character: , ASCII Value: 32 Character: f, ASCII Value: 102 Character: i, ASCII Value: 105 Character: r, ASCII Value: 114 Character: s, ASCII Value: 115 Character: t, ASCII Value: 116 Character: , ASCII Value: 32 Character: l, ASCII Value: 108 Character: i, ASCII Value: 105 Character: n, ASCII Value: 110 Character: e, ASCII Value: 101 Character: , ASCII Value: 32 Character: o, ASCII Value: 111 Character: f, ASCII Value: 102 Character: , ASCII Value: 32 Character: t, ASCII Value: 116 Character: h, ASCII Value: 104 Character: e, ASCII Value: 101 Character: , ASCII Value: 32 Character: f, ASCII Value: 102 Character: i, ASCII Value: 105 Character: l, ASCII Value: 108 Character: e
Submitted by Abhiram eerla (Abhirameerla)
Download packets of source code on Coders Packet
Comments