[ create a new paste ] login | about

Link: http://codepad.org/HD4rB1uY    [ raw code | output | fork ]

C++, pasted on Jun 5:
#include "vectorX.h"
#include <iostream>
#include <numeric>
#include <limits>
#include <cstdlib>
using namespace std;

/* 
   Finish this function template, SumVector.
   SumVector calls vectorX::sum() and catch two exceptions thrown by vectorX::sum(), OverLargest and OverLowest.
*/
template <class T>
void SumVector(vectorX<T>& v)
{
    try
	{
		cout << v.sum() << endl;
	}
	catch(OverLargest OLarge)
	{
		cout << OLarge.message() << endl;
	}
	catch(OverLowest OLowest)
	{
		cout << OLowest.message() << endl;
	}
}

// DO NOT change main().
int main()
{
    cout <<  "--- integer test ---" << endl;
    int A[6] = {numeric_limits<int>::min() + 3, -10, 0, 6, 7,  numeric_limits<int>::max() - 3};
    vectorX<int> vi1, vi2(5, 6), vi3(6, A), vi4 = vi3;
    
    cout << "vi1 = " << vi1 << endl;
    cout << "vi2 = " << vi2 << endl;
    cout << "vi3 = " << vi3 << endl;
    cout << "vi4 = " << vi4 << endl;
    
    SumVector(vi3);
    
    cout << "ACC:" << accumulate(vi3.begin(), vi3.end(), 0) << endl;
    
    
    vi4[0] = vi4[1] = 0;
    cout << "vi4 = " << vi4 << endl;
    SumVector(vi4);
    
    vi4 = vi3;
    vi4[3] = vi4[4] = vi4[5] = 0;
    cout << "vi4 = " << vi4 << endl;
    SumVector(vi4);
    
    /*cout <<  "--- unsigned long long test ---" << endl;
    unsigned long long LL[5] ={ 0, 7, numeric_limits<unsigned long long>::max() - 3, 1, 3};
    vectorX<unsigned long long> vll1(5, LL), vll2(5, 6), vll3 = vll1;
    
    cout << "vll1 = " << vll1 << endl;
    cout << "vll2 = " << vll2 << endl;
    cout << "vll3 = " << vll3 << endl;
    
    SumVector(vll3);
    
    cout << "ACC:" << accumulate(vll3.begin(), vll3.end(), 0) << endl;
    
    vll3[2] >>= 2;
    cout << "vll3 = " << vll3 << endl;
    SumVector(vll3);
    
    cout <<  "--- float test ---" << endl;
    float F[5] ={ 1.73f, numeric_limits<float>::max() - 0.5f, 0.0f, -1.0f, -numeric_limits<float>::max() + 0.5f};
    vectorX<float> vf1(5, F), vf2 = vf1;
    
    cout << "vf1 = " << vf1 << endl;
    cout << "vf2 = " << vf2 << endl;
    
    SumVector(vf2);
    
    cout << "ACC:" << accumulate(vf2.begin(), vf2.end(), 0.0f) << endl;
    
    vf2[1] = 0.0f;
    cout << "vf2 = " << vf2 << endl;
    SumVector(vf2);
    
    vf2 = vf1;
    vf2[4] = 0.0f;
    cout << "vf2 = " << vf2 << endl;
    SumVector(vf2);
    
    cout <<  "--- double test ---" << endl;
    double D[5] ={ 1.56, numeric_limits<double>::max() - 0.5, 0.0, -1.0, -numeric_limits<double>::max() + 0.5};
    vectorX<double> vd1(5, D), vd2 = vd1;
    
    cout << "vd1 = " << vd1 << endl;
    cout << "vd2 = " << vd2 << endl;
    
    SumVector(vd2);
    
    cout << "ACC:" << accumulate(vd2.begin(), vd2.end(), 0.0f) << endl;
    
    vd2[1] = 0.0f;
    cout << "vd2 = " << vd2 << endl;
    SumVector(vd2);
    
    vd2 = vd1;
    vd2[4] = 0.0f;
    cout << "vd2 = " << vd2 << endl;
    SumVector(vd2);*/
}


Output:
1
2
3
Line 20: error: vectorX.h: No such file or directory
Line 13: error: variable or field 'SumVector' declared void
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: