
Concept explainers
22.41E a) Program Description:
The program declares an array of characters and integer to store the alphabets and corresponding counts initialized to 0;
It takes multi line inputs from the user and stores those into a
22.41E a) Program
/* * 22_41a_charactercount.cpp string handling and total alphabet counts table */ #include<string> #include<iostream> #include<cstring> #include<vector> usingnamespace std; intmain() { char alphaBets[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T','U', 'V', 'W', 'X', 'Y', 'Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; int counts[]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0}; vector<string> input; string str, strInput; //take input from user cout<<"Please enter any text. Enter ZZZ to finish typing:\n\n"; getline(cin, str); while ( str!= "ZZZ") { input.push_back(str); getline(cin, str); } //process the input string for (constauto& em: input){ strInput = em; for(int i=0; i < strInput.length();i++){ char test = strInput.at(i); for(int j=0;j <sizeof(alphaBets); j++){ if( test == alphaBets[j]){ counts[j]+=1; } } } } cout<<"The Alphabets counts in the supplied text are as below :\n\n\n"; for(int n=0;n <sizeof(alphaBets); n++){ cout<<"Count of "<<alphaBets[n]<<" = "<<counts[n]<<endl; } return 0; }//end main
22.41E a) Sample Output
Sample Output 22.41 a)
Please enter any text. Enter ZZZ to finish typing:
This is another test, of a justification program
for 65 chars long, with so many inputs and ! and commas,
Therefore, I have to admit this is just
a very basic program which does nothing but keeps testing
the input provided for length and applies justification logic
to the right & left parts of 65th position.
There can be many possible improvements
to this very very basic program. Thanks !
ZZZ
The Alphabets counts in the supplied text are as below :
Count of A = 0
Count of B = 0
Count of C = 0
Count of D = 0
Count of E = 0
Count of F = 0
Count of G = 0
Count of H = 0
Count of I = 1
Count of J = 0
Count of K = 0
Count of L = 0
Count of M = 0
Count of N = 0
Count of O = 0
Count of P = 0
Count of Q = 0
Count of R = 0
Count of S = 0
Count of T = 3
Count of U = 0
Count of V = 0
Count of W = 0
Count of X = 0
Count of Y = 0
Count of Z = 0
Count of a = 23
Count of b = 5
Count of c = 9
Count of d = 7
Count of e = 26
Count of f = 8
Count of g = 9
Count of h = 18
Count of i = 28
Count of j = 3
Count of k = 2
Count of l = 6
Count of m = 10
Count of n = 19
Count of o = 25
Count of p = 13
Count of q = 0
Count of r = 22
Count of s = 25
Count of t = 31
Count of u = 7
Count of v = 7
Count of w = 2
Count of x = 0
Count of y = 6
Count of z = 0
22.41E b) Program Description
The program stores lines of text input into a vector<string> and then iterates over each element, tokenizing strings into words using strtok and keeps a count of the words in an array which is finally printed out. The max word length assumed is 45 as that's the longest word in English dictionary (pneumonoultramicroscopicsilicovolcanoconiosis ).
22.41E b) Program
/* * 22_41b_wordslengthcpp string handling and total words & their length counts table */ #include<string> #include<iostream> #include<cstring> #include<vector> usingnamespace std; intmain() { //Assume the maximum word length = 45 ( as per modern dictionary //keep counts lengthwise , index 0 for length one char int counts[45]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; vectorinput; string str, strInput; //take input from user cout<<"Please enter any text. Enter ZZZ to finish typing:\n\n"; getline(cin, str); while ( str!= "ZZZ") { input.push_back(str); getline(cin, str); } constchar space[2]= " "; //process the input string for (constauto& em: input){ char * temp = newchar[em.length() + 1]; strcpy(temp, em.c_str()); char * word = strtok(temp, space); while(word != 0){ int wordLen = strlen(word); if( wordLen >0) counts[wordLen-1]+=1; word =strtok(NULL, space); } } cout<<"The Words Length and their counts in the supplied text are as below :\n\n" <<"\tWord Length\t\t\t\t"<<"Total count\n" <<"\t------------\t\t\t\t------------\n"<<endl; for(intn=0;n< 45; n++){ cout<<"\t "<<n+1<<"\t\t\t\t "<<counts[n]<<endl; } return 0; }//end main
22.41E b) Sample Output
pneumonoultramicroscopicsilicovolcanokoniosis is a disease caused by exposure to volcanic silica, also termed as silicosis.
ZZZ
The Words Length and their counts in the supplied text are as below :
Word Length Total count
------------ ------------
1 2
2 4
3 0
4 1
5 0
6 3
7 1
8 2
9 1
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
32 0
33 0
34 0
35 0
36 0
37 0
38 0
39 0
40 0
41 0
42 0
43 0
44 0
45 1
22.41E c) Program Description
The program will use map
Finally, using the vector, all words will be iterated and their respective counts will be fetched from the map.
Explanation:
22.41E c)Program
/* * 22_41c_wordscount.cpp string handling and unique words & their length counts table */ #include<string> #include<iostream> #include<cstring> #include<vector> #include<map> #include<algorithm>// to convert whole string to uppercase or lowercase using STL. usingnamespace std; intmain() { map
22.41E c) Sample Output
Please enter any text. Enter ZZZ to finish typing:
To be or not To be is an old proverb yet interests many in the modern world
To understand this better a course in modern literature has to be pursued and that too in a deep sense
ZZZ
The unique Words and their counts in the supplied text are as below :
Word Total count -------------------- ------------ to 4 be 3 or 1 not 1 is 1 an 1 old 1 proverb 1 yet 1 interests 1 many 1 in 3 the 1 modern 2 world 1 understand 1 this 1 better 1 a 2 course 1 litratire 1 has 1 pursued 1 and 1 that 1 too 1 deep 1 sense 1

Want to see the full answer?
Check out a sample textbook solution
Chapter 22 Solutions
C++ How to Program (10th Edition)
- Compare the security services provided by a digital signature (DS) with those of a message authentication code (MAC). Assume that Oscar can observe all messages sent between Rina and Naseem. Oscar has no knowledge of any keys but the public one, in the case of DS. State whether DS and MAC protect against each attack and, if they do, how. The value auth(x) is computed with a DS or a MAC algorithm. In each scenario, assume the message M = x#####auth(x). (Message integrity) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message M, and then sends M in cleartext to Naseem. Oscar intercepts the message and replaces “Mark” with “Oscar.” Will Naseem detect this in the case of either DS or MAC? If yes, how will Naseem detect it? If not, why? (Replay) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message…arrow_forwardI need to resolve the following....You are trying to convince your boss that your company needs to invest in a license for MS-Project (project management software from Microsoft) before beginning a systems project. What arguments would you give her?arrow_forwardWhat are the four types of feasibility? what is the issues addressed by each feasibility component.arrow_forward
- I would like to get ab example of a situation where Agile Methods might be preferable versus the traditional SDLC? What are the characteristics of this situation that give Agile Methods an advantage?arrow_forwardWhat is a functional decomposition diagram? what is a good example of a high level task being broken down into tasks in at least two lower levels (three levels in all).arrow_forwardWhat are the advantages to using a Sytems Analysis and Design model like the SDLC vs. other approaches?arrow_forward
- 3. Problem Description: Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. • A data field radius with a get method. • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. • A constructor that creates a circle with the specified x, y, and radius. • A method getArea() that returns the area of the circle. • A method getPerimeter() that returns the perimeter of the circle. • • • A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure (a). A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure (b). A method overlaps (Circle2D circle) that returns true if the specified circle overlaps with this circle. See the figure below. р O со (a) (b) (c)< Figure (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another…arrow_forward1. Explain in detail with examples each of the following fundamental security design principles: economy of mechanism, fail-safe default, complete mediation, open design, separation of privilege, least privilege, least common mechanism, psychological acceptability, isolation, encapsulation, modularity, layering, and least astonishment.arrow_forwardSecurity in general means the protection of an asset. In the context of computer and network security, explore and explain what assets must be protected within an online university. What the threats are to the security of these assets, and what countermeasures are available to mitigate and protect the organization from such threats. For each of the assets you identify, assign an impact level (low, moderate, or high) for the loss of confidentiality, availability, and integrity. Justify your answers.arrow_forward
- Please include comments and docs comments on the program. The two other classes are Attraction and Entertainment.arrow_forwardObject-Oriented Programming In this separate files. ent, you'll need to build and run a small Zoo in Lennoxville. All classes must be created in Animal (5) First, start by building a class that describes an Animal at a Zoo. It should have one private instance variable for the name of the animal, and one for its hunger status (fed or hungry). Add methods for setting and getting the hunger satus variable, along with a getter for the name. Consider how these should be named for code clarity. For instance, using a method called hungry () to make the animal hungry could be used as a setter for the hunger field. The same logic could be applied to when it's being fed: public void feed () { this.fed = true; Furthermore, the getter for the fed variable could be named is Fed as it is more descriptive about what it answers when compared to get Fed. Keep this technique in mind for future class designs. Zoo (10) Now we have the animals designed and ready for building a little Zoo! Build a class…arrow_forward1.[30 pts] Answer the following questions: a. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuit in your report. 2. [20 pts] Student A B will enjoy his picnic on sunny days that have no ants. He will also enjoy his picnic any day he sees a hummingbird, as well as on days where there are ants and ladybugs. a. Write a Boolean equation for his enjoyment (E) in terms of sun (S), ants (A), hummingbirds (H), and ladybugs (L). b. Implement in Logisim, the logic circuit of E function. Use the Circuit Analysis tool in Logisim to view the expression, include an image of the expression generated by Logisim in your report. 3.[20 pts] Find the minimum equivalent circuit for the one shown below (show your work): DAB C…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningFundamentals of Information SystemsComputer ScienceISBN:9781337097536Author:Ralph Stair, George ReynoldsPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage



