-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.cpp
87 lines (67 loc) · 2.04 KB
/
db.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
#include <iostream>
#include <string>
#include <fstream>
class Heker {
public:
std::string nick;
std::string marga;
std::string tim;
Heker (std::string nick, std::string marga, std::string tim){
Heker::nick = nick;
Heker::marga = marga;
Heker::tim = tim;
}
std::string stringify (){
return "\n" + nick + " " + marga + " " + tim;
}
};
class DBase {
public:
std::ifstream in;
std::ofstream out;
std::string fileName;
DBase (const char* fileName){
DBase::fileName = fileName;
}
void save (Heker data){
std::cout << data.nick << std::endl;
std::cout << data.marga << std::endl;
std::cout << data.tim << std::endl;
DBase::out.open(DBase::fileName, std::ios::app);
DBase::out << data.stringify();
DBase::out.close();
}
void showAll (){
DBase::in.open(DBase::fileName, std::ios::in);
std::string nick, marga, tim;
int index = 1;
while (!DBase::in.eof())
{
DBase::in >> nick;
DBase::in >> marga;
DBase::in >> tim;
std::cout << index++ << ".\t";
std::cout << nick << "\t";
std::cout << marga << "\t";
std::cout << tim << std::endl;
}
DBase::in.close();
}
};
int main(int argc, char const *argv[])
{
DBase database = DBase ("data.txt");
database.showAll ();
std::string nick, marga, tim;
std::cout << "MASUKAN DATA HEKER" << std::endl;
std::cout << "Nick : ";
std::cin >> nick;
std::cout << "Marga : ";
std::cin >> marga;
std::cout << "Tim : ";
std::cin >> tim;
Heker dataHeker = Heker (nick, marga, tim);
database.save (dataHeker);
database.showAll ();
return 0;
}