Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Users.h Code
- #ifndef USERS_H
- #define USERS_H
- #include<iostream>
- #include<string>
- using namespace std;
- class Users{
- public:
- //Functions
- //Default Constructor:
- Users();
- //Overload Constructor:
- Users(string, string, int);
- //Deconstructor:
- ~Users();
- //Acessor Functions:
- string getUsername() const;
- string getPassword() const;
- int getUserID() const;
- private:
- //Member variables
- string newUsername;
- string newPassword;
- int userID;
- };
- #endif
- //Users.cpp code:
- #include "Users.h"
- //Default Constructor:
- Users::Users(){
- userID = 0;
- }
- //Overload Constructor:
- Users::Users(string name, string password, int ID ){
- newUsername = name;
- newPassword = password;
- userID = ID;
- }
- Users::~Users(){
- }
- //Acessor Functions:
- string Users::getUsername() const{
- return newUsername;
- }
- string Users::getPassword() const{
- return newPassword;
- }
- int Users::getUserID() const{
- return userID;
- }
- //Main.cpp code:
- #include<iostream>
- #include<string>
- #include<vector>
- #include "Users.h"
- using namespace std;
- void createVec(vector<Users>&); //Create vector function (Add users to vector)
- void showVec(const vector<Users>&); //Show vector function (Display users in vector)
- int main(){
- vector<Users> uVec;
- createVec(uVec);
- showVec(uVec);
- system("pause");
- return 0;
- }
- void createVec(vector<Users>& newVec){
- int lSize;
- string username;
- string password;
- int ID;
- cout << "Enter user list size: "; //Have user define number of loops
- cin >> lSize;
- for(int i = 0; i < lSize; i++){
- //Loop logic
- cout << "Username: ";
- cin >> username;
- cout << "Password: ";
- cin >> password;
- cout << "ID Number: ";
- cin >> ID;
- cout << "\nUser: " << username << " added\n";
- cout << endl;
- Users newUser(username, password, ID); //Create user with given information
- newVec.push_back(newUser); //Add it to vector
- }
- }
- void showVec(const vector<Users>& newVec){
- unsigned int vecSize = newVec.size(); //So C++ doesn't have to keep referencing Users.h (Saving time)
- cout << "-----------" << endl;
- cout << "User Data:" << endl;
- cout << endl;
- for(unsigned int i = 0; i < vecSize; i++){
- cout << "Username: " << newVec[i].getUsername() << endl;
- cout << "Password: " << newVec[i].getPassword() << endl;
- cout << "ID: " << newVec[i].getUserID() << endl;
- cout << endl;
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement