Results 1 to 2 of 2

Thread: function prototype and definition question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    18

    function prototype and definition question

    Im a beginner in C++ and I have this program here:

    #include <iostream>
    #include <vector>
    #include <cmath> //abs()

    using namespace std;

    void RotateLetters (vector <char> & CharList, int NumPositions);

    int main (void)
    {
    vector <char> Alphabet (26);

    for (int cnt = 0; cnt < 26; cnt++)
    Alphabet [cnt] = char (cnt + ‘A’);

    cout << “How many positions do you intend to rotate this alphabet list? “
    << “ ‘-‘ means rotate upward; otherwise downward.” << endl;

    int Positions;

    cin >> Positions;

    RotateLetters (Alphabet, Positions);

    for (cnt = 0; cnt < Alphabet.size(); cnt++)
    cout << Alphabet[cnt];

    cout << endl;

    return 0;
    }
    //Purpose: Rotate the letters in CharList either upward or downward depending
    // on the sign of the integer argument
    //Precondition: CharList is a char vector containing the 26 alphabetical letters,
    // NumPositions is the desired position for the 26 letters to rotate –
    // ‘+’ or no sign => downward and ‘-‘ => upward
    //Postcondition: The CharList vector is rotated accordingly

    void RotateLetters (vector <char> & CharList, int NumPositions)


    How do I supply the function prototype and definition for the function RotateLetters() ????

  2. #2
    Member
    Join Date
    Oct 2002
    Location
    Look out your window.
    Posts
    54
    Well you already have the function's prototype. You just need to give it's definition.

    Like so.

    Code:
    void RotateLetters (vector <char> & CharList, int NumPositions) 
    {
        // Rotate characters here.
        return;
    }
    It is defined in the same manner as main().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width