Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // 4-1
- //
- // Created by ss on 28/10/15.
- // Copyright © 2015 ss. All rights reserved.
- //
- #include <iostream>
- using namespace std;
- class Post {
- int id;
- string title;
- string content;
- };
- class Feedback {
- int id;
- string title;
- string content;
- };
- class User {
- public:
- // const
- User(int id = 0, string username="", string password="", string email="") {
- ++count;
- this->id = id;
- this->username = username;
- this->password = password;
- this->email = email;
- }
- // dest
- ~User() {
- --count;
- cout << getCount() << endl;
- }
- // set
- void setId(int id) { this->id = id; }
- void setUsername(string username) { this->username = username; }
- void setPassword(string password) { this->password = password; }
- void setEmail(string email) { this->email = email; }
- // get
- static size_t getCount(){return count;}
- void showInfo() {
- cout << "Id: " << id << endl;
- cout << "Username: " << username << endl;
- cout << "Password: " << password << endl;
- cout << "Email: " << email << endl;
- }
- private:
- int id;
- string username;
- string password;
- string email;
- Post* posts;
- Feedback* feedbacks;
- static size_t count;
- };
- size_t User::count = 0;
- void fill(User* users, int n) {
- for (int i = 0; i < n; ++i) {
- cout << "Enter Id" << endl; int id; cin >> id; users[i].setId(id);
- cout << "Enter Username" << endl; string username; cin >> username; users[i].setUsername(username);
- cout << "Enter Password" << endl; string password; cin >> password; users[i].setPassword(password);
- cout << "Enter Email" << endl; string email; cin >> email; users[i].setEmail(email);
- }
- }
- int main(int argc, const char * argv[]) {
- User * user1 = new User(0, "testUser1", "test1Pass", "test1@gmail.com");
- User * user2 = new User(1, "testUser2", "test2Pass", "test2@gmail.com");
- // create and fill a table
- cout << "Enter size of an array" << endl; int n; cin >> n;
- User * users = new User[n]; fill(users, n);
- // printing objects values
- for (int i = 0; i < n; ++i) { users[i].showInfo(); }
- // delete objects
- delete[] users;
- delete user1;
- delete user2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement