fork download
  1. #include<iostream>
  2. #include<math.h>
  3. #include <string>
  4. using namespace std;
  5. class LIST
  6. {
  7. LIST *next;
  8. string name;
  9. string surname;
  10. string mname;
  11. public:
  12. LIST(string _surname,string _name, string _mname, LIST *oldlist);
  13. ~LIST();
  14. virtual void print();
  15. };
  16. LIST::LIST(string _surname,string _name, string _mname, LIST *oldlist)
  17. { name=_name;
  18. surname=_surname;
  19. mname=_mname;
  20. next=oldlist; }
  21. LIST::~LIST()
  22. {
  23. if (next)
  24. delete next;
  25. }
  26. void LIST::print()
  27. {
  28. cout<<surname<<'\t'<<name<<'\t'<<mname<<endl;
  29. cout<<surname<<" "<<name[0]<<". "<<mname[0]<<"."<<endl;
  30. if (next)
  31. next->print();
  32. }
  33. int main()
  34. {LIST *mylist;
  35. mylist=new LIST("Koval","Nazar","Jaros",mylist);
  36. mylist=new LIST("Mazyr","Dima","Anton",mylist);
  37. mylist->print();
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 2820KB
stdin
Standard input is empty
stdout
Mazyr	Dima	Anton
Mazyr D. A.
Koval	Nazar	Jaros
Koval N. J.