Write a program that reads in a sequence of characters

Assignment Help Computer Engineering
Reference no: EM132084370

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.

Reference no: EM132084370

Questions Cloud

Corporate overhead among cost centers : What is the best way to distribute corporate overhead among cost centers?
How many shares outstanding does flex have : They issued these shares at $40 and they are now trading at $50. How many shares outstanding does Flex have?
What is greenlandic pull total market value : Their preferred stock has a book value of $500,000, is currently trading at $90, and earns a dividend of $3.00. Their tax rate is 21%.
What is slopes united weighted average flotation cost : Flotation costs on equity is 15%, on debt is 5%, and on preferred stock is 7%. What is Slopes United's weighted average flotation cost?
Write a program that reads in a sequence of characters : Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.').
What is the expected return on a portfolio : Given the formula information. What is the expected return on a portfolio which is invested 40% in stock X and 60% in stock y?
What is the cost of equity : This dividend is expected to increase by 5 percent annually. The company's stock is currently selling for $35 per share. What is the cost of equity?
About clinical data repository : Which of the following is NOT true about clinical data repository (CDR)?
Total dollar return on investment : Today, you sold your shares at a price of $46 a share. What is your total dollar return on this investment?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Execute a set adt in java using a singly linked list

Execute a Set ADT in Java using a singly linked list

  Termination and resumption models of continuation

Describe three approaches to exception handling in languages that do not provide direct support for it - Summarize the arguments in favor of the termination and resumption models of continuation.

  Data-communication system

A data-communication system operates at the 28.8 kb/s (typical of the current high-speed telephone modems).

  Explain why you chose advantage and challenge that you did

Explain why you chose the advantage and challenge that you did, and provide one real-world example of each environment.

  Why would you add permissions to group instead of individual

Why would you add permissions to a group instead of the individual? List at least three different types of access control permissions you can enable for a file.

  What is the difference between formative assessment and

1 in a 750-1000 word essay draft your proposal to utilize software to support assessment in the classroom. consider the

  What is advantage of a layout manager over telling container

What is the advantage of a layout manager over telling the container place this component at position (x, y)?

  Define how referential integrity actions can be used

explain the default rules for enforcing referential integrity constraints. Explain how referential integrity actions can be used to override the default referential integrity constraints.

  Design a program that will plot a given set of points

Design a program that will plot a given set of points on a graph. The input to the program will be a text file, each line of which contains two numbers.

  Qestiona explain in details what are structuresb

questiona explain in details what are structures.b following explains how computation of commission is performed in

  Give a formal definition of the term extended stack

Give a formal definition of the term extended stack. In mathematics the Cartesian product of sets T1, T2,... ,Tn is defined as the set of all n-tuples,

  Find a case involving social engineering

Find a case involving social engineering. Be sure to explain the case. In this day an age do you believe people still become a victim of social engineering.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd