This project is maintained by abrarShariar
View On Github



  Methods.h

This header file deifnes the necessary functions and extensions to other classes



Brief Description:


- Contains necessary functions and extensions to the other classes .

- Can be considered as a supporting header file .

- Containes additional faetures and funtionalities .


Functions


vector<string> readFromFile (string fileName)

vector readFromFile(string fileName){
    vector readFile;                  
    ifstream read;
    read.open(fileName);
    string output;
    while(getline(read,output)){
        readFile.push_back(output);
    }
    read.close();
    return readFile;
}
                  

void displayFile (string fileName)

void displayFile(string fileName){
    ifstream display;
    string line;
    display.open(fileName);
    while(getline(display,line)){
        cout<< line<< endl;
    }
    display.close();
}
                  

void writeToFile (vector<PhoneBook> myPhoneBook,string fileName)

void writeToFile(vector myPhoneBook,string fileName){
    ofstream write;
    fileName="PhoneBook/"+fileName;
    write.open(fileName);
    for(int i=0;i< myPhoneBook.size();i++){
        PhoneBook phoneBook=myPhoneBook[i];
        string name=phoneBook.getContactName();
        string number=phoneBook.getContactNumber();
        write<< name<< " : "<< number<< endl;
    }
    write.close();
}

                  

bool validPhoneNumber (string number)

//function to validate if a number is a valid phone number
bool validPhoneNumber(string number){
    bool chk;
    if(number.length()==11){
            for(int i=0;i=48 && number[i]<=57){
                    chk=true;
                }else{
                    chk=false;
                    break;
                }
            }
    }else{
        chk=false;
    }
    return chk;
}
                  

void viewCallHistory (Phone phone)

/*
Function to display Call History/details
*/
void viewCallHistory(Phone phone){
    for(int i=0;i< phone.getCallHistorySize();i++){
         PhoneCall call=phone.getCallHistory(i);
        cout<<"Call Details["<< i+1<< "]"<< endl;
        cout<<"Call Number: "<< call.getCallNumber()<<"\t";
        cout<<"Rate: "<< call.getCallRate() << "p/s"<< endl;
        cout << "Duration: "<<  call.getCallDuration()/60<<"min\t";
        cout<<"Cost: "<< call.getCallCost()<<"tk"<< endl;
        cout<< endl;
    }
}
                  

bool checkDuplicate (vector phoneBook)

/*
    Function to be used on PhoneBook objects
    return true duplicate entry is found and false otherwise
*/
bool checkDuplicate(vector< string >phoneBook){
    for(int i=0;i< phoneBook.size();i++){
        int chk=0;
        string check=phoneBook[i];
        for(int j=0;j< phoneBook.size();j++){
            if(phoneBook.at(j)==check){
                chk++;
            }
        }
        if(chk>1){
            return true;
            break;
        }
    }
    return false;
}
                  

void addPhoneBookEntry (string fileName)

/*
    Function to add a vector to the given fileName
*/
void addPhoneBookEntry(string fileName){
    string temp1,temp2;
    int ct;
    stringstream ss;
    vectormyPhoneBook;
    printf("Number of Phone Book Entry: ");
    scanf("%d",&ct);

    for(int i=0;i< ct;i++){
        PhoneBook myEntry;
        printf("Contact Number: ");
        cin>>temp1;
        cin.ignore(numeric_limits::max(), '\n');        //http://stackoverflow.com/questions/5918451/why-getline-skips-first-line
        myEntry.setContactNumber(temp1);
        printf("Contact Name: ");
        getline(cin,temp2);
        myEntry.setContactName(temp2);
        //temp="";
        myPhoneBook.push_back(myEntry);
        cout<< endl;
    }
        //to write myPhoneBook to a file
    writeToFile(myPhoneBook,fileName);
}

                  

Person choosePerson (vector< Person > personList,string index)

                        /*
    Function to choose new Person
    returns a person object
*/
Person choosePerson(vector< Person >personList,string index){
    for(int i=0;i< personList.size();i++){
       Person per=personList[i];
        if(index==per.getPersonName()){
            return per;
            break;
        }
    }
}


                      
void flushLine()

   /*
    code to fix first line skip of getline()
    the following code is found at:
    http://stackoverflow.com/questions/5918451/why-getline-skips-first-line
    */
void flushLine(){
        cin.ignore(numeric_limits::max(), '\n');
    }

                      

void loading()

  void loading(){
    int show=219;
    for(int i=0;i< 50;i++){
        for(int j=0;j < 7000000;j++){
        }
        printf("%c",show);
    }
}
                      

string showDate()

string showDate(){
        time_t now=time(0);
        tm *ptm=localtime(&now);
        int day=(ptm->tm_mday);
        int month=(ptm->tm_mon)+1;
        int year=1900+((ptm->tm_year));

        stringstream c_day,c_month,c_year;
        c_day<< day;
        string d=c_day.str();
        c_month<< month;
        string m=c_month.str();
        c_year<< year;
        string y=c_year.str();

        string startDate=m+"/"+d+"/"+y;
        return startDate;
}
                      

string showTime()


string showTime(){
     time_t now=time(0);
        tm *ptm=localtime(&now);
        int hour=(ptm->tm_hour);
        int mint=(ptm->tm_min);
        int sec=(ptm->tm_sec);

        stringstream c_hour,c_mint,c_sec;
        c_hour<< hour;
        string h=c_hour.str();
        c_mint<< mint;
        string m=c_mint.str();
        c_sec<< sec;
        string s=c_sec.str();

       string startTime=h+":"+m+":"+s;
        return startTime;
}

                      

void preRegister()

// SEE RegisterPerson.h
void preRegister(){
    map< int,string > preMap;
    RegisterPerson::setRegisterPerson("Abrar Shariar");
    RegisterPerson::setRegisterPerson("Steve Jobs");
    RegisterPerson::setRegisterPerson("Mike");
    RegisterPerson::setRegisterPerson("Harry Potter");
    RegisterPerson::setRegisterPerson("Batman");
    RegisterPerson::setRegisterPerson("Mark Tyson");
    RegisterPerson::setRegisterPerson("Henry Ford");
    RegisterPerson::setRegisterPerson("Rakib Hasan");
    RegisterPerson::setRegisterPerson("Fahim Khan");
    RegisterPerson::setRegisterPerson("Gilfoyle");
    RegisterPerson::setRegisterPerson("Richard Hendricks");
    RegisterPerson::setRegisterPerson("Bruce Wayne");
    RegisterPerson::setRegisterPerson("Jon Snow");

    RegisterPerson::writeRegisterPerson();
}


                      

void displayMenu()

//Functions to handle MENU activities
string arrOption[]={"[+S]","[+R]","[+P]","[+D]","[X]","[#]"};
void displayMenu(){
    string arrText[]={"Select Person","Register Person","Use C++ Phone","View Details","EXIT","View Main Controller"};
    char icon=219;
    //HEAD
     for(int i=0;i < 3 0;i++){
        cout<< icon;
    }
    cout << " MAIN Controller \n"<< endl;

    //Body
    // fist 2 icon
    for(int i=0;i < 2;i++){
       cout<< arrOption[i]<<"\t\t\t";
    }
    cout<< endl;
    // first 2 text
    for(int i=0;i< 2;i++){
        cout<< arrText[i] << " \t\t";
    }
    cout<<"\n\n";
    //second 2 icon
    for(int i=2;i< 4;i++){
        cout<< arrOption[i]<<"\t\t\t";
    }
    cout<< endl;
    //second 2 text
    for(int i=2;i< 4;i++){
        cout<< arrText[i]<<"\t\t";
    }
    cout<<"\n\n";
    //last two icon
    for(int i=4;i < 6;i++){
        cout<< arrOption[i]<< "\t\t\t";
    }
    cout<< endl;
    //last two text
    for(int i=4;i < 6;i++){
        cout<< arrText[i]<<"\t\t\t";
    }

    cout<<"\n";
    for(int i=0;i< 30;i++){
        cout<< icon;
    }
    cout<< endl;
}

                      

string chooseMenu()

string chooseMenu(){
    bool valid=false;
    string option;
    cout<<" Choose Controller Option: ";
    cin>>option;
    option="["+option+"]";
    for(int i=0;i < 6;i++){
        if(option==arrOption[i]){
            valid=true;
            break;
        }
    }
    if(valid==false){
        return "INVALID INPUT !!";
    }else{
        return option;
    }
}