Write a function that accepts a pointer to a c string

Assignment Help C/C++ Programming
Reference no: EM131270393

Write a function that accepts a pointer to a C string as an argument and calculates the number of words contained in the string as well as the number of letters in the string. Communicate (or send) both of these values back to the main function, but DO NOT use global variables (variables defined outside of a function).

Write another function that accepts the number of letters and the number of words and sends the average number of letters per word (or average word size) back to the main function.

Demonstrate the functions in a program that asks the user to input a string. First, store the input in a large array. The program should dynamically allocate just enough memory to store the contents of that array. Copy the contents of the large array into the dynamically allocated memory. Then the program should pass that new, dynamically allocated array to the first function. Both the number of words and the average word size should be displayed on the screen. Round the average word size to 2 decimal places.

For instance, if the string argument is "Four score and seven years ago" the first function (word count) should calculate and send back a word count of 6 and a letter count of 25. The second function (average word size) should send back 4.17, or 25 / 6.

Extra challenge: See if you can prevent the program from counting punctuation (such as quotes or periods) as part of the sentence. Also, see if you can prevent the program from counting extra spaces as new words. For instance, 2 spaces will often follow a colon, such as the sentence:

"There are 3 primary colors: red, blue, and green."

In this example, the word count should be 9 (the number 3 does count as a 1-letter word), and the letter count should be 37, for an average of 4.11.

Reference no: EM131270393

Questions Cloud

Should managers promote open discussion of stereotypes : Should managers promote open discussion of stereotypes as part of a strategy for managing diversity? And what are the advantages and disadvantages of strategy
Explain several significant points : Explain several significant points that can be raised about economic goals in terms of definition, complementarity, tradeoffs, and priorities.
Describe the effective use of influence tactics : In your own experience, what is one challenge as well as one benefit in implementing an effective diversity management program? Why is embracing diversity an important role in human resources? Describe the effective use of influence tactics. What ite..
Exchange rate and the balance of payments : Use the following data to work Problems 1 to 3 The U.S. dollar exchange rate increased from $0.96 Canadian in June 2011 to $1.03 Canadian in June 2012, and it decreased from 81 Japanese yen in June 2011 to 78 yen in June 2012
Write a function that accepts a pointer to a c string : Write a function that accepts a pointer to a C string as an argument and calculates the number of words contained in the string as well as the number of letters in the string.
Use definite integrals to approximate total revenues : Use definite integrals to approximate Total revenues taken in over the 2-year period,  Total revenues taken in from t = 8 to t = 14.
Should baseball''s anti-trust exemption be discontinued : Would hosting the 2024 Olympics be a good thing for Los Angeles? Should cities and states provide public support for professional sports stadiums and arenas? Should baseball's anti-trust exemption be discontinued?
What is the x axis (q) looks like : Why the MC (marginal cost) is looks like a ''U''? When the serving is 1 (no extra production) what is the marginal cost? What is the x axis(Q) looks like?
Sketch a three-input rtl nor gate : Sketch a three-input RTL NOR gate. Use a minimum number of transistors.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Prompts the user to enter the mass of a person

Write a program that prompts the user to enter the mass of a person in kilograms and outputs the equivalent weight in pounds. Output both the mass and the weight rounded to two decimal places

  Determine the meaof the numbers in the array

Determine the mean(average) of the numbers in the array, and output the reslt. Use a subprogram to input the numbers, a function to find the mean.

  Search the maximum number from a list of numbers

Write a function to search the maximum number from a list of numbers:

  rewrite that statement in a more readable style.

Give an example statement in C, C++, or Java that is particularly unreadable. Rewrite that statement in a more readable style.

  The examination room is freed

A doctor checks in by telling the scheduler his or her name, an examination room number, and a medical specialty code. Each doctor has a favorite room. The scheduler checks to see whether the room is free. If so, it assigns this doctor to the room; i..

  Compcets of office apps

Cell Reference is the location of a cell. Cells are located in columns marked by letters, and rows are marked by numbers. Example to reference a cell in column D row 10 you would reference it as D10.

  What do you need to declare in the class

Question: What do you need to declare in the class and define to accomplish the bk3 = bk1+bk2; successfully? Design the three classes . The classes must use appropriate relationships.

  Write a program in c of fibonacci series

Write a program in c of fibonaci series with and without using fibo func, both

  How to modify this program

Directions are below the pasted code.

  Deal two cards at a time

Deal two cards at a time, print them out.- Check if they are identical, have just the same rank or just same suit or are completely.different. Print out a message indicating the result of your comparison.

  Program to check the account status

Place the account record into an appropriate structure, and store the accounts in an array of structures.

  Write a program that obtains two integer numbers from users

Pseudo code is an informal high-level and compact description of a computer programming algorithm that uses structural conventions of a programming language. Write a program that obtains two integer numbers from the user

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