100k views
1 vote
Write a program that opens a text file and reads its contents into a queue of characters. The program should then dequeue each character and have a counter to see how many of the characters are actually letters. This number should be printed to the console for the user

User Matharden
by
5.3k points

1 Answer

6 votes

Answer:

Please see explaination for code and attachment for output

Step-by-step explanation:

The program source code.

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

ifstream fs("xy.txt");

char ch;

string str=""; // for storing characters

while(fs>>ch)

{

str=str+ch; // appending characters to string

}

int i=0,count=0;

while(str[i]!='\0')

{

if((str[i]>=65 && str[i]<=90)||(str[i]>=97 && str[i]<=122))

{

count++;

}

i++;

}

cout<<"No. of Alphabets:"<<count<<endl;

}

xy.txt:

Check attachment for output and code on screen.

Write a program that opens a text file and reads its contents into a queue of characters-example-1
Write a program that opens a text file and reads its contents into a queue of characters-example-2
User Pheona
by
4.9k points