Advertisement
Guest User

Untitled

a guest
Oct 28th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // 4-1
  4. //
  5. // Created by ss on 28/10/15.
  6. // Copyright © 2015 ss. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. class Post {
  13. int id;
  14. string title;
  15. string content;
  16. };
  17. class Feedback {
  18. int id;
  19. string title;
  20. string content;
  21. };
  22.  
  23. class User {
  24. public:
  25. // const
  26. User(int id = 0, string username="", string password="", string email="") {
  27. ++count;
  28. this->id = id;
  29. this->username = username;
  30. this->password = password;
  31. this->email = email;
  32. }
  33. // dest
  34. ~User() {
  35. --count;
  36. cout << getCount() << endl;
  37. }
  38. // set
  39. void setId(int id) { this->id = id; }
  40. void setUsername(string username) { this->username = username; }
  41. void setPassword(string password) { this->password = password; }
  42. void setEmail(string email) { this->email = email; }
  43. // get
  44. static size_t getCount(){return count;}
  45.  
  46. void showInfo() {
  47. cout << "Id: " << id << endl;
  48. cout << "Username: " << username << endl;
  49. cout << "Password: " << password << endl;
  50. cout << "Email: " << email << endl;
  51. }
  52. private:
  53. int id;
  54. string username;
  55. string password;
  56. string email;
  57. Post* posts;
  58. Feedback* feedbacks;
  59. static size_t count;
  60. };
  61. size_t User::count = 0;
  62.  
  63. void fill(User* users, int n) {
  64. for (int i = 0; i < n; ++i) {
  65. cout << "Enter Id" << endl; int id; cin >> id; users[i].setId(id);
  66. cout << "Enter Username" << endl; string username; cin >> username; users[i].setUsername(username);
  67. cout << "Enter Password" << endl; string password; cin >> password; users[i].setPassword(password);
  68. cout << "Enter Email" << endl; string email; cin >> email; users[i].setEmail(email);
  69. }
  70. }
  71.  
  72. int main(int argc, const char * argv[]) {
  73. User * user1 = new User(0, "testUser1", "test1Pass", "test1@gmail.com");
  74. User * user2 = new User(1, "testUser2", "test2Pass", "test2@gmail.com");
  75.  
  76. // create and fill a table
  77. cout << "Enter size of an array" << endl; int n; cin >> n;
  78. User * users = new User[n]; fill(users, n);
  79.  
  80. // printing objects values
  81. for (int i = 0; i < n; ++i) { users[i].showInfo(); }
  82.  
  83. // delete objects
  84. delete[] users;
  85. delete user1;
  86. delete user2;
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement