19_5.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //19_5
  2. #include <iostream.h>
  3. #include <fstream.h>
  4. #include <iomanip.h>
  5. #include <string.h>
  6. class AddressBook{
  7. public:
  8.   AddressBook(char* n, char* p, char* h);
  9.   virtual void Display(ostream& out);
  10. protected:
  11.   char name[20];
  12.   char phone[10];
  13.   char handp[15];
  14. };
  15. AddressBook::AddressBook(char* n, char* p, char* h)
  16. {
  17.   strncpy(name, n, 19);  name[19]=0;
  18.   strncpy(phone, p, 9);  phone[9]=0;
  19.   strncpy(handp, h, 14); handp[14]=0;
  20. }
  21. void AddressBook::Display(ostream& out)
  22. {
  23.   out <<setiosflags(ios::left) <<setw(20) <<name
  24.   <<setw(10) <<phone <<setw(15) <<handp <<endl;
  25. }
  26. ostream& operator<<(ostream& out, AddressBook& a)
  27. {
  28.   a.Display(out);
  29.   return out;
  30. }
  31. void main()
  32. {
  33.   AddressBook a1("Dill Arnson", "8869533", "13902201080");
  34.   AddressBook a2("Welch Shammas", "6695482", "13023399001");
  35.   AddressBook a3("Portel Braumbel", "5937221","13908032991");
  36.   cout <<a1;
  37.   cout <<a2;
  38.   cout <<a3;
  39. }