Question

In: Computer Science

We want to design and develop a text statistical analyzer. This analyzer should consider an input...

We want to design and develop a text statistical analyzer. This analyzer should consider an input text as a finite sequence of characters, including letters (‘a’, .., ‘z’, ‘A’, ..., ‘Z’), digits (0,…, 9), special characters (space and new line), and punctuation characters (‘.’, ‘,’, ‘;’). The input text must end with ‘#’. A word is defined as a sequence of alphanumeric characters (letters and numbers, 0 to 9) delimited by two separators. A separator is any non-alphanumeric character. Use your favorite object-oriented programming language to write a program that accepts a text as input and gives as output the following results: i. The total number of alphanumeric characters (i.e., letters and digits). ii. The total number of letters and their frequency with respect to the total number of alphanumeric characters. 2 iii. The total number of digits and their frequency with respect to the total number of alphanumeric characters. iv. The total number of words. v. The total number of words starting with “ted” and their frequency with respect to the total number of words. vi. The total number of words ending with “ted” and their frequency with respect to the total number of words. vii. The total number of words having “ted” in the middle and their frequency with respect to the total number of words. viii. The total number of sequences of “ted” and their frequency with respect to the total number of sequences of three alphanumeric characters. The implementation of this text statistical analyzer should be as structured as possible.

Write a code for the above problem either in c/c++.

Solutions

Expert Solution

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>

using namespace std;

void countStuff(istream& in,
                int& chars,
                int& words,
                int& lines) {

   char cur = '\0';
   char last = '\0';
   chars = words = lines = 0;

   while (in.get(cur)) {
      if (cur == '\n' ||
          (cur == '\f' && last == '\r'))
         lines++;
      else
        chars++;
      if (!std::isalnum(cur) &&   // This is the end of a
          std::isalnum(last))     // word
         words++;
      last = cur;
   }
   if (chars > 0) {               // Adjust word and line
      if (std::isalnum(last))     // counts for special
         words++;                 // case
      lines++;
   }
}

int main(int argc, char** argv) {

   if (argc < 2)
      return(EXIT_FAILURE);

   ifstream in(argv[1]);

   if (!in)
      exit(EXIT_FAILURE);

   int c, w, l;

   countStuff(in, c, w, l);
1
   cout << "chars: " << c << '\n';
   cout << "words: " << w << '\n';
   cout << "lines: " << l << '\n';
}

Related Solutions

We want to develop a sales system for a mobile shop. The system should keep information...
We want to develop a sales system for a mobile shop. The system should keep information about the mobile phones available at the shop. the system should allow the user the ADD new mobile phones, one at a time, along with their features. The system should also allow to search mobile phones , update their information, and delete them (one by one). Try to provide different criteria for search. When the system starts, it should load the information about the...
In this assignment we will be working with both text strings and a user input integer...
In this assignment we will be working with both text strings and a user input integer array from the data segment. The goal of the assignment is to have the user choose the number of items that they want to have in an array (we will keep it a small number for now, 1-10) and then enter those values which we will store into our array. We then want to allow them to search for a specific item in the...
Develop a set of test cases for the algorithm In a scheduling program, we want to...
Develop a set of test cases for the algorithm In a scheduling program, we want to check whether two appointments overlap. For simplicity, appointments start at a full hour, and we use military time (with hours 0–24). The following pseudocode describes an algorithm that determines whether the appointment with start time start1 and end time end1 overlaps with the appointment with start time start2 and end time end2. If start1 > start2 s = start1 Else s = start2 If...
What statistical tool should I use in a pretest posttest control group design?
What statistical tool should I use in a pretest posttest control group design?
Design a Moore state machine that has an input w and an output z that should...
Design a Moore state machine that has an input w and an output z that should output a ‘1’ when the previous 4 values of w were 1001 or 1111. Overlapping patterns are allowed. Show the state diagram and state table. Use a simple binary counting order for the state assignment. Derive all of the next-state and output equations. You do not need to draw the resulting circuit, instead write a Verilog module for it.
Design the format of the packet with which we want to transmit the current time with...
Design the format of the packet with which we want to transmit the current time with an accuracy of milliseconds. Are there more ways to design such a format?
Which statistical test should I use if I want to know if two values are close...
Which statistical test should I use if I want to know if two values are close to one another? For example, the average time for birds at a birdfeeder are 53.52 sec compared to those who stay in the surrounding branches (52.81 sec) I don't know if there is an applicable test I can apply for two simple variables. Thanks !
Question 1 We want to conduct a statistical test to determine how a sample mean compares...
Question 1 We want to conduct a statistical test to determine how a sample mean compares to a population mean. We have alpha = 0.05. We have 40 observations in the sample, and our sample is normally distributed. We do not know our population standard deviation. Which test would we use? Group of answer choices a) z-test b) t-test Question 2 I want to see if the mean midterm scores for our class (the sample) differs from a baseline average...
Statistical significance tests do not tell the researcher what we want to know nor do they...
Statistical significance tests do not tell the researcher what we want to know nor do they evaluate whether or not our results are important. They tell us only whether or not the results of a study were due to chance. Therefore, how do researchers go about doing this? In your video response, please discuss the relationship of the p-value in relation to the level of significance. Lastly, please provide an example of a Type I and Type II errors.  
a) Design and develop a complete project management methodology for you organisation. The methodology should include...
a) Design and develop a complete project management methodology for you organisation. The methodology should include the following: • The basic principles of project management by making use of well-known guidelines such as PMBoK, PRINCE II, ICB4, ISO, etc. You can also make use of the principles explained in the P2M2 methodology or V-model . • Proper life-cycle definition • Function and role definition across the project life-cycle • Clear gate criteria and deliverables • Process flow within the phases...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT