Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ program

Name: Anonymous 2010-11-09 13:33

In C++, write a program that declares an array named myArray with 8 components of the type double. Initialize the array to 8 values that the user will input. Finally, pass the array as a parameter to a new function called printAllElements. This function will display values of each element in the array. You must use a separate function to print the elements.

Name: Anonymous 2010-11-10 11:42



#include <iostream>
#include <vector>

using namespace std;

typedef vector<double> DoubleVec;

template <class T>
void printAllElements(const T& container)
{
    typename T::const_iterator i = container.begin();
    const typename T::const_iterator e = container.end();
    while (i != e)
    {
        cout << *i << endl;
        ++i;
    }
}


int main(void)
{
    DoubleVec db;
    while (db.size() < 8)
    {
        double temp;
        cout << "Please input a number: ";
        cin >> temp;
        db.push_back(temp);
    }

    printAllElements(db);
    return true;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List