Guest User

Untitled

a guest
Feb 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. class Entry
  6. {
  7. private:
  8. int age;
  9. int zip;
  10.  
  11. std::string name;
  12. std::string address;
  13. std::string city;
  14. std::string state;
  15. public:
  16. int ID;
  17.  
  18. Entry();
  19. Entry(int _age, int _zip, std::string _name, std::string _address, std::string _city, std::string _state);
  20.  
  21. void setAge(int _age) {age = _age;};
  22. void setZip(int _zip) {zip = _zip;};
  23. void setName(std::string _name) {name = _name;};
  24. void setAddress(std::string _address){address = _address;};
  25. void setCity(std::string _city) {city = _city;};
  26. void setState(std::string _state) {state = _state;};
  27.  
  28. int getAge() {return age;}
  29. int getZip() {return zip;}
  30. std::string getName() {return name;};
  31. std::string getAddress() {return address;};
  32. std::string getCity() {return city;};
  33. std::string getState() {return state;};
  34. };
  35.  
  36. Entry::Entry()
  37. {
  38. }
  39.  
  40. Entry::Entry(int _age, int _zip, std::string _name, std::string _address, std::string _city, std::string _state)
  41. {
  42. age = _age;
  43. zip = _zip;
  44. name = _name;
  45. address = _address;
  46. city = _city;
  47. state = _state;
  48. }
  49.  
  50. class Database
  51. {
  52. private:
  53. int uID;
  54. std::vector<Entry> tableEntries;
  55. public:
  56. Database();
  57.  
  58. void addEntry(Entry e);
  59. Entry viewEntry(int i);
  60. };
  61.  
  62. Database::Database()
  63. {
  64. uID = 0;
  65. }
  66.  
  67. void Database::addEntry(Entry e)
  68. {
  69. e.ID = uID;
  70. tableEntries.push_back(e);
  71.  
  72. uID++;
  73. }
  74.  
  75. Entry Database::viewEntry(int i)
  76. {
  77. return tableEntries.at(i);
  78. }
  79.  
  80. int main()
  81. {
  82. Database db;
  83.  
  84. Entry test;
  85. test.setAge(12);
  86. test.setZip(1337);
  87. test.setName("Mark");
  88. test.setAddress("a");
  89. test.setCity("b");
  90. test.setState("c");
  91.  
  92. db.addEntry(test);
  93. db.addEntry(Entry(12, 1337, "using constructor", "a", "b", "c"));
  94.  
  95. Entry vEntry = db.viewEntry(0);
  96. std::cout << vEntry.getName() << std::endl;
  97. system("pause");
  98. }
Add Comment
Please, Sign In to add comment