Question: Having trouble figuring out why my program keeps crashing this is coded in c++. the error in my IDE is currently syntax error: missing, before
Having trouble figuring out why my program keeps crashing this is coded in c++. the error in my IDE is currently "syntax error: missing"," before '<'" in the "class gVector: public vector
//gVector.h
#pragma once
#include
template
class gVector: public vector
{
public:
gVector(int low, int high);
// vector has high - low+1 elements in range [low,high]
T& operator [] (int i);
// operator verifies that lower <= i <= upper.
// if not, it throws the indexRangeError exception
void resize(int lowIndex, int highIndex);
// resize vector and set range to [lowIndex, highIndex]
private:
int lower;
int upper;
};
#include "gVector.cpp"
--------------------------------------------------------------------
//gVector.cpp
#ifndef __G_VECTOR_CPP__
#define __G_VECTOR_CPP__
#include "gVector.h"
// For all gVector
template
//You must implement utilize vector
gVector
vector
lower = low;
upper = high;
}
//Override vector
//You must implement
template
T& gVector
if ((i < lower) || (i > upper)) {
throw indexRangeError("index range error", i, size());
}
else {
return gVector
}
}
//Overload vector
//You must implement
template
void gVector
if (!(low <= high)) {
int temp;
temp = low;
low = high;
high = temp;
}
else {
vector.resize(highIndex - lowIndex + 1);
lower = lowIndex;
upper = highIndex;
}
}
#endif
-------------------------------------------------------------------------
//mainDriver.cpp
#include
#include "gVector.h" //use gVector class
#include "CS255_Exceptions.h"
using namespace std;
int main() {
// this test declares and defines two types of gVector objects
const int MIN_TEMP = -10;
const int MAX_TEMP = 15;
gVector
gVector
// a very simple encryption of upper-case Latin letters
for (char ch = 'A'; ch <= 'Z'; ch++)
code[ch] = ch + 5;
// tempVector [cel_temp] holds Fahrenheit equivalent of Celsius
// temperature cel_temp. Conversion is F = 9/5 C + 32
for (int cel_temp = MIN_TEMP; cel_temp <= MAX_TEMP; cel_temp++)
fahrVector[cel_temp] = 9.0 / 5.0*cel_temp + 32.0;
// Show simple encryption shift
cout << "Encryption Shift:" << endl;
for (char ch = 'A'; ch <= 'Z'; ch++)
cout << ch;
cout << endl;
for (char ch = 'A'; ch <= 'Z'; ch++)
cout << code[ch];
cout << endl << endl;
// output the temperature conversions
cout << "Temperature Conversion C - > F:" << endl;
cout << " C" << " " << "F" << endl;
for (int cel_temp = MIN_TEMP; cel_temp <= MAX_TEMP; cel_temp++) {
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout.width(7);
cout << cel_temp << " " << fahrVector[cel_temp] << endl;
}
return 0;
}
--------------------------------------------------------------------------------------
#pragma once
#ifndef __CS255_EXCEPTION_CLASSES__
#define __CS255_EXCEPTION_CLASSES__
#include
#include
using namespace std;
class baseException
{
public:
baseException(const string& str = "") :
msgString(str)
{
if (msgString == "")
msgString = "Unspecified exception";
}
string what() const
{
return msgString;
}
// protected allows a derived class to access msgString.
protected:
string msgString;
};
// failure to allocate memory (new() returns NULL)
class memoryAllocationError : public baseException
{
public:
memoryAllocationError(const string& msg = "") :
baseException(msg)
{}
};
// function argument out of proper range
class rangeError : public baseException
{
public:
rangeError(const string& msg = "") :
baseException(msg)
{}
};
// index out of range
class indexRangeError : public baseException
{
public:
indexRangeError(const string& msg, int i, int size) :
baseException()
{
ostringstream indexErr;
indexErr << msg << " index " << i << " size = " << size << ends;
// indexRangeError can modify msgString, since it is in
// the protected section of baseException
msgString = indexErr.str();
}
};
// attempt to erase from an empty container
class underflowError : public baseException
{
public:
underflowError(const string& msg = "") :
baseException(msg)
{}
};
// attempt to insert into a full container
class overflowError : public baseException
{
public:
overflowError(const string& msg = "") :
baseException(msg)
{}
};
// error in expression evaluation
class expressionError : public baseException
{
public:
expressionError(const string& msg = "") :
baseException(msg)
{}
};
// bad object reference
class referenceError : public baseException
{
public:
referenceError(const string& msg = "") :
baseException(msg)
{}
};
// feature not implemented
class notImplementedError : public baseException
{
public:
notImplementedError(const string& msg = "") :
baseException(msg)
{}
};
// date errors
class dateError : public baseException
{
public:
dateError(const string& first, int v, const string& last) :
baseException()
{
ostringstream dateErr;
dateErr << first << ' ' << v << ' ' << last << ends;
// dateError can modify msgString, since it is in
// the protected section of baseException
msgString = dateErr.str();
}
};
// error in graph class
class graphError : public baseException
{
public:
graphError(const string& msg = "") :
baseException(msg)
{}
};
// file open error
class fileOpenError : public baseException
{
public:
fileOpenError(const string& fname) :
baseException()
{
ostringstream fileErr;
fileErr << "Cannot open \"" << fname << "\"" << ends;
// fileOpenError can modify msgString, since it is in
// the protected section of baseException
msgString = fileErr.str();
}
};
// error in graph class
class fileError : public baseException
{
public:
fileError(const string& msg = "") :
baseException(msg)
{}
};
#endif // __CS255_EXCEPTION_CLASSES__
-----------------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
