C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 22nd, 2004, 12:11 AM
semanticpolice semanticpolice is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 semanticpolice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face Sorting a string of characters

Here's what i need to do:



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. 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:
PHP Code:
 Enter a sequence of characters (end with '.'): do be Do boxyz
 
Letter
:    Number of Occurrences
     o     3
     d     2
     b     2
     e     1 
</FONT>
Here is what i have:

PHP Code:
#include <iostream>
using namespace std;const int ARRAY_SIZE 1000;void readChars(string list[], int &numItems);
void sort(string list[], int numItems);
void printChars(const string list[], int &numItems);int main()
{
    
string list[ARRAY_SIZE];
    
int numItems;    readChars(list, numItems);
//    sort(list, numItems);
    
printChars(list, numItemssort(list[ARRAY_SIZE], numItems);, int numItems);
}
void readChars(string list[], int &numItems)
{
    
string Char;
    
char count 0;
 
    
cout << "Enter a sequence of characters (end with '.'): ";
    
cin >> Char;
    
int subCounter 0;    list[subCounter] = Char.substr(subCounter1);
    
char period;
    while (list[
subCounter] != ".")
    {
        list[
subCounter] = Char.substr(subCounter1);
        
subCounter++;
//        cout << subCounter;
//        cout << list[2];
    
}
    
numItems subCounter;
    
cout << numItems;
}
void sort(string list[], int numItems)
{
/*
     for (int count = 0; count < numItems - 1; count++){
            swap(list[indexOfSmallest(list, count, numItems)],
                 list[count]);
        }
*/
}void printChars(const string list[], intnumItems)
{    for (
int count 0count numItemscount++){
            
cout << list[count] << " ";
    }} 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Sorting a string of characters


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT