Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Textbook Page 696, Programming Question 1 (Define a class called VectorDouble).do file .cpp and .h

1 answer below »
Textbook Page 696, Programming Question 1 (Define a class called VectorDouble).do file .cpp and .h
Answered Same Day Oct 29, 2021

Solution

Sudipta answered on Oct 31 2021
138 Votes

class declaration for VectorDouble
#define VECTORDOUBLE_H
#define VECTORDOUBLE_H
#includeusing namespace std;
class VectorDouble {
    
public member functions
    public:
        VectorDouble();
        VectorDouble(int size);
        VectorDouble(const VectorDouble&v);
        
destructo
        ~VectorDouble();
        void push_back(double val);
        double value_at(int i) const;
        void change_value_at(double newVal, int i);
        int size() const;
        int capacity() const;
        void reserve (int);
        void resize(int);
        friend ostrem& operator
(ostream& outs,const VectorDouble& v);
        friend bool operator ==(const VectorDouble& v1, const VectorDouble& v2);
        void operator =(const VectorDouble& v1);
    private:
        void expandCapacity();
        double *elements;
        int maxCount;
        int count;
};
#endif VECTORDOUBLE_H
end of the class declaration
implementation of the class VectorDouble.h header file
#include#include "VectorDouble.h"
using namespace std;
default constructor to create dynamic a
ay of capacity maxCount
VectorDouble::VectorDouble(){
    elements=new double[maxCount];
    count=0;
}
parameterized constructor accepts an integer value set the capacity of the vecto
VectorDouble::VectorDouble(int size){
    maxCount=size;
    elements=new double[maxCount];
    count=0;
}
copies sthe vector values sinto the class object values
VectorDouble::VectorDouble(const VectorDouble&v){
    double*tempelements=new double[v.count];
    count=v.size();
    for(int i=0; i        tempelements[i]=v.value_at(i);
        
    }
    elements=tempelements;
    
        
}
destructor...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here