#pragma once
#include <iostream>
struct task {
int id;
int dur;
int s_time;
int e_time;
int *dep;
// Adding three extra variables
int ls;
int lf;
int *f_deps;
};
class Schedular {
task * arr; // array for tasks
int *n_d; // dependencies list
int *n_f;
int n; // Total tasks
public:
Schedular();
Schedular(task *ts, int n);
void setTaskDuration();
void set_nth_TaskDuration(int i, int t);
void printTaskDependencyList(int i);
void completionTime();
};
#include "Schedular.h"
usingnamespace std;
Schedular::Schedular()
{
arr = NULL;
}
Schedular::Schedular(task * ts, int n)
{
system("cls");
ts = new task[n];
n_f = newint[n];
n_d = newint[n]; // Stores dependencies of all tasks
this->n = n;
int temp;
//Taking Input
// First Task has no Predecessor
cout << "Enter Duration for Task 1: ";
cin >> ts[0].dur;
ts[0].dep = NULL;
for (int i = 1; i < n; i++)
{
cout << "Enter Duration for Task " << i + 1 << ": ";
cin >> ts[i].dur;
cout << "Enter number of Predecessors for Task " << i + 1 << ": ";
cin >> temp;
ts[i].dep = NULL; // giving default value of NULL.
ts[i].dep = newint[temp];
for (int z = 0; z < temp; z++)
{
cout << "Enter Predecessor #" << z + 1 << ": ";
cin >> ts[i].dep[z];
}
}
// Storing the tasks which one task can call
for (int task = 0; task < n; task++)
{
int count = 0, k = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n_d[i]; j++)
{
if (arr[i].dep[j] == task)
count++;
}
}
arr[task].f_deps = newint[count];
n_f[task] = count;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n_d[i]; j++)
{
if (arr[i].dep[j] == task)
arr[task].f_deps[k++] = task;
}
}
}
}
void Schedular::setTaskDuration()
{
for (int i = 0; i < n; i++)
{
int t;
cout << "Enter the time duration for task " << i << " :";
cin >> t;
arr[i].dur = t;
}
}
void Schedular::set_nth_TaskDuration(int i, int t)
{
arr[i].dur = t;
}
void Schedular::printTaskDependencyList(int i)
{
for (int i = 0; i < n; i++)
{
cout << "For Task " << i + 1 << ": ";
for (int j = 0; j < n_d[i]; j++)
{
cout << arr[i].dep[j] << " ";
}
cout << endl;
}
for (int i = 0; i < n; i++)
{
cout << "For Task " << i + 1 << ": ";
for (int j = 0; j < n_f[i]; j++)
{
cout << arr[i].f_deps[j] << " ";
}
cout << endl;
}
}
void Schedular::completionTime()
{
}
Main
1 2 3 4 5 6 7 8 9 10 11
#include "Schedular.h"
usingnamespace std;
int main()
{
task *ptr = NULL;
int n = 8;
Schedular obj(ptr, n);
cout << endl;
system("pause");
return 0;
}
I am getting this error when I try to run this program,
1 2
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall Schedular::~Schedular(void)" (??1Schedular@@QAE@XZ) referenced in function _main
1>E:\Visual Studio\Projects\Project12\Debug\Project12.exe : fatal error LNK1120: 1 unresolved externals
Now, from what I have learned, you get this error if you haven't defined Default Constructor but I have done that clearly... Can anyone help me resolve this issue? Thank you
It doesn't really make sense for the exact code you've posted, but normally that error (complaining about a missing destructor) would be caused by having declared the dtor in the class but never actually defining it. You probably need a dtor for your class since you have dynamically allocated memory to clean up.
If you're programming for C++11 or better you should never use the macro NULL; use the keyword nullptr instead.
BTW, I don't know if it's on purpose or not, but "scheduler" doesn't usually have an 'a' in it.