I am still in the process of revising my program however the only issue I am receiving when trying to build is that 2 duplicate symbols for architecture x84_64. I have not had this issue in the past and I am running xcode 14.0.1 on Mac OSX monterey.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <sstream>
#include "Linked.hpp"
using namespace std;
time_t t = time(0);
tm* now = localtime(&t);
int main(){
LinkedList l;
Node* head = nullptr;
string line;
unsigned int sys_time = 0;
fstream myfile ("myfile.txt");
if (myfile.is_open()){
cout << "ready to proceed..." << endl;
}
ofstream outputFile ("output.txt");
if (outputFile.is_open()){
cout << "ready to proceed.." << endl;
}
outputFile << "Job_ID " << std::setfill('0') << std::setw(4) << "Priority_Value " << std::setfill('0') << std::setw(4) << "Arrival_Time" << std::setfill('0') << std::setw(4) << " Processing_Time" << endl;
while(!myfile.eof()){
std::replace(line.begin(), line.end(), ',', ' ');
stringstream ss(line);
getline(myfile, line);
string date;
int job_ID;
int priority_value;
int arrival_time;
int processing_time;
ss >> job_ID;
ss >> priority_value;
ss >> arrival_time;
ss >> processing_time;
l.enqueue(&head,job_ID, priority_value,arrival_time,processing_time);
}
return 0;
}
`
#ifndef Linked_hpp
#define Linked_hpp
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <sstream>
using namespace std;
class Node {
public:
Node *next;
int jobID;
int priority_num;
int arrival_time;
int priority_value;
int wait_time;
Node(int jd, int pv, int at, int wt);
};
class LinkedList{
public:
Node *head;
static Node* firstNode(int jd, int pv, int at, int wt);
static int peek(Node** head);
static void enqueue(Node **head,int jd, int pv, int at, int wt);
static void dequeue(Node **head);
static int getLength(Node* head);
static bool isEmpty(Node* head);
static void display(Node* head);
LinkedList();
};
#endif /* LinkedList_hpp */
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <sstream>
#include "Linked.hpp"
time_t t = time(0);
tm* now = localtime(&t);
using namespace std;
Node::Node(int jd, int pv, int at, int wt){
jobID = jd;
priority_value = pv;
arrival_time = at;
wait_time = wt;
next = nullptr;
}
Node* LinkedList::firstNode(int jd, int pv, int at, int wt){
Node *newNode = new Node(jd, pv, at, wt);
newNode->jobID = jd;
newNode->priority_value = pv;
newNode->arrival_time = at;
newNode->wait_time = wt;
return newNode;
}
LinkedList::LinkedList(){
head = NULL;
}
int LinkedList::peek(Node** head){
return (*head)->jobID;
}
void LinkedList::dequeue(Node** head){
Node* newNode = *head;
(*head) = (*head)->next;
free(newNode);
}
void LinkedList::enqueue(Node **head,int jd, int pv, int at, int wt){
Node* startNode = (*head);
Node* tempNode = firstNode(jd, pv, at, wt);
//This if statement will assign the head node the first item that is inserted into the linked list in order to begin the queue
if(head == NULL){
Node* newNode = firstNode(jd, pv, at, wt);
}
// If the head node's priority is greater than the next node then they are swapped.
else if((*head)->priority_value > pv){
tempNode->next = *head;
(*head) = tempNode;
}
else{
// If the head node is not null and its priority is less than the current node's priority that was just passed through the function then the head node stays as the highest priority while the the node that was just passed into this function gets compared to other nodes in the list.
while (startNode->next != NULL && startNode->next->priority_value < pv){
startNode = startNode->next;
}
// Either at the ends of the list
// or at required position
tempNode->next = startNode->next;
startNode->next = tempNode;
}
}
// This checks to see how many nodes are in the list and then returns that value
int LinkedList::getLength(Node* head){
Node *list = head;
int count = 0;
// the count variable is used to count the number of nodes while the while loop goes through each node in the list until it reaches the nullptr
while(list){
list = list->next;
count = 1;
}
return count;
}
//This boolean function checks to see if the queue is empty and returns either true or false back to main
bool LinkedList::isEmpty(Node* head){
return head == nullptr;
}
//This function displays the job's id, date, and its level of priority in the queue
void LinkedList::display(Node* head){
ofstream outputFile ("output.txt");
Node* list = head;
outputFile << "Job ID " << setw(10) << "Arrival Time " << setw(10) << "Priority ID " << endl;
while(list){
if (head == nullptr){
isEmpty(list);
}
else{
outputFile << list->jobID << " " << setw(10) << (now->tm_year 1900) << "-" << (now->tm_mon 1) << "-" << now->tm_mday << setw(5) << list->priority_value << endl;
list = list->next;
}
}
}
I have tried going to the build settings to see if there was anything that wasn't set properly but all the settings are defaulted to C .
CodePudding user response:
OK figured it out (would have been faster with the error message).
Here's the first cpp file
time_t t = time(0);
tm* now = localtime(&t);
and here's the second cpp file
time_t t = time(0);
tm* now = localtime(&t);
Both t
and now
are defined globally in both cpp files. So you get a duplicate symbol error.
Since you only seem to be using those variables in the second cpp file, just deleting them from the first should solve your problem.