Hi. I'm getting the following message when I try to overload operator= here in line 830-833. I have also included the error messages.
Thanks
#include <iostream>
#include <string>
#include <limits>
#include <vector>
#include <iomanip>
#include <cstdlib>
using namespace std;
/**
* Global Variables
*/
string k;
int pmem, plen;
int dmem, dlen;
int cmem, clen;
string dname, pname, cname, drw, prw, crw;
int g_pid = 0;
float g_tau = 0;
int g_tau2 = 0;
float g_tau3 = 0;
float tempTau;
int counter = 0;
/**
* Process Control Block Class
*/
class PCB
{
public:
PCB() : pid (0), filename ( "InitialString" ), memoryLocation ( 0 ), rw ( "InitialString" ), fileLen ( 0 ), procTime( 0 ), tau( 0 ) { }
void setPid( int p );
int getPid() const;
void setFilename( string f );
string getFilename() const;
void setMemoryStart( int m );
int getMemoryStart() const;
void setFileLength( int l );
int getFileLength() const;
void setRW( string r );
string getRW() const;
void setTime( float t ); // Used to set "how long" time
float getTime() const;
void setTime2( float t );
float getTime2() const;
float addTime(); // Used to add times at end of burst
void setTau( float t );
float getTau() const;
void setAlpha( float a );
float getAlpha() const;
void setCylin( int cc );
int getCylin() const;
float calculateTau(); // Used to calculate tau value in ready queue
void setCpuTime( float c );
float getCpuTime() const;
bool operator<( const PCB& other ) const;
bool operator>( const PCB& other ) const;
bool operator=( const PCB& other );
PCB findMin( vector<PCB> & v );
PCB insertionSort( vector<PCB> & v, int length );
private:
int pid;
string filename;
int memoryLocation;
string rw;
int fileLen;
int procTime;
int cylinder;
float tau;
static float alpha;
float cpuTime;
static float time;
static float time2;
static float time3;
};
/*
* Computer structure
*/
struct computer
{
int printer;
int disk;
int cd;
vector<PCB> readyQueue;
vector<PCB> printerQueues[9];
vector<PCB> diskQueues[9];
vector<PCB> cdQueues[9];
vector<int> time;
vector<PCB> vCylinder;
void screen();
void prompt();
void setNum2( int j );
void runningPrompt();
void calculate();
int & findMin( vector<int> & v );
int findPos( vector<int> & vv );
void removeElem();
void pScreenLoop();
void dScreenLoop();
void cScreenLoop();
};
/**
* Sys Gen Process begins here. Prompt the user for input.
*/
void computer::prompt()
{
cout << "Welcome to the Sys Gen Process"<<endl;
cout<<"Please enter the number of printers in the system (between 1 and 9)"<<endl;
while( ! ( cin >> printer ) )
{
cout << "That was not an integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
while(printer<1 || printer>9)
{
cout<<"Sorry, that is an invalid value, please re-enter amount of printers:"<<endl;
while( ! ( cin >> printer ) )
{
cout << "That was not an integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
}
cout<<"Thank you. Please enter the number of disks in the system (between 1 and 9)"<<endl;
while( ! ( cin >> disk ) )
{
cout << "That was not an integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
while(disk<1 || disk>9)
{
cout<<"Sorry, that is an invalid value, please re-enter amount of disks:"<<endl;
while( ! ( cin >> disk ) )
{
cout << "That was not an integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
}
cout<<"Please enter the number of CD/RW's in the system (between 1 and 9)"<<endl;
while( ! ( cin >> cd ) )
{
cout << "That was not an integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
while(cd<1 || cd>9)
{
cout<<"Sorry, that is an invalid value, please re-enter amount of CD/RW's:"<<endl;
while( ! ( cin >> cd ) )
{
cout << "That was not an integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
}
cout << "Please enter an initial burst tau: " << endl;
PCB t;
string inputTau;
cin >> inputTau;
tempTau = atof(inputTau.c_str());
while( tempTau <= 0 )
{
cout << "Please enter a value such as 10" << endl;
cin >> inputTau;
tempTau = atof(inputTau.c_str());
}
t.setTau( tempTau );
g_tau = tempTau;
cout << "Please enter a value for alpha: " << endl;
string inputAlpha;
float tempAlpha;
cin >> inputAlpha;
tempAlpha = atof(inputAlpha.c_str());
while( tempAlpha <= 0 )
{
cout << "Please enter a value such as 0.9" << endl;
cin >> inputAlpha;
tempAlpha = atof(inputAlpha.c_str());
}
t.setAlpha( tempAlpha );
cout << "Please enter how many cylinders for each disk: " << endl;
string inputCylinder;
int tempCylinder;
for( int i = 1; i < disk + 1; i++ )
{
cout << "Disk[" << i << "]:" << endl;
cin >> inputCylinder;
tempCylinder = atof(inputCylinder.c_str());
while( tempCylinder <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputCylinder;
tempCylinder = atof(inputCylinder.c_str());
}
t.setCylin( tempCylinder );
vCylinder.push_back( t );
}
}
/**
* This runningPrompt Function receives input from the keyboard regarding processes
*/
void computer::runningPrompt()
{
cout << "You may enter a command or type 'exit' to exit the system." << endl;
PCB process;
int num;
while (k != "exit")
{
cout << "Please enter command: ";
cin >> k;
if( k[0] == 'A' )
{
if( !readyQueue.empty() )
{
cout << "Interrupt detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
g_pid++;
process.setPid( g_pid );
process.setTime( timeTemp ); // Time is set for incoming process if a process already exists in ready Queue
readyQueue.push_back( process );
calculate(); // Function called to subtract "how long" time, from inital burst time
counter++;
}
else
{
cout << "New Process created." << endl;
g_pid++;
process.setPid( g_pid );
process.setTau( tempTau );
g_tau = tempTau;
readyQueue.push_back( process );
}
}
if( k[0] == 'L' ) // this is a test construct
{
//PCB j;
//cout << "the value of get time is :" << j.getTime() << endl;
//cout << j.calculateTau() << endl;
//calculate();
/*for( int i = 0; i < g_pid; i++ )
readyQueue.push_back( j.findMin( readyQueue ) );
for( int i = 0; i < g_pid; i++ )
readyQueue.erase( readyQueue.begin() );*/
//cout << cdQueues[0][0].getTau() << endl;
//cout << j.getTau() << endl;
//cout << j.getAlpha() << endl;
//j.calculate();
//cout << j.getTau() << endl;
//cout << readyQueue[0].calculate() << endl;
//cout << readyQueue[1].calculate() << endl;
}
if( k[0] == 't' )
{
if( !readyQueue.empty() )
{
cout << "Interrupt detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
cout << "Process terminating." << endl;
readyQueue.erase( readyQueue.begin() );
}
else
{
cout << "Ready queue is empty." << endl;
}
}
if( k[0] == 'S' )
{
cout << "Interrupt detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
screen();
}
if( k[1] == '1' )
num = 0;
if( k[1] == '2' )
num = 1;
if( k[1] == '3' )
num = 2;
if( k[1] == '4' )
num = 3;
if( k[1] == '5' )
num = 4;
if( k[1] == '6' )
num = 5;
if( k[1] == '7' )
num = 6;
if( k[1] == '8' )
num = 7;
if( k[1] == '9' )
num = 8;
if ( k[0] == 'd' ) // When disk number is entered, start here.
{
if( disk >= num )
{
if( !readyQueue.empty() )
{
cout << "System Call detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
process.setTime2( timeTemp );
cout << "This is a system call requesting Disk " << num << endl;
cout << "What is the filename? Please enter it: " << endl;
cin >> dname;
process.setFilename( dname );
cout << "What is the starting location in memory? Please enter it:" << endl;
while( ( ! ( cin >> dmem ) ) || dmem < 0 )
{
cout << "That was not a positive integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
process.setMemoryStart( dmem );
cout << "Please enter the length of your file in an integer value:" << endl;
while( ( ! ( cin >> dlen ) ) || dlen < 0 )
{
cout << "That was not positive integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
process.setFileLength( dlen );
cout << "Please enter r for read or w for write" << endl;
cin >> drw;
while( ! ( drw == "r" || drw == "w" ) )
{
cout << "Please enter a r or a w" << endl;
cin >> drw;
}
process.setRW( drw );
process.setPid( readyQueue.front().getPid() );
g_tau3 = process.calculateTau();
process.setTau( g_tau3 );
diskQueues[num].push_back( process );
readyQueue.erase( readyQueue.begin());
}
else
{
cout << "There are no processes in the ready queue." << endl;
}
}
else
{
cout << "Please enter a valid disk number" << endl;
}
}
if ( k[0] == 'p' )
{
if( printer >= num )
{
if( !readyQueue.empty() )
{
cout << "System call detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
process.setTime2( timeTemp );
cout << "This is a system call requesting printer: " << num+1 << endl;
cout << "What is the filename? Please enter it: " << endl;
cin >> pname;
process.setFilename( pname );
cout << "What is the starting location in memory? Please enter it:" << endl;
while( ( ! ( cin >> pmem ) ) || pmem < 0 )
{
cout << "That was not a positive integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
process.setMemoryStart( pmem );
cout << "Please enter the length of your file in an integer value:" << endl;
while( ( ! ( cin >> plen ) ) || plen < 0 )
{
cout << "That was not positive integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
process.setFileLength( plen );
process.setPid( readyQueue.front().getPid() );
g_tau3 = process.calculateTau();
process.setTau( g_tau3 );
readyQueue.erase( readyQueue.begin());
printerQueues[num].push_back( process );
}
else
{
cout << "There are no processes in the ready queue." << endl;
}
}
else
{
cout << "Please enter a valid printer number" << endl;
}
}
if ( k[0] == 'c' )
{
if( cd >= num )
{
if( !readyQueue.empty() )
{
cout << "System Call detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
process.setTime2( timeTemp );
cout << "This is a system call requesting CD/RW: " << num << endl;
cout << "What is the filename? Please enter it: " << endl;
cin >> cname;
process.setFilename( cname );
cout << "What is the starting location in memory? Please enter it:" << endl;
while( ( ! ( cin >> cmem ) ) || cmem < 0 )
{
cout << "That was not a positive integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
process.setMemoryStart( cmem );
cout << "Please enter the length of your file in an integer value:" << endl;
while( ( ! ( cin >> clen ) ) || clen < 0 )
{
cout << "That was not positive integer...\nTry again: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
}
process.setFileLength( clen );
cout << "Please enter r for read or w for write" << endl;
cin >> crw;
while( ! ( crw == "r" || crw == "w" ) )
{
cout << "Please enter a r or a w" << endl;
cin >> crw;
}
process.setRW( crw );
process.setPid( readyQueue.front().getPid() );
g_tau3 = process.calculateTau();
process.setTau( g_tau3 );
cdQueues[num].push_back( process );
readyQueue.erase( readyQueue.begin() );
}
else
{
cout << "There are no processes in the ready queue." << endl;
}
}
else
{
cout << "Please enter a valid CD/RW number. " << endl;
}
}
if( k[0] == 'D' )
{
if( !diskQueues[num].empty() )
{
cout << "System call detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
process.setTime( timeTemp );
counter = 0;
calculate();
int kk = diskQueues[num].front().getPid();
process.setPid( kk );
readyQueue.push_back( process );
diskQueues[num].erase( diskQueues[num].begin() );
}
else
{
cout << "The disk queue is empty. " << endl;
}
}
if( k[0] == 'P' )
{
if( !printerQueues[num].empty() )
{
cout << "System call detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
process.setTime( timeTemp );
counter = 0;
calculate();
int kk = printerQueues[num].front().getPid();
process.setPid( kk );
readyQueue.push_back( process );
printerQueues[num].erase( printerQueues[num].begin() );
}
else
{
cout << "The printer queue is empty. " << endl;
}
}
if( k[0] == 'C' )
{
if( !cdQueues[num].empty() )
{
cout << "System call detected" << endl;
cout << "How long? " << endl;
string inputTime;
cin >> inputTime;
int timeTemp;
timeTemp = atof( inputTime.c_str() );
while( timeTemp <= 0 )
{
cout << "Please enter an integer value: " << endl;
cin >> inputTime;
timeTemp = atof(inputTime.c_str());
}
process.setTime( timeTemp );
counter = 0;
calculate();
int kk = cdQueues[num].front().getPid();
process.setPid( kk );
readyQueue.push_back( process );
cdQueues[num].erase( cdQueues[num].begin());
}
else
{
cout << "The CD/RW queue is empty. " << endl;
}
}
}
}
/**
* User can get a "Screen Shot" by typing "S" at command line.
*/
void computer::screen()
{
PCB p1;
cout << "Taking Snapshot." << endl;
cout << "Please select r, d, p, or c." << endl;
string rpdc;
cin >> rpdc;
while ( ! ( rpdc[0] == 'r' || rpdc[0] == 'p' || rpdc[0] == 'd' || rpdc[0] == 'c' ) )
{
cout << "Please enter r, p, d, or c. Thank you." << endl;
cout << "Enter selection" << endl;
cin >> rpdc;
}
if( rpdc[0] == 'r' )
{
cout << left << setw(9) << "PID" << left << setw(14) << "CPU Time"
<< left << setw(14) << "Tau" << " R/W" << endl;
if( !readyQueue.empty() )
{
for( int i = 0; i < readyQueue.size(); i++ )
{
cout << left << setw(0) << "" << readyQueue[i].getPid() << left << setw(8) << " "
<< left << setw(14) << " " << left << setw(14) << readyQueue[i].getTau()
<< left << setw(14) << " " << " " << " " << endl;
}
}
else
{
cout << left << setw(0) << "" << "0" << left << setw(4) << " "
<< left << setw(14) << " " << left << setw(14) << " "
<< left << setw(14) << " " << " " << endl;
}
}
if( rpdc[0] == 'p' )
{
cout << endl;
cout << left << setw(8) << "PID" << setw(14) << "Filename"
<< setw(14) << "Memstart" << setw(14) << "FileLen" << " Tau" << endl;
pScreenLoop();
}
if( rpdc[0] == 'd' )
{
cout << endl;
cout << left << setw(8) << "PID" << left << setw(14) << "Filename"
<< left << setw(14) << "Memstart" << left << setw(14) << "FileLen" << setw(14) << " R/W" << "Tau" << endl;
dScreenLoop();
}
if( rpdc[0] == 'c' )
{
cout << endl;
cout << left << setw(8) << "PID" << left << setw(14) << "Filename"
<< left << setw(14) << "Memstart" << left << setw(14) << "FileLen" << setw(14) << " R/W" << "Tau" << endl;
cScreenLoop();
}
}
/**
* Member function definititions follows:
*/
void PCB::setPid(int p)
{
pid = p;
}
int PCB::getPid() const
{
return pid;
}
void PCB::setFilename( string f )
{
filename = f;
}
string PCB::getFilename() const
{
return filename;
}
void PCB::setMemoryStart( int m )
{
memoryLocation = m;
}
int PCB::getMemoryStart() const
{
return memoryLocation;
}
void PCB::setFileLength( int l )
{
fileLen = l;
}
int PCB::getFileLength() const
{
return fileLen;
}
void PCB::setRW( string r )
{
rw = r;
}
string PCB::getRW() const
{
return rw;
}
void PCB::setTime( float t )
{
time = t;
}
float PCB::getTime() const
{
return time;
}
void PCB::setTime2( float t )
{
time2 = t;
}
float PCB::getTime2() const
{
return time2;
}
int & computer::findMin( vector<int> & v )
{
int minIndex = 0;
for( int i = 1; i < v.size( ); i++ )
if( v[ minIndex ] > v[ i ] )
minIndex = i;
return v[ minIndex ];
}
int computer::findPos( vector<int> & v )
{
int minIndex = 0;
for( int i = 1; i < v.size( ); i++ )
if( v[minIndex] > v[ i ] )
minIndex = i;
return minIndex;
}
void computer::removeElem()
{
time.erase( time.begin() + ( findPos( time ) ) );
}
void PCB::setTau( float t )
{
tau = t;
}
float PCB::getTau() const
{
return tau;
}
void PCB::setAlpha( float a )
{
alpha = a;
}
float PCB::getAlpha() const
{
return alpha;
}
void PCB::setCylin( int cc )
{
cylinder = cc;
}
int PCB::getCylin() const
{
return cylinder;
}
void computer::calculate() // Used to calculate tau value in ready queue
{
float t;
PCB j;
t = ( readyQueue[counter].getTau() - j.getTime() );
//cout << t << endl;
readyQueue[counter].setTau( t );
g_tau2 = t;
// Now test it:
//cout << "readyQueue[0].getTau(): " << readyQueue[counter].getTau() << endl;
//cout << "readyQueue[1].getTau(): " << readyQueue[counter+1].getTau() << endl;
//cout << "Counter value is: " << counter << endl;
}
float PCB::addTime()
{
time3 += getTime() + getTime2();
return time3;
}
float PCB::calculateTau()
{
float f;
computer c;
f = ( ( getAlpha() * g_tau ) + ( getAlpha() * addTime() ) );
return f;
}
bool PCB::operator<( const PCB& other ) const
{
return other.getTau() < this->getTau();
}
bool PCB::operator>( const PCB& other ) const
{
return other.getTau() < this->getTau();
}
bool operator=( const PCB& other )
{
return other.getTau() = this->getTau();
}
PCB PCB::findMin( vector<PCB> & v )
{
float minIndex = 0.0;
for(int i = 1; i < v.size(); i++ )
{
if( v[ minIndex ] > v[ i ] )
minIndex = i;
return v[ minIndex ];
}
}
PCB PCB::insertionSort( vector<PCB> & v, int length )
{
float j, temp;
for(int i = i; i < v.size(); i++ )
{
j = i;
while( j < 0 && v[j] > v[j-1] )
{
temp = v[j];
v[j] = v[j-1];
v[j-1] = temp;
j--;
}
}
}
/*void PCB::setCpuTime( float c )
{
cpuTime = c;
}
float PCB::getCpuTime() const
{
return cpuTime;
}*/
void computer::pScreenLoop()
{
cout << endl;
for( int i = 0; i < printer; i++ )
{
cout << "Printer Queue " << i+1 << ":" << endl;
if(!printerQueues[i].empty()){
for (int j=0; j<printerQueues[i].size(); j++)
{
cout << setw(0) << printerQueues[i][j].getPid() << setw(8) << " "
<< setw(14) << printerQueues[i][j].getFilename() << setw(14) << printerQueues[i][j].getMemoryStart()
<< setw(14) << printerQueues[i][j].getFileLength() << printerQueues[i][j].getTau() << endl;
cout << endl;
}
}
else
{
cout<<"is empty"<<endl;
}
}
cout << endl;
}
void computer::dScreenLoop()
{
for( int i = 0; i < disk; i++ )
{
cout << "Disk Queue " << i+1 << ":" << endl;
if(!diskQueues[i].empty())
{
for (int j=0; j<diskQueues[i].size(); j++)
{
cout << setw(0) << diskQueues[i][j].getPid() << setw(6) << " "
<< setw(14) << diskQueues[i][j].getFilename() << setw(14) << diskQueues[i][j].getMemoryStart()
<< setw(14) << diskQueues[i][j].getFileLength() << setw(14) << " - " << diskQueues[i][j].getTau() << endl;
cout << endl;
}
}
else
{
cout<<"is empty"<<endl;
}
}
}
void computer::cScreenLoop()
{
for( int i = 0; i < cd; i++ )
{
cout << "CD/RW Queue " << i+1 << ":" << endl;
if(!cdQueues[i].empty())
{
for (int j=0; j< cdQueues[i].size(); j++)
{
cout << setw(0) << cdQueues[i][j].getPid() << setw(6) << " "
<< setw(14) << cdQueues[i][j].getFilename() << setw(14) << cdQueues[i][j].getMemoryStart()
<< setw(14) << cdQueues[i][j].getFileLength() << setw(14) << " - " << cdQueues[i][j].getTau() << endl;
cout << endl;
}
}
else {
cout<<"is empty"<<endl;
}
}
}
float PCB::alpha = 0;
float PCB::time = 0;
float PCB::time2 = 0;
float PCB::time3 = 0;
/**
* main() begins here--
*/
int main()
{
computer c;
c.prompt();
c.runningPrompt();
return 0;
}
[Error] 'bool operator=(const PCB&)' must be a nonstatic member function
In member function 'PCB PCB::insertionSort(std::vector<PCB>&, int)':
[Error] cannot convert 'PCB' to 'float' in assignment
[Error] no match for 'operator=' (operand types are 'PCB' and 'float')
candidate is:
[Note] bool PCB::operator=(const PCB&)
[Note] no known conversion for argument 1 from 'float' to 'const PCB&'