Show us the code from your initial attempt and describe the shortcomings.
OK, but please don't laugh. I am not good at coding so I'm sure you'll find plenty of mistakes. BTW, I am also having a problem creating objects of my job class using templates (that's why it's commented out).
My assignment is to put these jobs (each line of the input file) into a queue based on its type; mm, fp or txt. So I will need 3 queues.
So my idea was to read each job or line from the file, place it in a job object called "buff", determine its type, place it in its appropriate job object (mm, fp or txt) and read the next line into the "buff" object until all the lines have been read and sorted into their approriate objects.
Thanks for looking!
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
template <class ItemType>
class job
{
public:
job()
{
ItemType switches=0;
ItemType fTime=0;
ItemType urgent=0;
}
job::~job()
{
}
job<ItemType>* next;
job<ItemType>* back;
void setName(ItemType name);
ItemType getName();
void setLength(ItemType length);
void decLength(ItemType length);
ItemType getLength();
void setAtime (ItemType time);
ItemType getAtime();
void setStime (ItemType sTime);
ItemType getStime();
void setFtime (ItemType fTime);
ItemType getFtime();
void incSwtch (ItemType switches);
ItemType getSwitch();
void setType (ItemType type);
ItemType getType();
void setBool (ItemType urgent);
ItemType getBool();
private:
ItemType _name;
ItemType _length;
ItemType _aTime;
ItemType _sTime;
ItemType _fTime;
ItemType _switches;
ItemType _type;
ItemType _urgent;
};
int main()
{
/*
job<ItemType> buff;
job<ItemType> mm;
job<ItemType> txt;
job<ItemType> fp;
*/
ifstream iFile("d:/input1.txt");
if (! iFile)
{
cout << "Error opening input file" << endl;
return -1;
}
cout << "File opened" << endl;
while(!iFile.eof())
{
getline(iFile, buff.name, ' ');
getline(iFile, buff.length, ' ');
getline(iFile, buff.aTime, ' ');
getline(iFile, buff.type, ' ');
getline(iFile, buff.urgent, ' ');
}
iFile.close();
template<class ItemType>
void job<ItemType>::setName(ItemType name)
{
_name=name;
}
template<class ItemType>
ItemType job<ItemType>::getName()
{
return _name;
}
template<class ItemType>
void job<ItemType>::setLength(ItemType length)
{
_length=length;
}
template<class ItemType>
void job<ItemType>::decLength(ItemType length)
{
_length=_length-50;
}
template<class ItemType>
ItemType job<ItemType>::getLength()
{
return _length;
}
template<class ItemType>
void job<ItemType>::setAtime (ItemType aTime)
{
_aTime=aTime;
}
template<class ItemType>
ItemType job<ItemType>::getAtime()
{
return _aTime;
}
template<class ItemType>
void job<ItemType>::setStime (ItemType sTime)
{
_sTime=sTime;
}
template<class ItemType>
ItemType job<ItemType>::getStime()
{
return _sTime;
}
template<class ItemType>
void job<ItemType>::setFtime (ItemType fTime)
{
_fTime=fTime;
}
template<class ItemType>
ItemType job<ItemType>::getFtime()
{
return _fTime;
}
template<class ItemType>
void job<ItemType>::incSwtch (ItemType switches)
{
_switches++;
}
template<class ItemType>
ItemType job<ItemType>::getSwitch()
{
return _switches;
}
template<class ItemType>
void job<ItemType>::setType (ItemType type)
{
_type=type;
}
template<class ItemType>
ItemType job<ItemType>::getType()
{
return _type;
}
template<class ItemType>
void job<ItemType>::setBool (ItemType urgent)
{
_urgent=urgent;
}
template<class ItemType>
ItemType job<ItemType>::getBool()
{
return _urgent;
}