-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
116 lines (112 loc) · 2.6 KB
/
main.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
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include "B_Tree.h"
using namespace std;
class StorageEngine
{
private:
BTree *Tree;
public:
StorageEngine()
{
Tree = new BTree;
}
void insertRecord()
{
int id;
string name;
int age;
int marks;
cout << "ENTER THE ID: " << endl;
cin >> id;
cout << "ENTER THE NAME: " << endl;
cin >> name;
name = "charan";
cout << "ENTER THE AGE: " << endl;
cin >> age;
age = 21;
cout << "ENTER THE MARKS: " << endl;
cin >> marks;
marks = 99;
string recordName = "Records/";
recordName += to_string(id) + ".txt";
FILE *filePtr = fopen(recordName.c_str(), "w");
string data = name + " " + to_string(age) + " " + to_string(marks) + "\n";
fprintf(filePtr, data.c_str());
Key newKey(id, filePtr);
Tree->insert(newKey);
fclose(filePtr);
cout << filePtr << endl;
cout << "SUCCESSFULLY INSERTED" << endl;
cout << endl;
}
void searchRecord()
{
int id;
cout << "ENTER THE ID: " << endl;
cin >> id;
FILE *filePtr = Tree->search(id);
if (filePtr == nullptr)
{
cout << "No record found" << endl;
}
else
{
cout << "The indexing was pointing to the memory location: " << filePtr << endl;
}
}
void displayKeys()
{
cout << "Displaying the Tree" << endl;
Tree->display();
}
void deleteRecord()
{
int key;
cout << "Enter the key to delete: ";
cin >> key;
Tree->deletion(key);
cout << "SUCCESSFULLY DELETED" << endl;
}
};
int main()
{
system("cls");
cout << "WELCOME" << endl;
cout << endl;
int option;
StorageEngine se;
while (true)
{
cout << "SELECT ONE OF THE OPTIONS" << endl;
cout << "1.INSERT" << endl;
cout << "2.DELETE" << endl;
cout << "3.SEARCH" << endl;
cout << "4.DISPLAY" << endl;
cout << "5.EXIT" << endl;
cin >> option;
switch (option)
{
case 1:
se.insertRecord();
break;
case 2:
se.deleteRecord();
break;
case 3:
se.searchRecord();
break;
case 4:
se.displayKeys();
break;
case 5:
exit(0);
break;
default:
cout << "ENTER A VALID OPTION" << endl;
break;
}
}
}