473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

need help to write some programs

19
plz, can you tell me how to write a c program (using functions)
i)to count the number of words in a sentence
ii)menu driven program to sort n names
iii)to sort the alphabets in a name,&to count the number of vowels, consonants,spaces&special characters in a sentence which is read from the user
advance thanx to those who help me
Oct 13 '06 #1
1 2247
D_C
293 100+
i) The number of words in a sentence is proportional to how many spaces you encounter. If it's single spaced, there may be one less space than word. If it's double spaced, it's probably 2* the number of words - 1. A finite state machine would easily describe how to do this. I assume there are no spaces after the last period, otherwise it may be off by one.
Expand|Select|Wrap|Line Numbers
  1. int count = 1;
  2. // string input = // some sentence
  3. // point a pointer at input
  4. while(the character pointed at by the pointer != '\0')
  5. {
  6.   while(contents of the pointer != ' ')
  7.     increment the pointer; // update it to next char
  8.   count++
  9.   while(contents of the pointer == ' ')
  10.      increment the pointer; // update it to next char
  11. }
ii) Do you know the value of N before you start entering the words to be sorted? In that case, you could use an array, of course link list also applies. In either case, I would use insertion sort.
Expand|Select|Wrap|Line Numbers
  1. input = // get next word
  2. cursor = first element in linked list/array
  3. while(input > cursor element)
  4.   cursor = next cursor;
  5. insert input, pushing the rest of the entries further down.
iii)Read in the name, sort it, then loop through each character, and if it qualifies as anything else, increment the counter. An example would have helped. Should "MacGyver" be "aceGMrvy" or "GMacervy"
Expand|Select|Wrap|Line Numbers
  1. // string input = "MacGyver" (for example)
  2. string sorted = "";
  3. int vowel_cnt = 0;
  4. int cnsnt_cnt = 0;
  5. int space_cnt = 0;
  6. int other_cnt = 0;
  7.  
  8. while(input.length() > 0)
  9. {
  10. // find the index of the character with the minimum value.
  11. // you may need to use pointer
  12. // a character array would be easier though.
  13.   sorted += // char with minimum value
  14.   if(char with min value is space)
  15.     space_cnt++;
  16.   else if('a' < the lowercase of char of min value < 'z') 
  17.   {
  18.     if(char with min value is a vowel)
  19.       vowel_cnt++;
  20.     else
  21.       cnsnt_cnt++;
  22.   }
  23.   else // assume special means not a space, vowel, or consonant
  24.     other_cnt++;
  25. }
  26.  
  27. // display string sorted, and the four counters.
  28. }
Oct 13 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Patrick Useldinger | last post by:
Hi, I think I found a bug in the write method of file objects. It seems as if before writing each block, a check was done in order to verifiy that there is enough space left for the *whole*...
33
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
5
by: Mr. X | last post by:
Hello, Let me begin by saying that I am a strong advocate of science, math and engineering students learning to program... just a skill that they need to experience even if they go another path....
70
by: rahul8143 | last post by:
hello, 1) First how following program get executed i mean how output is printed and also why following program gives different output in Turbo C++ compiler and Visual c++ 6 compiler? void main()...
8
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of...
85
by: | last post by:
List, I'm looking for C links for Standard C for a website targeting professional SW engineers. Intent is to have a convenient reference to Standard C, particularly for those who come from...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
1
by: karizmatrix22 | last post by:
Hi, I need a programmer who can write 3 programs for following questions below.Programs need to be ready before nextweek.thank you. Person who help me these 3 questions will be get paid.. I am...
27
by: duli | last post by:
Hi: I would like recommendations for books (in any language, not necessarily C++, C, python) which have walkthroughs for developing a big software project ? So starting from inception, problem...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.