This project is maintained by abrarShariar
View On Github




  Person.h

This header file deifnes the class Person



Brief Description:


- Creates a new Person

- Registers a Phone with a Phone Number to a Person

- Methods to find:

  • Total credit over all phones
  • Average length of all calls made
  • Total cost of calls made last month from each phone
  • Max call number
  • - Registers a Phone with a Phone Number to a Person


    Data Members [private]

  • string personName
  • int personId

  • Member Functions [public]

  • Person()   [default constructor]
  • Person(string name)   [parameterize constructor]
  • string getPersonName()
  • int getPersonId()
  • double getTotalCredit()
  • double getAvgCallLength()
  • double getCostLastMonth()
  • string getMaxCallNumber()
  • int getPhoneBoxSize()

  • Static Members [static]

  • int personCount
  • int getPersonCount()

  • Containers

  • vector<string> allCallNumber
  • vector<Phone> phoneBox

  • Code

    
    #include "Phone.h"
    using namespace std;
    
    //class to create new Persons objects
    class Person{
        private:
            string personName;
            int personId;
    
        public:
            vectorallCallNumber;
            vectorphoneBox;
            //Person(){ };
            Person();
            Person(string name);
                                     
            string getPersonName();
            int getPersonId();
            double getTotalCredit();
            double getAvgCallLength();
            double getCostLastMonth(int index);
            string getMaxCallNumber();
            int getPhoneBoxSize();
    
        //static members
            static int personCount;
            static int getPersonCount();
    };
    
    Person::Person(){
        this->personName="";
        this->personId=0;
    }
    
    Person::Person(string name){
            this->personName=name;
            personCount++;
            this->personId=personCount;
    }
    
    int Person::getPhoneBoxSize(){
            return this->phoneBox.size();
    }
    
    //getters
    string Person::getPersonName(){
            return this->personName;
    }
    int Person::getPersonId(){
            return this->personId;
    }
    double Person::getTotalCredit(){
            double sumCredit=0;
            for(int i=0;iphoneBox.size();i++){
                double credit=phoneBox[i].getPhoneCredit();
                sumCredit=sumCredit+credit;
            }
            return sumCredit;
    }
    
    double Person::getAvgCallLength(){
        double totalCallLength=0,callCount=0;
         for(int i=0;iphoneBox.size();i++){
            Phone myPhn=this->phoneBox[i];
            for(int j=0;jphoneBox[index];
    
            time_t now=time(0);
            tm *ptm=localtime(&now);
            int currentMonth=ptm->tm_mon+1;
            int previousMonth=currentMonth-1;
            if(previousMonth==0){
                previousMonth=12;
            }
    
            double totalCost=0;
            for(int i=0;i>digit;
    
                if(digit==previousMonth){
                    totalCost=totalCost+call.getCallCost();
                }
            }
            return totalCost;
    }
    
    string Person::getMaxCallNumber(){
            int sz=this->getPhoneBoxSize();
        //store all call numbers from all Phone in phoneBox into the vector allCallNumber
            for(int i=0;iphoneBox[i];
                for(int j=0;jallCallNumber.push_back(num);
                }
            }
        //calculate the maximum callNumber stored in vector allCallNumber
            int mxCount=0,inCount;
            string mxCall;
            for(int i=0;imxCount){
                    mxCount=inCount;
                    mxCall=check;
                }
            }
            if(mxCall!=""){
                return mxCall;
            }
            else{
                return "NULL";
            }
    }
    
    //static members
    int Person::personCount=0;
    int Person::getPersonCount(){
            return personCount;
    }