Thread: Creating a removeVowel function for Loops...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    48

    Creating a removeVowel function for Loops...

    Hi,

    Here is the problem that I was given:

    Write a program that reads in a collection of strings and displays each string read with the vowels removed. For example, if the data strings are:

    hat
    dog
    kitten
    *** (sentinel)

    the output would be:

    ht
    dg
    kttn

    Write and call a function removeVowel with prototype

    string removeVowel (string);

    that returns its argument string with the vowels removed.

    So far as I can guess, the program should begin as follows, I'm just hung up on removing the vowels:

    Code:
    .
    .
    .
    for (cin >> words; words != SENTINEL; cin >> words)
    {
    .
    .
    .
    cout << words << endl;
    Any help is appreciative...

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    i dont know what the dots are, but the first thing you should always write for a function is the definition/signature/header (you can say 'prototype' here, but it isnt exactly), along with the opening and closing parentheses.
    for example, here is a function that takes in an integer x and returns its square, as an int:
    Code:
    int sq(int x)
    {
       return x*x;
    }
    also, i would read up about for loops, for example, here: http://www.cprogramming.com/tutorial/lesson3.html.

    as with all functions/algorithms in programming, you should start by thinking about the problem in english, not in programming. if you can do that from the start, i guarantee you will be a better programmer than if you hadnt. the best way to think of it is like writing a recipe. that is, step-by-step exact instructions on how to solve the problem. pretend you have to tell a child how to do this, what would you tell them? that is what you need to tell the computer, because it doesnt know anything.

    now, after you think about the problem, have a look at the c++ String class functions here: http://www.cppreference.com/cppstring/index.html. a good one to look into might be the erase function.
    erase removes characters from a string
    that seems like what you want to do, right?

    again, hope it helps.

    ps, if your stuck and when you want to post back, please give us some details as to what youve tried and where your stuck, in english or in c++.
    Last edited by nadroj; 10-31-2007 at 08:33 PM.

  3. #3
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    i'm not sure if that for loop is correct, but you can rewrite it as

    Code:
    while ( cin >> x && x != "SENTINEL" ){/*.....*/)
    also, the standard library provides functions that may be useful for you, such as find
    http://www.cppreference.com/cppalgorithm/find.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM