Facebook
From Jittery Crocodile, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 210
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5. //class Person definition
  6. class Person{
  7. string lastname;
  8. string name;;
  9. int age;
  10.  
  11. public:
  12. Person *next_Person;
  13. //function to save personal data
  14. void save_Person_data(string add_lastname, string add_name, int add_age);
  15. //function to display personal data
  16. string display_lastname();
  17. string display_name();
  18. int    display_age();
  19.  
  20. };
  21.  
  22. class List{
  23.     Person *first_Person;
  24. public:
  25.     Person find_Person(string lastanme); //it means that function gives Person - remember it's new type!!
  26.     void add_Person (Person *ptr_Person);//function take pointer at that Person
  27.  
  28. };
  29.  
  30.  
  31. int main(){
  32.     //temporary variables using to adding new Person (new object) to class
  33.     string temp_lastname;
  34.         string temp_name;
  35.     int temp_age;
  36.     //temporary pointing
  37.     Person*temp_ptr;
  38.     cout << "Input last name: ";
  39.     cin >> temp_lastname;
  40.     cout << "Input name: ";
  41.     cin >> temp_name;
  42.     cout << "Input age: ";
  43.     cin >> temp_age;
  44.     temp_ptr = new Person; //tymczasowy wskaznik na nowa osobÄ™
  45.  
  46.     //save person data to temp_ptr - Person object
  47.     (*temp_ptr).save_Person_data(temp_lastname, temp_name, temp_age); //here's specific data
  48.     delete temp_ptr;
  49.  
  50.  
  51. return 0;}
  52. //save_Person_data definition
  53. void Person:: save_Person_data(string add_lastname, string add_name, int add_age){
  54.  
  55. lastname = add_lastname;
  56. name = add_name;
  57. age = add_age;
  58.  
  59. }
  60.  
  61. //function for
  62. string Person:: display_lastname(){ return lastname ;}
  63. string Person:: display_name(){ return name;}
  64. int    Person:: display_age(){ return age;}
  65.  
  66. //function to find some Person
  67.  
  68. Person List:: find_Person(string lastname){
  69. Person *temp_ptr; //temporary pointer (type Person) that
  70. string temp_lastname; //temporary last name to compare with others
  71. temp_ptr = first_Person; //set up temporary pointer at first Person
  72. }
  73.