This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Record.h
140 lines (118 loc) · 2.69 KB
/
Record.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include <iostream>
#include <string>
#include <string.h>
#include <fstream>
using std::cout;
using std::endl;
using std::ostream;
using std::istream;
class Record {
protected:
string* records = nullptr;
int noRecords = 0;
public:
Record() {
}
Record(string* newValues, int newNoValues) {
this->noRecords = newNoValues;
this->records = new string[newNoValues];
for (int i = 0; i < newNoValues; i++) {
this->records[i] = newValues[i];
}
}
Record(const Record& record) {
this->noRecords = record.noRecords;
this->records = new string[record.noRecords];
for (int i = 0; i < record.noRecords; i++) {
this->records[i] = record.records[i];
}
}
~Record() {
if (this->records != nullptr) {
delete[] this->records;
}
}
Record& operator=(const Record& record) {
this->noRecords = record.noRecords;
if (this->records != nullptr) {
delete[] this->records;
}
this->records = new string[record.noRecords];
for (int i = 0; i < record.noRecords; i++) {
this->records[i] = record.records[i];
}
return *this;
}
string* getValues() {
return this->records;
}
void setValues(string* newValues, int newNoValues) {
if (this->records != nullptr) {
delete[] this->records;
}
this->noRecords = newNoValues;
this->records = new string[newNoValues];
for (int i = 0; i < newNoValues; i++) {
this->records[i] = newValues[i];
}
}
int getNoValues() {
return this->noRecords;
}
void setNoValues(int value) {
if (value >= 0) {
this->noRecords = value;
}
}
bool operator!=(Record record) {
if (this->noRecords == record.noRecords) {
bool found = false;
for (int i = 0; i < this->noRecords; i++)
{
if (this->records[i] != record.records[i])
{
found = true;
}
}
if (found == true)
return true;
else
return false;
}
else
return true;
}
string& operator[](int i)
{
if (i < 0 || i > this->noRecords)
{
throw SQLException("Index out of bounds");
}
else
{
return this->records[i];
}
}
friend ostream& operator<<(ostream& console, Record& record);
friend istream& operator>>(istream& input, Record& record);
};
ostream& operator<<(ostream& console, Record& record) {
console << "Number of Field Records: " << record.noRecords << endl;
console << "Field Values: ";
for (int i = 0; i < record.noRecords; i++) {
console << endl << "The field number: " << i << " is " << record.records[i];
}
cout << endl;
cout << endl;
return console;
}
istream& operator>>(istream& input, Record& record)
{
cout << "Number Of Values: " << endl;
input >> record.noRecords;
cout << "Values: " << endl;
for (int i = 0; i < record.noRecords; i++)
input >> record.records[i];
return input;
}