-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
105 lines (86 loc) · 2.71 KB
/
main.c
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
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "template.h"
int main() {
int choice;
TransNode *mainhead=NULL, *maintail=NULL, *temp;
SellersList *sellerhead=NULL, *sellertail=NULL;
seller_buyer *sellerlisthead=NULL;
seller_buyer *buyerlisthead=NULL;
Pair *pairhead=NULL;
retstat status_code;
loadSellersFromFile(&sellerhead,&sellertail);
readTransactions(&mainhead,&maintail);
do {
printf("\n=======================================\n");
printf("Energy Trading System Menu:\n");
printf("=======================================\n");
printf("1. Add New Transaction\n");
printf("2. Display All Transactions\n");
printf("3. List Transactions by Seller\n");
printf("4. List Transactions by Buyer\n");
printf("5. List Transactions in a Given Time Period\n");
printf("6. Calculate Total Revenue by Seller\n");
printf("7. Find Transaction with Highest Energy Amount\n");
printf("8. Sort Buyers by Energy Bought\n");
printf("9. Sort Seller/Buyer Pairs by Number of Transactions\n");
printf("10. Update Transaction\n");
printf("11. Create a list of regular buyers for every seller\n");
printf("0. Exit\n");
printf("=======================================\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
status_code=addEntry(&mainhead,&maintail,sellerhead);
if(status_code==failure) printf("Failed to add the entry!!\n");
else printf("Successfully added the entry!!\n");
break;
case 2:
displayData(mainhead);
break;
case 3:
createSellersList(&sellerlisthead,mainhead);
break;
case 4:
createBuyersList(&buyerlisthead,mainhead);
break;
case 5:
listTransinTime(mainhead);
break;
case 6:
revenueGenerated(sellerlisthead);
break;
case 7:
mainhead=max_ener(mainhead);
temp=mainhead;
while(temp->next!=NULL) temp=temp->next;
maintail=temp;
break;
case 8:
buyerlisthead=calculateEnergy(buyerlisthead);
break;
case 9:
pairhead=sort_pairs(mainhead,pairhead);
break;
case 10:
update(mainhead,sellerhead);
break;
case 11:
createListRegular(sellerhead,pairhead);
break;
case 0:
printf("Exiting program...\n");
break;
default: printf("Invalid choice! Please enter a valid option.\n");
}
} while (choice != 0);
saveTransactions(mainhead);
saveRegularBuyers(sellerhead);
clearPairs(&pairhead);
cleanTransList(&mainhead);
clearSellersList(&sellerlisthead);
clearSellersList(&buyerlisthead);
cleanSellersList(&sellerhead);
}