// Justin C. Miller
// University of Wisconsin Oshkosh
// made for: http://www.geocities.com/neonprimetime.geo/index.html
// Unix Lab, g++ compiler
// 3-1-2001
// Title: STL Vectors 2
// Description: An application using the STL vector
#include
#include
using namespace std ;
template
void get10numbers(vector & vec) ;
template
void printMin(const vector &vec) ;
template
void printMax(const vector &vec) ;
template
void printSize(const vector &vec) ;
template
void printSum(const vector &vec) ;
template
void printVector(const vector & vec) ;
int main(){
vector< int > collection ; // create a vector to hold my integers
get10numbers(collection) ; // get 10 numbers from the user off the keyboard
printVector(collection) ; // print the 10 numbers onto the screen
printSize(collection) ; // prints the size of my collection
printSum(collection) ; // prints the sum of my collection of integers
printMin(collection) ; // prints the minimum number in your collection
printMax(collection) ; // prints the maximum number in your collection
return 0 ;
}
template
void get10numbers(vector & vec)
{
vector::const_iterator p1 ;
int x ;
cout << "Please enter your 10 favorite numbers...." << endl ;
for(int i = 1 ; i <= 10 ; i++){
cout << "Please enter #" << i << endl ;
cin >> x ;
vec.push_back(x) ;
}
}
template
void printMin(const vector &vec)
{
vector::const_iterator p1 ;
int Min = *vec.begin() ;
for(p1 = vec.begin() + 1 ; p1 != vec.end() ; ++p1)
if(*p1 < Min)
Min = *p1 ;
cout << "The Minimum number in your collection is " << Min << endl ;
}
template
void printMax(const vector &vec)
{
vector::const_iterator p1 ;
int Max = *vec.begin() ;
for(p1 = vec.begin() + 1 ; p1 != vec.end() ; ++p1)
if(*p1 > Max)
Max = *p1 ;
cout << "The Maximum number in your collection is " << Max << endl ;
}
template
void printSize(const vector &vec)
{
cout << "The current size of your collection is " << vec.size() << " elements." << endl ;
}
template
void printSum(const vector &vec)
{
vector::const_iterator p1 ;
int sum = 0 ;
for(p1 = vec.begin() ; p1 != vec.end() ; ++p1)
sum = sum + *p1 ;
cout << "The sum of all the numbers in your collection is " << sum << endl ;
}
template
void printVector(const vector & vec)
{
vector::const_iterator p1 ;
cout << "Your Collection is..." << endl ;
for(p1 = vec.begin() ; p1 != vec.end() ; ++p1)
cout << *p1 << ' ' ;
cout << endl ;
}
               (
geocities.com/neonprimetime.geo/cpp)                   (
geocities.com/neonprimetime.geo)