Advertisement
TermSpar

YouTube Classes

Apr 22nd, 2016
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. //Header File:
  2.  
  3. #ifndef USERS_H
  4. #define USERS_H
  5.  
  6. #include <iostream>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. class Users{
  12. public:
  13.     //Default Constructor:
  14.     Users();
  15.  
  16.     //Overloaded Constructor:
  17.     Users(string, string, int);
  18.  
  19.     //Deconstructor:
  20.     ~Users();
  21.  
  22.     //Accessor Functions:
  23.     string getUsername() const;
  24.  
  25.     string getPassword() const;
  26.  
  27.     int getID() const;
  28.  
  29. private:
  30.     //Member Variables:
  31.     string newUsername;
  32.     string newPassword;
  33.     int newID;
  34. };
  35.  
  36. #endif
  37. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38.  
  39. //Function Declarations:
  40. #include "Users.h"
  41.  
  42.  
  43. //Default Constructor:
  44. Users::Users(){
  45.     newID = 0;
  46. }
  47.  
  48. //Overloaded Constructor:
  49. Users::Users(string name, string pass, int id){
  50.     newUsername = name;
  51.     newPassword = pass;
  52.     newID = id;
  53. }
  54.  
  55. //Deconstructor:
  56. Users::~Users(){
  57.    
  58. }
  59.  
  60. //Accessor Functions:
  61. string Users::getUsername() const{
  62.     return newUsername;
  63. }
  64.  
  65. string Users::getPassword() const{
  66.     return newPassword;
  67. }
  68.  
  69. int Users::getID() const{
  70.     return newID;
  71. }
  72.  
  73. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74.  
  75. #include <iostream>
  76. #include <string>
  77. #include <vector>
  78. #include "Users.h"
  79.  
  80. using namespace std;
  81.  
  82. void createVec(vector<Users>&);
  83. void showVec(const vector<Users>&);
  84.  
  85. int main(){
  86.  
  87.     vector<Users> uVec;
  88.     createVec(uVec);
  89.     showVec(uVec);
  90.  
  91.     system("pause");
  92.     return 0;
  93. }
  94.  
  95. //Create Vector Function:
  96. void createVec(vector<Users>& newVec){
  97.    
  98.     //Variables
  99.     int uSize;
  100.     string username;
  101.     string password;
  102.     int id;
  103.  
  104.     cout << "Enter number of users: ";
  105.     cin >> uSize;
  106.  
  107.     for(int i = 0; i < uSize; i++){
  108.        
  109.         cout << "Enter username: ";
  110.         cin >> username;
  111.         cout << "Enter password: ";
  112.         cin >> password;
  113.         cout << "Enter ID: ";
  114.         cin >> id;
  115.  
  116.         Users newUser(username, password, id);
  117.         newVec.push_back(newUser);
  118.  
  119.     }
  120.  
  121.  
  122. }
  123.  
  124. void showVec(const vector<Users>& newVec){
  125.    
  126.     unsigned int vecSize = newVec.size();
  127.  
  128.     for(unsigned int i = 0; i < vecSize; i++){
  129.        
  130.         cout << "Username: " << newVec[i].getUsername() << endl;
  131.         cout << "Password: " << newVec[i].getPassword() << endl;
  132.         cout << "ID: " << newVec[i].getID() << endl;
  133.  
  134.     }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement