October 1999
Beginner
304 pages
7h 11m
English
The formula for the Pentagonal numeric sequence is Pn=n*(3n-1)/2. This yields the sequence 1, 5, 12, 22, 35, and so on. Define a function to fill a vector of elements passed in to the function calculated to some user-specified position. Be sure to verify that the position specified is valid. Write a second function that, given a vector, displays its elements. It should take a second parameter identifying the type of numeric series the vector represents. Write a main() function to exercise these functions.
#include <vector> #include <string> #include <iostream> using namespace std; bool calc_elements( vector<int> &vec, int pos ); void display_elems( vector<int> &vec, const string &title, ostream &os=cout ); int main() { vector<int> ...Read now
Unlock full access