Guest User

Untitled

a guest
Sep 1st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. Personal Information program. Does not accept address as a string [closed]
  2. #ifndef INFO_H
  3. #define INFO_H
  4.  
  5. #include <string>
  6.  
  7. class info
  8. {
  9. private:
  10. std::string name;
  11. std::string address;
  12. int age;
  13. std::string phone;
  14.  
  15. public:
  16. void setName(std::string);
  17. void setAge(int);
  18. void setAddress(std::string);
  19. void setPhone(std::string);
  20.  
  21. std::string getName();
  22. int getAge();
  23. std::string getAddress();
  24. std::string getPhone();
  25. };
  26. #endif
  27.  
  28. #include "info.h"
  29. #include <iostream>
  30. #include <cstdlib>
  31. #include <string>
  32.  
  33. using namespace std;
  34.  
  35. void info::setName(string n)
  36. {
  37. name = n;
  38. }
  39. void info::setAge(int ag)
  40. {
  41. age = ag;
  42. }
  43. void info::setAddress(string adr)
  44. {
  45.  
  46. address = adr;
  47.  
  48. }
  49. void info::setPhone(string phn)
  50. {
  51. phone = phn;
  52. }
  53.  
  54. string info::getName()
  55. {
  56. return name;
  57. }
  58. string info::getAddress()
  59. {
  60. return address;
  61. }
  62. int info::getAge()
  63. {
  64. return age;
  65. }
  66. string info::getPhone()
  67. {
  68. return phone;
  69. }
  70.  
  71. #include <iostream>
  72. #include "info.h"
  73. #include<string>
  74.  
  75. using namespace std;
  76.  
  77. int main()
  78. {
  79. info MyInfo;
  80.  
  81. string person_name;
  82. int person_age;
  83. string person_address;
  84. string person_phone;
  85.  
  86. cout << "Enter name: ";
  87. cin >> person_name;
  88. MyInfo.setName(person_name);
  89. cout << "Enter your age: ";
  90. cin >> person_age;
  91. MyInfo.setAge(person_age);
  92. cout << "Enter address: ";
  93. cin >> person_address;
  94. MyInfo.setAddress(person_address);
  95. cout << "Enter a phone number: ";
  96. cin >> person_phone;
  97. MyInfo.setPhone(person_phone);
  98.  
  99. cout << MyInfo.getName() << " " << MyInfo.getAge() << " " << MyInfo.getAddress() << " " << MyInfo.getPhone() << endl;
  100. return 0;
  101. }
Add Comment
Please, Sign In to add comment