Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,480 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,700 people online right now. Registration is fast and FREE... Join Now!




Vowel Occurence in a String Input

 
Reply to this topicStart new topic

Vowel Occurence in a String Input, Help me.. i'm dying!

bengt23648
5 Mar, 2008 - 06:05 PM
Post #1

New D.I.C Head
*

Joined: 30 Jun, 2007
Posts: 37


My Contributions
Create an Interactive Program that accepts a string into an array. Count the number of times a character occurs in a given string then reverses the string and displays it. Implement everything (from input to output) using pointers.

here's my code:
CODE

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>


void sort(int a, char *p)
{
    char *temp;
    for(int i=0;i<a-1;i++)
    {
        for(int j=i+1;j<a;j++)
        {
            if(*(p+i)>*(p+j))
            {
                *temp=*(p+i);
                *(p+i)=*(p+j);
                *(p+j)=*temp;
            }
        }
    }
}

void main()
{
    clrscr();
    char arr[100];
    char arr1[30];
    int arr2[30];
    int count=1,b=0,q=0;
    char *p,*p1;
    int *p2;
    p1=&arr1[q];
    p2=&arr2[q];
    int a;

    cout<<"Enter a string: ";
    gets(arr);
    p=&arr[q];
    a=strlen(arr);
    cout<<"\n\n\n"<<strrev(arr);
    sort(a,p);
    cout<<"\n\n\n";

    for(int i=0;i<strlen(arr);)
    {
        while(*(p+i)==*(p+i+1))
        {
            count++;
            i++;
        }

        *(p1+b)=*(p+i);
        *(p2+b)=count;
        count=1;
        b++;
        i++;
    }

    for(i=0;i<b;i++)
    {
        cout<<"Character "<<*(p1+i)<<" occurs "<<*(p2+i)<<" time/s";
        cout<<"\n\n";
    }
    getch();
}



well, there's nothing wrong with that code. I would just like to enhance it to be able to solve this problem:

Write a program to count the vowels and letters in free text given as standard input. Read text a character at a time until you encounter end-of-data.

Then print out the number of occurrences of each of the vowels a, e, i, o, u in th the text, the total number of letters, and each of the vowels as an integer percentage of the letter total.


Suggested output format is:

Numbers of characters:
a 3; e 2; i 0; o 1; u 0; rest 17
Percentages of total:
a 13%; e 8%; i 0%; o 4%; u 0%; rest 73%


how can i solve this using the code i've made for the first problem?? please help me.. thanks a lot!

This post has been edited by bengt23648: 5 Mar, 2008 - 06:06 PM
User is offlineProfile CardPM
+Quote Post

bhandari
RE: Vowel Occurence In A String Input
6 Mar, 2008 - 12:30 AM
Post #2

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
when you are counting the characters, check if the character at hand is vowel (any of a e i o u). If yes then increment the counter for it.
After loop ends you have count of each vowel and total number of characters. Now you can easily calculate the percentage.

No code sorry!!! policy:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

code.gif
User is offlineProfile CardPM
+Quote Post

bengt23648
RE: Vowel Occurence In A String Input
6 Mar, 2008 - 02:43 AM
Post #3

New D.I.C Head
*

Joined: 30 Jun, 2007
Posts: 37


My Contributions
QUOTE(bhandari @ 6 Mar, 2008 - 01:30 AM) *

when you are counting the characters, check if the character at hand is vowel (any of a e i o u). If yes then increment the counter for it.
After loop ends you have count of each vowel and total number of characters. Now you can easily calculate the percentage.

No code sorry!!! policy:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

code.gif


yeah.. i understand the policy.. biggrin.gif

anyway, thanks for the idea.. tongue.gif

but i still don't get it.. sorry.. rolleyes.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 06:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month