Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // cpp program: fb and google popularity checker
- // AIUB Summer15-16 MiD exam pl2 Code-Writing ques 3
- // Author: fueanta
- #include <iostream>
- using namespace std;
- // prototype declaration for classes:
- class Facebook;
- class GooglePlus;
- // prototype declaration for global functions:
- void compare(Facebook,GooglePlus);
- // Facebook class:
- class Facebook{
- string name;
- string password;
- int user_no;
- static int total;
- public:
- Facebook();//constructor 1
- Facebook(string,string);// constructor 2
- void set_info(string,string);// setter method
- string get_name();// getter method
- int get_user_no();// getter
- int get_total();// getter
- } ; int Facebook::total=0;
- // definition for Facebook class constructors:
- Facebook::Facebook() {
- /*total++;
- user_no=total;*/
- }
- Facebook::Facebook(string name,string password) {
- total++;
- user_no=total;
- this->name=name;
- this->password=password;
- }
- // definition for Facebook Class methods:
- void Facebook::set_info(string name,string password) {
- total++;
- user_no=total;
- this->name=name;
- this->password=password;
- }
- string Facebook::get_name() {
- return name;
- }
- int Facebook::get_user_no() {
- return user_no;
- }
- int Facebook::get_total() {
- return total;
- }
- // GooglePlus class:
- class GooglePlus{
- string name;
- string password;
- int user_no;
- static int total;
- public:
- GooglePlus();//constructor 1
- GooglePlus(string,string);// constructor 2
- void set_info(string,string);// setter method
- string get_name();// getter method
- int get_user_no();// getter
- int get_total();// getter
- } ; int GooglePlus::total=0;
- // definition for GooglePlus class constructors:
- GooglePlus::GooglePlus() {
- /*total++;
- user_no=total;*/
- }
- GooglePlus::GooglePlus(string name,string password) {
- total++;
- user_no=total;
- this->name=name;
- this->password=password;
- }
- // definition for GooglePlus Class methods:
- void GooglePlus::set_info(string name,string password) {
- total++;
- user_no=total;
- this->name=name;
- this->password=password;
- }
- string GooglePlus::get_name() {
- return name;
- }
- int GooglePlus::get_user_no() {
- return user_no;
- }
- int GooglePlus::get_total() {
- return total;
- }
- // Main Function
- int main(void) { //### MAIN FUNCTION ###//
- int choice_number,x=0,y=0;
- Facebook *fbuser= new Facebook[100];
- GooglePlus *gpuser= new GooglePlus[100];
- string name,password; lol:
- cout << "01. Add a Facebook user.\n02. Add a GooglePlus user.\n03. Compare popularity.\n" << endl;
- cin >> choice_number;
- switch (choice_number) {
- case 1 :
- cout << "\nFacebook Account-> "<< x+1 << endl ;
- cout << "\nName: " ; cin.sync();
- getline(cin,name);
- cout << "Password: " ;
- getline(cin,password);
- fbuser[x].set_info(name,password);
- x++;
- break;
- case 2 :
- cout << "\nGooglePlus Account-> "<< y+1 << endl ;
- cout << "\nName: " ; cin.sync();
- getline(cin,name);
- cout << "Password: " ;
- getline(cin,password);
- gpuser[y].set_info(name,password);
- y++;
- break;
- case 3 :
- compare(fbuser[0],gpuser[0]);
- }
- cout << "\n\n" ;
- cout << "Another Cycle?(yes/no)\n" << endl; string y_n;
- cin >> y_n;
- cout << "\n\n" ;
- if (y_n=="yes")
- goto lol;
- else
- return 0;
- }
- // definition Compare Function
- void compare(Facebook obf,GooglePlus obg) {
- if(obf.get_total()>obg.get_total()) {
- cout << "\n\nFacebook is more popular than googlePlus." << endl;
- }
- else if (obg.get_total()>obf.get_total()) {
- cout << "\n\nGoogle Plus is more popular than Facebook." << endl;
- }
- else
- cout << "\n\nBoth of them have same popularity." << endl;
- }
Add Comment
Please, Sign In to add comment