Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ofstream fout;
- class Person {
- private:
- char name[55];
- char number[55];
- char address[105];
- public:
- Person() {}
- Person(char *_name, char *_number, char *_address) {
- strcpy(name, _name);
- strcpy(number, _number);
- strcpy(address, _address);
- }
- Person(const Person &obj) {
- strcpy(name, obj.name);
- strcpy(number, obj.number);
- strcpy(address, obj.address);
- }
- ~Person() {}
- const char* get_name() {
- return name;
- }
- const char* get_number() {
- return number;
- }
- const char* get_address() {
- return address;
- }
- void set_name(char *s) {
- strcpy(name, s);
- }
- void set_number(char *s) {
- strcpy(number, s);
- }
- void set_address(char *s) {
- strcpy(address, s);
- }
- friend ostream& operator << (ostream &stream, Person &p);
- };
- ostream& operator << (ostream &stream, Person &p) {
- stream << p.name << " " << p.address << " " << p.number << endl;
- return stream;
- }
- class InheritedPerson : public Person {
- private:
- char *adr[105];
- public:
- InheritedPerson() {}
- InheritedPerson(char *_name, char *_number, char *_address) : Person(_name, _number, _address) {
- adr[0] = _address;
- }
- ~InheritedPerson() {
- }
- };
- void print_same_address(Person p[], int n, char *adr) {
- for(int i = 0; i < n; i++) {
- if(strcmp(adr, p[i].get_address()) == 0) {
- fout << p[i];
- }
- }
- }
- void print_same_number(Person p[], int n, char *num) {
- for(int i = 0; i < n; i++) {
- if(strcmp(num, p[i].get_number()) == 0) {
- fout << p[i];
- }
- }
- }
- int main(){
- fout.open("file.txt", ios::out);
- Person p1("john", "123", "houston");
- Person p2("jack", "234", "houston");
- Person p3("jerry", "123", "texas");
- Person p[] = {p1, p2, p3};
- print_same_number(p, 3, "123");
- print_same_address(p, 3, "houston");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement