Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Header File:
- #ifndef USERS_H
- #define USERS_H
- #include <iostream>
- #include <string>
- using namespace std;
- class Users{
- public:
- //Default Constructor:
- Users();
- //Overloaded Constructor:
- Users(string, string, int);
- //Deconstructor:
- ~Users();
- //Accessor Functions:
- string getUsername() const;
- string getPassword() const;
- int getID() const;
- private:
- //Member Variables:
- string newUsername;
- string newPassword;
- int newID;
- };
- #endif
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //Function Declarations:
- #include "Users.h"
- //Default Constructor:
- Users::Users(){
- newID = 0;
- }
- //Overloaded Constructor:
- Users::Users(string name, string pass, int id){
- newUsername = name;
- newPassword = pass;
- newID = id;
- }
- //Deconstructor:
- Users::~Users(){
- }
- //Accessor Functions:
- string Users::getUsername() const{
- return newUsername;
- }
- string Users::getPassword() const{
- return newPassword;
- }
- int Users::getID() const{
- return newID;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <string>
- #include <vector>
- #include "Users.h"
- using namespace std;
- void createVec(vector<Users>&);
- void showVec(const vector<Users>&);
- int main(){
- vector<Users> uVec;
- createVec(uVec);
- showVec(uVec);
- system("pause");
- return 0;
- }
- //Create Vector Function:
- void createVec(vector<Users>& newVec){
- //Variables
- int uSize;
- string username;
- string password;
- int id;
- cout << "Enter number of users: ";
- cin >> uSize;
- for(int i = 0; i < uSize; i++){
- cout << "Enter username: ";
- cin >> username;
- cout << "Enter password: ";
- cin >> password;
- cout << "Enter ID: ";
- cin >> id;
- Users newUser(username, password, id);
- newVec.push_back(newUser);
- }
- }
- void showVec(const vector<Users>& newVec){
- unsigned int vecSize = newVec.size();
- for(unsigned int i = 0; i < vecSize; i++){
- cout << "Username: " << newVec[i].getUsername() << endl;
- cout << "Password: " << newVec[i].getPassword() << endl;
- cout << "ID: " << newVec[i].getID() << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement