C++ Read inFile separated by a comma and a space - c++

i am required to read a file with data of this format (Date, ID, Activity, Qty, Price) in the main test class. I'm supposed to read and store the "Date" values into int day,month,year of type Date, followed by "ID, Activity, Qty, Price" of stock class.
02/08/2011, ABC, BUY, 100, 20.00
05/08/2011, ABC, BUY, 20, 24.00
06/08/2011, ABC, BUY, 200, 36.00
i stored the values accordingly to Stock() constructor and store all data via push_back() in my own "Vector" class. what must i add/ edit so that i can retrieve the rows of data in Vector and get(Date, ID, Activity, Qty, Price) and make calculations for qty and price.
#include"Vector.h"
#include"Date.h"
#include"Stock.h"
#include<iomanip>
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int main(){
string stockcode;
string act;
int qty;
double p;
int d,m,y;
char x;
//declare file stream variables
ifstream inFile;
ofstream outFile;
//open the file
inFile.open("share-data.txt");
//code for data manipulation
cout << fixed << showpoint << setprecision(2);
while(!inFile.eof()){
inFile>> d >> x >> m >> x >> y >> x
>> stockcode >> act >> qty >> x >> p;
Stock s1(d,m,y,stockcode,act,qty,p);
stockcode = stockcode.substr(0, stockcode.length()-1);
act = act.substr(0, act.length()-1);
Stock s1(d,m,y,stockcode,act,qty,p);
stockList.push_back(s1);
}
inFile.close();
system("PAUSE");
return 0;
}
i have my own Vector class which is needed for this assignment because i am not allowed to use #include default vector
#include<iostream>
using namespace std;
template <class T>
class Vector
{
public:
Vector(); // default constructor
virtual ~Vector() {}; //destructor
bool isEmpty() const;
bool isFull() const;
void print() const;
void push_back(T);
T pop_back();
T at(int i);
int Size();
//Vector<T> operator +=(T);
private:
int size;
T list[100];
};
template <class T>
Vector<T>::Vector()
{
size = 0;
}
template <class T>
Vector<T> Vector<T>::operator +=(T i)
{
this->push_back(i);
return *this;
}
template <class T>
bool Vector<T>::isEmpty() const
{
return (size == 0);
}
template <class T>
bool Vector<T>::isFull() const
{
return (size == 100);
}
template <class T>
void Vector<T>::push_back(T x)
{
list[size] = x;
size++;
}
template <class T>
T Vector<T>::operator[](T i)
{
return list[i];
}
template <class T>
T Vector<T>::at(int i)
{
if(i<size)
return list[i];
throw 10;
}
template <class T>
T Vector<T>::pop_back()
{
T y;
size--;
y= list[size];
return y;
}
template <class T>
void Vector<T>::print() const
{
for (int i = 0; i < size; i++)
cout << list[i] << " ";
cout << endl;
}
template <class T>
int Vector<T>::Size()
{
return size;
}
and here's my Stock class
#include"Date.h"
Stock::Stock()
{
stockID="";
act="";
qty=0;
price=0.0;
}
Stock::Stock(int d, int m , int y, string id,string a, int q, double p)
:date(d,m,y){
stockID = id;
act = a;
qty = q;
price = p;
}
.
.
.

use string::substr
act = act.substr(0, act.length()-1);
You can do the same for the other string variables.

Related

BST inorder method referencing vector showing error: declaration is incompatible

I am a beginner at c++ and I am coding a program that stores data into a BST template class the being another class called log_t that stores the variables, I am trying to use the inorder method from the BST class to reference a vector from main, to input the values into and be able to use it in the main class
my main class
int main(int argc, char* argv[])
{
BST<log_t> l;
string infilename = "";
string filePath = "data\\";
string files[1] = {
filePath + "MetData-31-3a.csv"
//filePath + "Jan20071toDec31abcdefghijklmnopq",
//filePath + "Jan20081toDec31abcdefghijklmnopq",
//filePath + "MetData_Jan01-2010-Jan01-2011-ALL"
};
/// checks if file can open
for (int i = 0; i < 1; i++) {
infilename = files[i];
ifstream infile(infilename);
if (!infile.is_open())
{
cout << "unable to read file" << files[i] << endl;
}
else
{
cout << "reading file" << files[i] << endl;
}
/* parse sensor data csv file */
string tmp;
getline(infile, tmp); // skip the first line
while (getline(infile, tmp))
{
// if successfully parsed then append into vector
log_t logline;
if (ParseLog(tmp, logline))
l.insert(logline);
}
}
cout << " end with reading file" << endl;
/* aggregate/filter logs */
Vector<log_t> vec;
l.inorder(vec);
/* prompt menu */
// this array stores all the menu option callback functions
void(*funs[])(const Vector<log_t> & vec) = { NULL, &option1, &option2, &option3, &option4, &option5,&option6 };
// keep printing menu in loop
while (true)
{
// prompt menu and ask user to select option
int choice = PromptMenu();
// check validity of choice
if (choice < 1 || choice > 6)
{
cout << "invalid choice" << endl;
}
else
{
cout << endl;
// call menu option handler
(funs[choice])(vec);
}
}
system("pause");
return -1;
}
my BST class
#include <string>
#include <iostream>
#include <stream>
#include <iomanip>
#include <stream>
#include "date.h"
#include "times.h"
#include "log_t.h"
#include "Vector.h"
using namespace std;
template <class T>
class BST {
private:
struct Node {
T num;
Node* left;
Node* right;
};
Node* root = NULL;
Node* insert(Node* node, T x);
Node* newnode(T num);
void removeprivate(T num, Node* parent);
T findsmallestprivate(Node* ptr);
void inorderprivate(Node* ptr, void (BST<T>::* FT)(T&), Vector<log_t>const& log);
void postorderprivate(Node* ptr, void (BST<T>::* FT)(T&));
void preorderprivate(Node* ptr, void (BST<T>::* FT)(T&));
//void inorderprivate(Node* ptr);
//void postorderprivate(Node* ptr);
//void preorderprivate(Node* ptr);
void removematch(Node* parent, Node* match, bool left);
public:
void insert(T num);
void remove(T num);
void removerootmatch();
T findsmallest();
void inorder(Vector<log_t>const& log);
void postorder();
void preorder();
void print(T& p) { cout << p << " "; };
};
template <class T>
void BST<T>::inorder(Vector<log_t>const& log) {
inorderprivate(root,print,log);
}
template <class T>
void BST<T>::inorderprivate(Node* ptr, void (BST<T>::* FT)(T&), Vector<log_t>const&
log) {
if (root != NULL)
{
if (ptr->left != NULL)
{
inorderprivate(ptr->left, FT);
}
(this->*FT)(log);
log.Append( ptr->num);
if (ptr->right != NULL)
{
inorderprivate(ptr->right, FT);
}
}
else
{
cout << "tree is empty";
}
}
my log_t class the T type
#pragma once
#ifndef LOG_T_H
#define LOG_T_H
#include <iostream>
#include <stream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stream>
#include "date.h"
#include "times.h"
#include "BST.h"
class log_t
{
public:
log_t();
log_t(log_t& log);
float gettemp();
float getwind();
float getsolar();
void setwind(float wind);
void setsolar(float rad);
void settemp(float temp);
Date date;
Times time;
private:
float wind_speed;
float solar_radiation;
float air_temperature;
};
log_t::log_t()
{
wind_speed = 0;
solar_radiation = 0;
air_temperature = 0;
}
log_t::log_t(log_t& log) {
wind_speed = log.wind_speed;
solar_radiation = log.solar_radiation;
air_temperature = log.air_temperature;
date.SetDate(log.date.GetDay(), log.date.GetMonth(), log.date.GetYear());
time.SetHour(log.time.GetHour());
time.SetMinute(log.time.GetMinute());
}
float log_t:: gettemp()
{
return air_temperature;
}
float log_t::getwind() {
return wind_speed;
}
float log_t::getsolar() {
return solar_radiation;
}
void log_t::setwind(float wind)
{
wind_speed = wind;
}
void log_t::setsolar(float rad)
{
solar_radiation = rad;
}
void log_t::settemp(float temp)
{
air_temperature = temp;
}
#endif // LOG_T_H
my vector class
#pragma once
#ifndef VECTOR_H
#define VECTOR_H
#include <iostream>
#include <stream>
#include <string>
template <class T>
class Vector
{
public:
Vector();
Vector(int capacity);
Vector(const Vector& vec);
Vector& operator=(const Vector& vec);
~Vector();
int GetSize() const;
void Expand();
T& GetLast();
void Append(const T& val);
T& operator[](int idx);
const T& operator[](int idx) const;
private:
T* elems;
int capacity;/** < int capacity, stores the size of the array */
int count;
void CopyFrom(const Vector& vec);
};
template <class T>
inline Vector<T>::Vector() : elems(nullptr), capacity(0), count(0)
{
}
template <class T>
inline Vector<T>::Vector(int capacity)
: elems(new T[capacity]()), capacity(capacity), count(0)
{
}
template <class T>
inline Vector<T>::Vector(const Vector& vec)
{
CopyFrom(vec);
}
template <class T>
inline Vector<T>& Vector<T>::operator=(const Vector& vec)
{
if (elems)
delete[] elems;
CopyFrom(vec);
return *this;
}
template <class T>
inline Vector<T>::~Vector()
{
if (elems)
delete[] elems;
}
template <class T>
inline int Vector<T>::GetSize() const
{
return count;
}
template <class T>
inline void Vector<T>::Expand()
{
++count;
if (count > capacity)
if (capacity)
capacity *= 2;
else
capacity = 4;
T* tmp = new T[capacity]();
for (int i = 0; i < count - 1; ++i)
tmp[i] = elems[I];
if (elems)
delete[] elems;
elems = tmp;
}
template <class T>
inline T& Vector<T>::GetLast()
{
return elems[count - 1];
}
template <class T>
inline void Vector<T>::Append(const T& oval)
{
Expand();
GetLast() = val;
}
template <class T>
inline T& Vector<T>::operator[](int idx)
{
return elems[idx];
}
template <class T>
inline const T& Vector<T>::operator[](int idx) const
{
return elems[idx];
}
template <class T>
inline void Vector<T>::CopyFrom(const Vector& vec)
{
elems = new T[vec.capacity]();
capacity = vec.capacity;
count = vec.count;
for (int i = 0; i < count; ++i)
elems[i] = vec.elems[i];
}
#endif //VECTOR_H
the errors that keep showing up are
Severity Code Description Project File Line Suppression State
Error (active) E0147 declaration is incompatible with "void BST::inorder(const Vector<> &log)" (declared at line 241 of "C:\Users\Frances\Documents\A2\A2\BST.h") A2 C:\Users\Frances\Documents\A2\A2\BST.h 241
Severity Code Description Project File Line Suppression State
Error C2065 'log_t': undeclared identifier A2 C:\Users\Frances\Documents\A2\A2\BST.h 33
Severity Code Description Project File Line Suppression State
Error C2923 'Vector': 'log_t' is not a valid template type argument for parameter 'T' A2 C:\Users\Frances\Documents\A2\A2\BST.h 33
could someone help me figure out what it is that's causing this or what I am doing wrong, I have been trying to find an answer for hours and haven't been successful thank you

How can I assign class object into a class

I need to creat an object Pokemon in the main()
that assign it into the class PokemonWorld, and let the PokemonWolrd to decide which PokemonStation is this Pokemon need to go
I tired get the data separatly (get name and hp) and get together(get a Pokemon class)
but both fail
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
class Pokemon {
public:
Pokemon() {};
Pokemon(char x[], int n) {
strncpy_s(name, x, 10);
hp = n;
};
private:
char name[10];
int hp;
};
class PokemonStation {
private:
Pokemon **list= new Pokemon*[1000];
public:
PokemonStation() {};
PokemonStation(int x) {
id = x;
};
int id;
void assigntoList(int i,Pokemon x)
{
if (i > 0)
i--;
list[i] = new Pokemon(x);
cout << "creat" << list[i];
};
};
class PokemonWorld {
private:
char name[10];
public:
PokemonStation s1;
PokemonStation s2;
PokemonWorld() {};
PokemonWorld(char x[], int y=1, int z=2) {
strncpy_s(name, x, 10);
PokemonStation s1(y);
PokemonStation s2(z);
};
const char* const getName() const{
return name;
};
void assigntoStation(int i,Pokemon x) {
if (i == 0 || i % 2 == 0)
s1.assigntoList(i, x);
else
s2.assigntoList(i, x);
};
};
void main() {
int number,hp,i;
char name[10];
cout << "What is the World Name ?" <<endl;
cin >> name;
PokemonWorld world(name);
cout << "Please input the number of Pokemon in the " << world.getName() <<" world:" << endl;
cin >> number;
Pokemon **mon = new Pokemon*[number];
cout << "Please input the characteristics of all Pokemon: Name HP" << endl;
for (i = 0;i < number;i++)
{
cin >> name >> hp;
mon[i] = new Pokemon(name, hp);
world.assigntoStation(i,*(mon[i]));
}
for (i = 0;i < number;i++)
cout << "world is " << world.getName() << endl;
system("pause");
};
In C++, you should use std::vectors for dynamic lists of things and std::strings for text. If you know Java, these are like ArrayList and String. (To use these, make sure you #include <vector> and <string>.)
For instance, your Pokemon class, rewritten with name as a string:
class Pokemon {
public:
Pokemon() {}
Pokemon(string name, int hp):name(name), hp(hp) { // construct the fields directly
}
private:
string name;
int hp;
};
And your PokemonStation class, rewritten using a vector for the list of Pokemon:
class PokemonStation {
private:
vector<Pokemon> list;
public:
PokemonStation() {}
PokemonStation(int x):id(x) {}
int id;
void assignToList(Pokemon x)
{
list.push_back(x); // add x to the list
}
};
If you want to print a Pokemon with cout <<, then you'll have to overload the << operator to define what gets printed. Add this into your class:
class Pokemon {
public:
...
friend ostream& operator<<(ostream& out, const Pokemon& p) {
out << p.name; // just print the name
return out;
}
...
};
Just make sure that you're couting a Pokemon, not a pointer-to-Pokemon (Pokemon*), and you won't get an address.

How would I change an array to a vector?

so i have this code which is a checkbook program and i have to use the STL and make it do the same thing so the only thing i can think of to change is the array in it to a vector. If you think i can do more let me know, i'm a beginner level programmer and c++ is one of my weak languages.
template <class DataType>
class Checkbook
{
public:
Checkbook( );
Checkbook( float iBalance );
void setBalance( float amnt );
bool writeCheck( const DataType & amount );
void deposit( float amount );
float getBalance( ) const;
DataType getLastCheck( ) const;
float getLastDeposit( ) const;
private:
float balance;
DataType lastCheck;
float lastDeposit;
};
template <class DataType>
bool operator > (DataType tempcheck, float z)
{
if(tempcheck.amount > z)
return true;
return false;
}
template <class DataType>
float operator - (float z, DataType tempcheck)
{
z = z - tempcheck.amount;
return z;
}
#include<iostream>
using namespace std;
template <class DataType>
Checkbook<DataType>::Checkbook( )
{}
template <class DataType>
Checkbook<DataType>::Checkbook( float initBalance )
{
balance = initBalance;
}
template <class DataType>
void Checkbook<DataType>::setBalance( float amount )
{
balance = amount;
}
template <class DataType>
bool Checkbook<DataType>::writeCheck( const DataType & amount )
{
if ( amount > balance )
return false;
balance = balance - amount;
cout<<"\n\nbalance = "<<balance<<endl<<endl;
lastCheck = amount;
return true;
}
template <class DataType>
void Checkbook<DataType>::deposit( float amount )
{
balance += amount;
lastDeposit = amount;
}
template <class DataType>
float Checkbook<DataType>::getBalance( ) const
{
return balance;
}
template <class DataType>
DataType Checkbook<DataType>::getLastCheck( ) const
{
return lastCheck;
}
template <class DataType>
float Checkbook<DataType>::getLastDeposit( ) const
{
return lastDeposit;
}
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#include <sstream>
using namespace std;
struct Check
{
static string Name;
static string account;
int check;
string checkDate;
float amount;
string comment;
string receipent;
};
string Check::Name = "";
string Check::account = "";
int main( )
{
struct Check ck[100];
float balance;
float Deposit=0.0;
float WriteCheck=0.0;
time_t now = time(0);
tm *ltm = localtime(&now);
string CurrentDate;
stringstream mon, day, year;
int temp;
temp = 1 + ltm->tm_mon;
mon << temp;
temp = ltm->tm_mday;
day << temp;
temp = 1900 + ltm->tm_year;
year << temp;
CurrentDate = mon.str() + "/" + day.str() + "/" + year.str();
cout<<"\nEnter name of Account Holder : ";
getline(cin,Check::Name);
cout<<"\nEnter Account No : ";
getline(cin,Check::account);
cout <<"\nEnter your initial balance: ";
cin >> balance;
Check tempCk;
Checkbook<Check> cbook( balance );
int i=0;
int j;
int choice=0;
do
{
cout<<endl<<"1- Writing checks";
cout<<endl<<"2- Show last checks";
cout<<endl<<"3- Deposit";
cout<<endl<<"4- Show Balance";
cout<<endl<<"5- Quit";
cout<<"\n\nEnter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nCheck Number : "<<i+1<<endl;
ck[i].check = i+1;
cout<<"\nEnter receipent name : ";
getline(cin,ck[i].receipent);
cout<<"\nEnter amount : ";
cin>>ck[i].amount;
cout<<"\nDate of check : "<<CurrentDate<<endl;
ck[i].checkDate = CurrentDate;
cout<<"\nEnter Comment for check : ";
getline(cin,ck[i].comment);
if(!cbook.writeCheck(ck[i]))
{
cout<<"\n\nNot enough balance "<<ck[i].amount<<endl<<endl;
}
else
i++;
break;
case 2:
cout<<"\n\nDetails of Last Check\n\n";
cout<<"*************************";
for(j = i-1;j>=0;j--)
{
cout<<"\nCheck Number : "<<ck[j].check;
cout<<"\nDate of Check : "<<ck[j].checkDate;
cout<<"\nReceipent : "<<ck[j].receipent;
cout<<"\nAmount on Check : "<<ck[j].amount;
cout<<"\nComment : "<<ck[j].comment;
cout<<"\n*************************\n";
}
break;
case 3:
cout<<"\nEnter amount to deposit : ";
cin>>Deposit;
cbook.deposit(Deposit);
break;
case 4:
cout << fixed << showpoint << setprecision( 3 );
cout << "Current Balance is: " << cbook.getBalance( )<<" " << endl;
break;
default:
if(choice!=5)
cout<<"\n\nInvalid Entry, please try again\n";
}
}while(choice!=5);
return 0;
}
So far all i know is that i need to do this.
Check ck[100]; -> std::vector<Check> ck;
After a quick glance at your code I believe this is the only thing you have to do:
Replace
struct Check ck[100];
with:
std::vector<Check> ck(100);
Or since you have a fixed-size array you could use std::array like this:
std::array<Check,100> ck;
You can declare a local variable, in the main: Check tmp;
And the vector as: std::vector<Check> ck;
when adding new check you work on the local tmp, and when successfully done, add it to the vector.
in your code:
if(!cbook.writeCheck(tmp)){
cout<<"\n\nNot enough balance "<<tmp.amount<<endl<<endl;
}else{
ck.push_back(tmp);
}
Also, you don't need to keep the count or index, since you can use ck.size().
iterate over the ck[] and push_back every item.something like this.
std::vector<Check> ckvector;
for(int i=0;i<100;i++)
ckvector.push_back(ck[i]);

Template with Inheritance C++

Using inheritance and templates, Ive to sort by name an array of employee information. I got three classes, Payroll, SimpleVector and SortingVector. Payroll contains all the user info attributes, SimpleVector creates a dynamic array of type Payroll to store all the user info. Now do SortingVector class is in charge of sorting the array by names. But I keep getting many different errors whenever I tried to fix a previous error.
Posting now each class:
Payroll class
#pragma once
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Payroll {
private:
int empNumber;
string name;
double hours;
double payRate;
double grossPay;
int *aptr;
int arraySize;
public:
Payroll(int size);
Payroll();
Payroll(const Payroll & aPayroll);
~Payroll();
//Mutators
void setVector(Payroll &aPayroll);
void setEmpNumber(int empNumber);
void setName(string name);
void setHours(double hours);
void setPayRate(double payRate);
void setGrossPay(double grossPay);
//Accessors
int getEmpNumber()const;
string getName()const;
double getHours()const;
double getPayRate()const;
double getGrossPay()const;
Payroll &operator =(const Payroll &aPayroll);
bool operator ==(const Payroll &aPayroll) const;
friend ostream & operator << (ostream & output, const Payroll & aPayroll);
friend istream & operator >> (istream & input, Payroll & aPayroll);
};
//cpp
Payroll::Payroll() : empNumber(0), name(""), hours(0.00), payRate(0.00), grossPay(0.00) {}
Payroll::Payroll(const Payroll & aPayroll) : empNumber(aPayroll.empNumber), name(aPayroll.name), hours(aPayroll.hours),
payRate(aPayroll.payRate), grossPay(aPayroll.grossPay) {}
Payroll::~Payroll() {
}
//Mutators
void Payroll::setEmpNumber(int empNumber) {
this->empNumber = empNumber;
}
void Payroll::setName(string name) {
this->name = name;
}
void Payroll::setHours(double hours) {
this->hours = hours;
}
void Payroll::setPayRate(double payRate) {
this->payRate = payRate;
}
void Payroll::setGrossPay(double grossPay) {
this->grossPay = grossPay;
}
//Accessors
int Payroll::getEmpNumber()const {
return(this->empNumber);
}
string Payroll::getName()const {
return(this->name);
}
double Payroll::getHours()const {
return(this->hours);
}
double Payroll::getPayRate()const {
return(this->payRate);
}
double Payroll::getGrossPay()const {
return(this-> hours * payRate);
}
Payroll &Payroll::operator = (const Payroll &aPayroll) {
this->name = aPayroll.name;
this->empNumber = aPayroll.empNumber;
this->hours = aPayroll.hours;
this->payRate = aPayroll.payRate;
this->grossPay = aPayroll.grossPay;
return(*this);
}
bool Payroll::operator ==(const Payroll &aPayroll) const {
bool equal = this->name == aPayroll.name;
return(equal);
}
SIMPLEVECTOR CLASS
#ifndef SIMPLEVECTOR_H
#define SIMPLEVECTOR_H
#include <iostream>
#include <cstdlib>
#include "C:\Users\Jorge\Dropbox\PayRoll Class\Payroll.h"
using namespace std;
template <class type>
class SimpleVector {
private:
type *aptr;
int arraySize;
void subError();
public:
SimpleVector(int);
SimpleVector(const SimpleVector &aVector);
~SimpleVector();
int size() {
return arraySize;
}
type &operator [](int);
void print();
};
template <class type>
SimpleVector<type>::SimpleVector(int s) {
arraySize = s;
aptr = new type[s];
for (int count = 0; count < arraySize; count++)
aptr[count] = type();
}
template <class type>
SimpleVector<type>::SimpleVector(const SimpleVector &aVector) {
arraySize = aVector.arraySize;
aptr = new type[arraySize];
for (int count = 0; count < arraySize; count++)
aptr[count] = aVector[count];
}
template <class type>
SimpleVector<type>::~SimpleVector(){
if (arraySize > 0)
delete[] aptr;
}
template <class type>
void SimpleVector<type>::subError() {
cout << "ERROR: Subscript out of range.\n";
exit(0);
}
template <class type>
type &SimpleVector<type>::operator[](int sub) {
if (sub < 0 || sub >= arraySize)
subError();
return aptr[sub];
}
template <class type>
void SimpleVector<type>::print() {
for (int k = 0; k < arraySize; k++)
cout << aptr[k] << " ";
cout << endl;
}
#endif
SORTINGARRAY CLASS
#ifndef SortingVector_h
#define SortingVector_h
#include "SimpleVector.h"
#include <iostream>
#include <string>
template <class t>
class SortingVector : public SimpleVector<t> {
public:
SortingVector(int s) : SimpleVector<t>(s) {}
SortingVector(SortingVector &aSort);
SortingVector(SimpleVector<t> &aVector) : SimpleVector<t>(aVector) {}
void sortingByName(SimpleVector<Payroll> &aVector);
};
#endif
template <class t>
SortingVector<t>::SortingVector(SortingVector &aVector) : SimpleVector<t>(aVector) {}
template <class t>
void SortingVector<t>::sortingByName(SimpleVector<Payroll> &aVector) {
bool swap;
SortingVector<Payroll> temp;
int x;
do {
swap = false;
for (int i = 0; i < aVector.arraySize; i++) {
x = strcmp(aVector[i], aVector[i + 1]);
if (x > 0) {
temp = aVector[i];
aVector[i] = aVector[i + 1];
aVector[i + 1] = temp;
swap = true;
}
}
} while (swap);
}
The errors right now are:
Error 2 error C2248: 'SimpleVector<Payroll>::arraySize' : cannot access private member declared in class 'SimpleVector<Payroll>' c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h 39 1 SimpleVector
Error 1 error C2512: 'SortingVector<Payroll>' : no appropriate default constructor available c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h 32 1 SimpleVector
Error 3 error C2664: 'int strcmp(const char *,const char *)' : cannot convert argument 1 from 'Payroll' to 'const char *' c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h 42 1 SimpleVector
Error 4 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Payroll' (or there is no acceptable conversion) c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h 45 1 SimpleVector
Error 5 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'SortingVector<Payroll>' (or there is no acceptable conversion) c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h 47 1 SimpleVector
SortingVector<Payroll> temp(); is not parsed as you expected (vexing parse), you want:
SortingVector<Payroll> temp;
or
SortingVector<Payroll> temp{}; /* since C++11 */

Class Template and Reference Return Type

Long-time reader, first-time poster!
A few comments before I begin: I'm not looking for anyone to do my work for me, I just need a little guidance. Also, I've done a decent amount of googling, and I haven't been able to find any solutions yet.
I have a class assignment that involves creating a template for the following class:
class SimpleStack
{
public:
SimpleStack();
SimpleStack& push(int value);
int pop();
private:
static const int MAX_SIZE = 100;
int items[MAX_SIZE];
int top;
};
SimpleStack::SimpleStack() : top(-1)
{}
SimpleStack& SimpleStack::push(int value)
{
items[++top] = value;
return *this;
}
int SimpleStack::pop()
{
return items[top--];
}
Everything seems to work except SimpleStack& push(int value):
template <class T>
class SimpleStack
{
public:
SimpleStack();
SimpleStack& push(T value);
T pop();
private:
static const int MAX_SIZE = 100;
T items[MAX_SIZE];
int top;
};
template <class T>
SimpleStack<T>::SimpleStack() : top(-1)
{}
template <class T>
SimpleStack& SimpleStack<T>::push(T value)
{
items[++top] = value;
return *this;
}
template <class T>
T SimpleStack<T>::pop()
{
return items[top--];
}
I keep getting the following errors on the definition of SimpleStack& push(int value): "use of class template requires template argument list," and "unable to match function definition to an existing declaration."
Here is main if it helps:
#include <iostream>
#include <iomanip>
#include <string>
#include "SimpleStack.h"
using namespace std;
int main()
{
const int NUM_STACK_VALUES = 5;
SimpleStack<int> intStack;
SimpleStack<string> strStack;
SimpleStack<char> charStack;
// Store different data values
for (int i = 0; i < NUM_STACK_VALUES; ++i)
{
intStack.push(i);
charStack.push((char)(i + 65));
}
strStack.push("a").push("b").push("c").push("d").push("e");
// Display all values
for (int i = 0; i < NUM_STACK_VALUES; i++)
cout << setw(3) << intStack.pop();
cout << endl;
for (int i = 0; i < NUM_STACK_VALUES; i++)
cout << setw(3) << charStack.pop();
cout << endl;
for (int i = 0; i < NUM_STACK_VALUES; i++)
cout << setw(3) << strStack.pop();
cout << endl;
return 0;
}
Sorry for the excessive code pasting!
Make it
template <class T>
SimpleStack<T>& SimpleStack<T>::push(T value) {...}