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 solutionChapter 22 Solutions
C++ How to Program (Early Objects Version)
- Consider the following expression in C: a/b > 0 && b/a > 0.What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to design a language in which this expression is guaranteed to evaluate to false when either a or b (but not both) is zero? Explain your answerarrow_forwardConsider the following expression in C: a/b > 0 && b/a > 0. What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to design a language in which this expression is guaranteed to evaluate to false when either a or b (but not both) is zero? Explain your answer.arrow_forwardWhat are the major threats of using the internet? How do you use it? How do children use it? How canwe secure it? Provide four references with your answer. Two of the refernces can be from an article and the other two from websites.arrow_forward
- Assume that a string of name & surname is saved in S. The alphabetical characters in S can be in lowercase and/or uppercase letters. Name and surname are assumed to be separated by a space character and the string ends with a full stop "." character. Write an assembly language program that will copy the name to NAME in lowercase and the surname to SNAME in uppercase letters. Assume that name and/or surname cannot exceed 20 characters. The program should be general and work with every possible string with name & surname. However, you can consider the data segment definition given below in your program. .DATA S DB 'Mahmoud Obaid." NAME DB 20 DUP(?) SNAME DB 20 DUP(?) Hint: Uppercase characters are ordered between 'A' (41H) and 'Z' (5AH) and lowercase characters are ordered between 'a' (61H) and 'z' (7AH) in the in the ASCII Code table. For lowercase letters, bit 5 (d5) of the ASCII code is 1 where for uppercase letters it is 0. For example, Letter 'h' Binary ASCII 01101000 68H 'H'…arrow_forwardWhat did you find most interesting or surprising about the scientist Lavoiser?arrow_forward1. Complete the routing table for R2 as per the table shown below when implementing RIP routing Protocol? (14 marks) 195.2.4.0 130.10.0.0 195.2.4.1 m1 130.10.0.2 mo R2 R3 130.10.0.1 195.2.5.1 195.2.5.0 195.2.5.2 195.2.6.1 195.2.6.0 m2 130.11.0.0 130.11.0.2 205.5.5.0 205.5.5.1 R4 130.11.0.1 205.5.6.1 205.5.6.0arrow_forward
- Analyze the charts and introduce each charts by describing each. Identify the patterns in the given data. And determine how are the data points are related. Refer to the raw data (table):arrow_forward3A) Generate a hash table for the following values: 11, 9, 6, 28, 19, 46, 34, 14. Assume the table size is 9 and the primary hash function is h(k) = k % 9. i) Hash table using quadratic probing ii) Hash table with a secondary hash function of h2(k) = 7- (k%7) 3B) Demonstrate with a suitable example, any three possible ways to remove the keys and yet maintaining the properties of a B-Tree. 3C) Differentiate between Greedy and Dynamic Programming.arrow_forwardWhat are the charts (with their title name) that could be use to illustrate the data? Please give picture examples.arrow_forward
- A design for a synchronous divide-by-six Gray counter isrequired which meets the following specification.The system has 2 inputs, PAUSE and SKIP:• While PAUSE and SKIP are not asserted (logic 0), thecounter continually loops through the Gray coded binarysequence {0002, 0012, 0112, 0102, 1102, 1112}.• If PAUSE is asserted (logic 1) when the counter is onnumber 0102, it stays here until it becomes unasserted (atwhich point it continues counting as before).• While SKIP is asserted (logic 1), the counter misses outodd numbers, i.e. it loops through the sequence {0002,0112, 1102}.The system has 4 outputs, BIT3, BIT2, BIT1, and WAITING:• BIT3, BIT2, and BIT1 are unconditional outputsrepresenting the current number, where BIT3 is the mostsignificant-bit and BIT1 is the least-significant-bit.• An active-high conditional output WAITING should beasserted (logic 1) whenever the counter is paused at 0102.(a) Draw an ASM chart for a synchronous system to providethe functionality described above.(b)…arrow_forwardS A B D FL I C J E G H T K L Figure 1: Search tree 1. Uninformed search algorithms (6 points) Based on the search tree in Figure 1, provide the trace to find a path from the start node S to a goal node T for the following three uninformed search algorithms. When a node has multiple successors, use the left-to-right convention. a. Depth first search (2 points) b. Breadth first search (2 points) c. Iterative deepening search (2 points)arrow_forwardWe want to get an idea of how many tickets we have and what our issues are. Print the ticket ID number, ticket description, ticket priority, ticket status, and, if the information is available, employee first name assigned to it for our records. Include all tickets regardless of whether they have been assigned to an employee or not. Sort it alphabetically by ticket status, and then numerically by ticket ID, with the lower ticket IDs on top.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