fueanta

Popularity Checking through counting created accounts

Sep 6th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.00 KB | None | 0 0
  1. // cpp program: fb and google popularity checker
  2. // AIUB Summer15-16 MiD exam pl2 Code-Writing ques 3
  3. // Author: fueanta
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. // prototype declaration for classes:
  10. class Facebook;
  11. class GooglePlus;
  12.  
  13. // prototype declaration for global functions:
  14. void compare(Facebook,GooglePlus);
  15.  
  16. // Facebook class:
  17. class Facebook{
  18.     string name;
  19.     string password;
  20.     int user_no;
  21.     static int total;
  22. public:
  23.     Facebook();//constructor 1
  24.     Facebook(string,string);// constructor 2
  25.     void set_info(string,string);// setter method
  26.     string get_name();// getter method
  27.     int get_user_no();// getter
  28.     int get_total();// getter
  29. } ; int Facebook::total=0;
  30.  
  31. // definition for Facebook class constructors:
  32. Facebook::Facebook() {
  33.     /*total++;
  34.     user_no=total;*/
  35. }
  36. Facebook::Facebook(string name,string password) {
  37.     total++;
  38.     user_no=total;
  39.     this->name=name;
  40.     this->password=password;
  41. }
  42.  
  43. // definition for Facebook Class methods:
  44. void Facebook::set_info(string name,string password) {
  45.     total++;
  46.     user_no=total;
  47.     this->name=name;
  48.     this->password=password;
  49. }
  50. string Facebook::get_name() {
  51.     return name;
  52. }
  53. int Facebook::get_user_no() {
  54.     return user_no;
  55. }
  56. int Facebook::get_total() {
  57.     return total;
  58. }
  59.  
  60. // GooglePlus class:
  61. class GooglePlus{
  62.     string name;
  63.     string password;
  64.     int user_no;
  65.     static int total;
  66. public:
  67.     GooglePlus();//constructor 1
  68.     GooglePlus(string,string);// constructor 2
  69.     void set_info(string,string);// setter method
  70.     string get_name();// getter method
  71.     int get_user_no();// getter
  72.     int get_total();// getter
  73. } ; int GooglePlus::total=0;
  74.  
  75. // definition for GooglePlus class constructors:
  76. GooglePlus::GooglePlus() {
  77.     /*total++;
  78.     user_no=total;*/
  79. }
  80. GooglePlus::GooglePlus(string name,string password) {
  81.     total++;
  82.     user_no=total;
  83.     this->name=name;
  84.     this->password=password;
  85. }
  86.  
  87. // definition for GooglePlus Class methods:
  88. void GooglePlus::set_info(string name,string password) {
  89.     total++;
  90.     user_no=total;
  91.     this->name=name;
  92.     this->password=password;
  93. }
  94. string GooglePlus::get_name() {
  95.     return name;
  96. }
  97. int GooglePlus::get_user_no() {
  98.     return user_no;
  99. }
  100. int GooglePlus::get_total() {
  101.     return total;
  102. }
  103.  
  104. // Main Function
  105. int main(void) {                                                                   //### MAIN FUNCTION ###//
  106.     int choice_number,x=0,y=0;
  107.     Facebook *fbuser= new Facebook[100];
  108.     GooglePlus *gpuser= new GooglePlus[100];
  109.     string name,password; lol:
  110.     cout << "01. Add a Facebook user.\n02. Add a GooglePlus user.\n03. Compare popularity.\n" << endl;
  111.     cin >> choice_number;
  112.     switch (choice_number) {
  113.         case 1 :
  114.             cout << "\nFacebook Account-> "<< x+1 << endl ;
  115.             cout << "\nName: " ; cin.sync();
  116.             getline(cin,name);
  117.             cout << "Password: " ;
  118.             getline(cin,password);
  119.             fbuser[x].set_info(name,password);
  120.             x++;
  121.             break;
  122.         case 2 :
  123.             cout << "\nGooglePlus Account-> "<< y+1 << endl ;
  124.             cout << "\nName: " ; cin.sync();
  125.             getline(cin,name);
  126.             cout << "Password: " ;
  127.             getline(cin,password);
  128.             gpuser[y].set_info(name,password);
  129.             y++;
  130.             break;
  131.         case 3 :
  132.             compare(fbuser[0],gpuser[0]);
  133.     }
  134.     cout << "\n\n" ;
  135.     cout << "Another Cycle?(yes/no)\n" << endl; string y_n;
  136.     cin >> y_n;
  137.     cout << "\n\n" ;
  138.     if (y_n=="yes")
  139.         goto lol;
  140.     else
  141.         return 0;
  142. }
  143.  
  144. // definition Compare Function
  145. void compare(Facebook obf,GooglePlus obg) {
  146.     if(obf.get_total()>obg.get_total()) {
  147.         cout << "\n\nFacebook is more popular than googlePlus." << endl;
  148.     }
  149.     else if (obg.get_total()>obf.get_total()) {
  150.         cout << "\n\nGoogle Plus is more popular than Facebook." << endl;
  151.     }
  152.     else
  153.         cout << "\n\nBoth of them have same popularity." << endl;
  154. }
Add Comment
Please, Sign In to add comment