-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBai67.cpp
71 lines (60 loc) · 1.29 KB
/
Bai67.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
/*
Ghi thông tin ra file text
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Person {
string name;
string address;
string email;
int age;
public:
Person();
Person(int, string, string, string);
void showInfo();
friend void writeToFile(Person, ofstream&);
};
void writeToFile(Person p, ofstream& ofs) {
ofs << p.name << endl;
ofs << p.address << endl;
ofs << p.email << endl;
ofs << p.age << endl;
}
Person::Person() {
age = 0;
name = "";
address = "";
email = "";
}
Person::Person(int age, string name, string address, string email) {
this->age = age;
this->name = name;
this->address = address;
this->email = email;
}
void Person::showInfo() {
cout << "I am " << name << ", I'm " << age << " years old."
<< "\nI live in " << address << ". My email address is '"
<< email << "'.\nNice to meet you!\n";
cout << endl;
}
void showInfo(Person* ps, size_t n) {
for (size_t i = 0; i < n; i++)
{
ps[i].showInfo();
}
}
int main() {
//fstream ofs("OUTPUT.txt", ios::app);
////ofs.open("OUTPUT.txt", ios::app);
//string message = "Have a nice day!";
//ofs << message << endl;
//ofs.close();
Person p(20, "Tran Thu Thuy", "Ha Noi", "[email protected]");
ofstream ofs2("E:\\OUTPUT.PDF", ios::app);
writeToFile(p, ofs2);
ofs2.close();
return 0;
}