1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
faltersainse [42]
3 years ago
15

Counting the character occurrences in a file

Computers and Technology
1 answer:
Katena32 [7]3 years ago
5 0

Answer:

hope this helps!

Explanation:

#include <iostream>

#include <fstream>

using namespace std;

void print_histogram(int counter[26])

{

   for(int i = 0; i < 26; ++i){

       cout << (char)(i+97) << " ";

       for(int j = 0; j < counter[i]; ++j){

           cout << (char)254;

       }

       cout << endl;

   }

}

int main()

{

   int counter[26] = {0};

   string filename = "data.txt";

   char byte = 0;

   // opens file in read mode

   ifstream input_file(filename);

   if (!input_file.is_open()) {

       cerr << "Could not open the file - '"

            << filename << "'" << endl;

       return EXIT_FAILURE; // exit if not opened

   }

   // reads every character from the file

   while(input_file.get(byte)){

       if(byte >= 97 && byte <= 122){

           ++counter[byte-97];

       }

   }

   print_histogram(counter); // required print histogram function

   return 0;

}

You might be interested in
Which are the best examples of cost that should be considered when creating a project budget
sashaice [31]

Explanation:

how much the project will cost

5 0
3 years ago
Weakness in software can be more quickly uncovered and exploited with new software tools and techniques.
grandymaker [24]
False because it might damage it more but if it was recommended by lots of people i mean the software then its true
6 0
3 years ago
During the troubleshooting of a pc that will not boot, it is suspected that the problem is with the ram modules. the ram modules
Damm [24]
The modules were somehow disconnected
8 0
4 years ago
my homework guides Write the definition of a method printDottedLine, which has no parameters and doesn't return anything. The me
Masteriza [31]

Answer:

   public static void printDottedLine(){

       System.out.print(".....\n");

   }

Explanation:

This method returns nothing so its return type is void

It also accepts no parameters so the argument list is empty

When called it executes the  System.out.print(".....\n"); which prints out 5 dots

See a complete program below:

public class TestClock {

   public static void main(String[] args) {

   printDottedLine();

   }

   public static void printDottedLine(){

       System.out.print(".....\n");

   }

}

8 0
3 years ago
Connection-oriented protocols protect against dropped data by forming connections and using what type of constant stream?
nataly862011 [7]

Answer:

A real constany

Explanation:

5 0
3 years ago
Other questions:
  • Write a program that reads in 10 numbers from the user and stores them in a 1D array of size 10. Then, write BubbleSort to sort
    13·1 answer
  • Identify the computer cycle in each of the descriptions below by choosing the answer from the
    12·1 answer
  • PLEASE ANYONE!!which present margins would be best to get the most information to fit on the page​
    13·2 answers
  • What are computer virus ? Explain in detail.In your answer include symptoms and prevention (3each)
    10·1 answer
  • Tree diagrams are useful for
    12·1 answer
  • In terms of object-oriented programming, after a class is defined,
    11·1 answer
  • Victor works for a telemarketing company that is on a very tight budget. He has been tasked with finding a method for the compan
    7·2 answers
  • The gene form of a trait is called a(n) ​
    10·1 answer
  • A garments manufacturing company buys various types of natural and synthetic materials to produce clothes. Which material is a s
    6·2 answers
  • In order to view a page break what should you do
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!