Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Note: Do not use classes or any variables of type string to complete this assignment

Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line.

The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must be ignored. Any characters entered after the period ('.') should be left in the input stream unprocessed. No limit may be placed on the length of the input.

Use an array with a struct type as its base type so that each array element can hold both a letter and an integer. (In other words, use an array whose elements are structs with 2 fields.) The integer in each of these structs will be a count of the number of times the letter occurs in the user's input.

Let me say this another way in case this makes more sense. You will need to declare a struct with two fields, an int and a char. (This should be declared above main, so that it is global; that is, so it can be used from anywhere in your program.) Then you need to declare an array (not global!) whose elements are those structs.

The int in each struct will represent the number of times that the char in the same struct has occurred in the input. This means the count of each int should start at 0 and each time you see a letter that matches the char field, you increment the int field.

Don't forget that limiting the length of the input is prohibited. If you understand the above paragraph you'll understand why it is not necessary to limit the length of the input.

The table should not be case sensitive -- for example, lower case 'a' and upper case 'A' should be counted as the same letter. Here is a sample run:

Enter a sequence of characters (end with '.'): do be Do bo. xyz Letter: Number of Occurrences o 3 d 2 b 2 e 1
Note: Your program must sort the array by descending number of occurrences, using a selection sort. Be sure that you don't just sort the output. The array itself needs to be sorted.

Submit your source code and some output to show that your code works.

Hints: Students seem to get hung up on the requirement that the user can enter multiple lines of input and that you should leave characters after the period in the input stream. The intention of these requirements (believe it or not) is to steer you toward a better and simpler solution, so please don't get too hung up on them! Another way of stating the requirement is this: just keep reading characters one at a time, ignoring newline characters (that is, treating them just like any other non-alphabetic character), until you get to a period.

You will definitely want to pay close attention to section 9.2 from the text while tackling this assignment. In my solution I use cin.get(ch), isalpha(ch), and tolower(ch).

When determining which array element to access you may want to do some arithmetic that involves characters. For example, saying array[ch - 'a'] will access array[0] if ch is 'a', array[1] if ch is 'b', and so on. Let me know if you need further explanation on this concept. Although it is not completely safe, you should assume for this assignment that the ASCII character set is being used. (This will simplify your code somewhat.)

Note that your struct should be declared above main, and also above your prototypes, so that your parameter lists can include variables that use the struct as their base type. It should be declared below any global consts.

Please add function comments.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93071843

Have any Question?


Related Questions in Computer Engineering

If the probability that an individual suffers from a bad

If the probability that an individual suffers from a bad reaction from an injection of a given serum is 0.001, determine the probability that out of 2000 individuals (a) exactly 3, (b) more than 2 individuals will suffer ...

Decision support systems dss what sorts of dss tools do you

Decision support systems (DSS). What sorts of DSS tools do you use at your work - e.g., what-if analysis, sensitivity analysis, scenario analysis, goal-seeking analysis, optimization analysis, etc.? Even if you don't use ...

Is smartart graphic and table slide important for

Is Smartart graphic and Table slide important for PowerPoint Presentation? How would it benefit?

Problemtelephone calls arrive at the rate of 12 per hour at

Problem Telephone calls arrive at the rate of 12 per hour at the reservation desk for Regional Airways. a. Find the probability of receiving 3 calls in a 4-minute interval. If required, round your answer to four decimal ...

Question suppose you wish to make a design with 10 lobes

Question : Suppose you wish to make a design with 10 lobes, and you have only a large ring with 120 inner teeth. What is the largest moving wheel you could use?

Bierco is a beer company based in germany you purchased the

BierCo is a beer company based in Germany. You purchased the stock in 2011 for 100 Euros when the exchange rate was 1.4 EUR/ USD. Today BierCo's price is 120 Euros and the exhange rate is 1.12 EUR/USD. What is the dollar ...

Simcon is a forensics software tool that can generate

SIMcon is a forensics software tool that can generate information for mobile device investigations. In Hands-On Project 12-1, you examined SMS messages on two phones that had been generated by SIMcon. In this project, yo ...

What is the solution for chapter 15 3e for java programming

What is the solution for chapter 15 3e for java programming 8th edition Create a JFrame that holds fjive buttons with the names of five different fonts. Include a sexth button that the user can click to make a font large ...

Several of the cameras in the lab can capture a greyscale

Several of the cameras in the lab can capture a greyscale image either as an 8 bit image, or as a 12 bit image. What would be the difference between them, and what would be the benefit of using one over the other? What w ...

Computer sciencewhat is required of an organization to

Computer Science What is required of an organization, to implement and maintain IT Governance? What outside resources are available to assist technology managers in the implementation and maintenance process?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As