-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.cpp
122 lines (104 loc) · 3.17 KB
/
temp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <fstream>
#include <string>
class ExecutionRepDetails
{
public:
std::string orderID;
std::string clientOrderID;
std::string instrument;
int side;
std::string executionStatus;
int quantity;
double price;
ExecutionRepDetails *previous;
ExecutionRepDetails *next;
ExecutionRepDetails(std::string oID, std::string cID, std::string inst, int s, std::string status, int qty, double pr)
{
orderID = oID;
clientOrderID = cID;
instrument = inst;
side = s;
executionStatus = status;
quantity = qty;
price = pr;
previous = nullptr;
next = nullptr;
}
};
// Function to add ExecutionRepDetails to the linked list
void addToLinkedList(ExecutionRepDetails *&head, std::string oID, std::string cID, std::string inst, int s, std::string status, int qty, double pr)
{
ExecutionRepDetails *newNode = new ExecutionRepDetails(oID, cID, inst, s, status, qty, pr);
if (head == nullptr)
{
head = newNode;
}
else
{
ExecutionRepDetails *temp = head;
while (temp->next != nullptr)
{
temp = temp->next;
}
temp->next = newNode;
newNode->previous = temp;
}
}
// Function to create a linked list of ExecutionRepDetails
ExecutionRepDetails *createLinkedList()
{
ExecutionRepDetails *head = nullptr;
addToLinkedList(head, "123", "456", "Instrument A", 1, "Executed", 10, 99.99);
addToLinkedList(head, "789", "012", "Instrument B", 0, "Pending", 5, 50.0);
addToLinkedList(head, "345", "678", "Instrument C", 1, "Rejected", 20, 199.99);
return head;
}
// Function to write data to a CSV file
void writeToCSV(const std::string &filename, const ExecutionRepDetails *head)
{
std::ofstream file(filename); // Open the file
if (!file.is_open()) // Check if the file was opened successfully
{
std::cout << "Failed to open the file: " << filename << std::endl;
return;
}
// Write the CSV header
file << "Order ID,Client Order ID,Instrument,Side,Execution Status,Quantity,Price\n";
const ExecutionRepDetails *temp = head;
while (temp != nullptr)
{
file << temp->orderID << ","
<< temp->clientOrderID << ","
<< temp->instrument << ","
<< temp->side << ","
<< temp->executionStatus << ","
<< temp->quantity << ","
<< temp->price << "\n";
temp = temp->next;
}
file.close(); // Close the file
std::cout << "Data has been written to the file: " << filename << std::endl;
}
// Function to free the memory of the linked list
void freeLinkedList(ExecutionRepDetails *&head)
{
ExecutionRepDetails *temp = head;
while (temp != nullptr)
{
ExecutionRepDetails *current = temp;
temp = temp->next;
delete current;
}
head = nullptr;
}
int main()
{
ExecutionRepDetails *head = createLinkedList();
// Write the linked list data to a CSV file
std::string filename = "execution_details.csv";
writeToCSV(filename, head);
// Free the memory of the linked list
freeLinkedList(head);
return 0;
}