This project is maintained by abrarShariar
View On Github




  Options.h

This header file contains all the necessary functions to handle Main Controller functionalities



Brief Description:


- Contains necessary functions to handle the features included in the Main Controller .

- Functions included here access the public functions defined in other classes .

- This is the hub of the whole program .

- Various functions defined here gives the user the flexibility to use different features of the sofware .


Functions


Person selectPerson()


//select from pre-registered person
Person selectPerson(){
    vector< Person >personList;

    map< int,string> selectMap;
    selectMap=RegisterPerson::readRegisterPerson();

    //display all registered person
    printf("\n\n\tAll Registered Person :\n\n");
    for(auto it=selectMap.begin();it!=selectMap.end();it++){
        cout<<"\t["<< it->first<<"] : "<< it->second<< endl;
        Person person(it->second);
        personList.push_back(person);
    }

    cout<< endl;

    //activated person
    int index;
    printf("Choose Person [index]: ");
    cin>>index;
    if(index>=personList.size()){
        throw "Caution: Please Enter Valid Index";
    }

    Person activePerson=personList[index];
    printf("\n\t\t%c%c ",219,219);
    cout<< activePerson.getPersonName()<<" is Activated !!"<<"\n\n";

    return activePerson;
}

                  

void selectPhone(Person activePerson)

  //select phone for a person
void selectPhone(Person activePerson){

        vector< Phone>phoneList;
        //Register Phone to Person
        int phoneCount;
        cout<< "Register Phone for "<< activePerson.getPersonName()<>phoneCount;
        cout<< endl;
        for(int i=0;i< phoneCount;i++){
            Phone phn(activePerson.getPersonId());
            cout<<"Phone["<< i<<"] : "<< phn.getPhoneNumber()<< endl;
            phoneList.push_back(phn);
        }
        cout<< endl;

        //Select Phone
        int phnIndex;
        cout<<"Select Phone: ";
        cin>>phnIndex;
        activePhone=phoneList[phnIndex];
        //Phone activities
        double credit;
        cout<<"\nUsing Phone["<< phnIndex<<"]: "<< activePhone.getPhoneNumber()<<"\t";
        cout<<"Load Credit:(tk) ";
        cin>>credit;
        activePhone.setPhoneCredit(credit);
}

bool processMenu(string option)

  //Process Controller/Main menu options
bool processMenu(string option){
        bool flag=true;
        int opt=666;
        for(int i=0;i< 6;i++){
            if(arrOption[i]==option){
                opt=i;
                break;
            }
        }
        switch(opt){
        case 0:
        {
            try{
                alphaPerson=selectPerson();
                selectPhone(alphaPerson);
            }catch(const char* exp){
                cerr<<"\n"<< exp<< endl;
            }
            break;
        }
        case 1:
            //RegisterPerson code here
            registerPerson();
            break;
        case 2:
            showPhoneScreen();
            chooseApp();
            break;
        case 3:
            viewPersonDetails();
            //ViewDetails code here
            break;
        case 4:
            //EXIT code here
            flag=false;
            break;
        case 5:
            system("cls");
            printf("%c%c",219,219);
            displayMenu();
            string option=chooseMenu();
            processMenu(option);
            break;
        }
        return flag;
}




void chooseApp()

    //Choose Phone App (see SFML)
void chooseApp(){
    string appName;
    printf("\n\n\tChoose App [Full Name] : ");
    cin>>appName;
    printf("\n");
    if(appName=="Phone" || appName=="phone"){
            usePhoneApp();
    }
    else if(appName=="Contacts" || appName=="Contacts"){
            printf("Contact List: \n");
    }
    else if(appName=="Text" || appName=="text"){

    }
}

void usePhoneApp()

//access all features of Phone
void usePhoneApp(){
    char opt;
    do{
        cout<<"Press + to Call & X to EXIT : ";
        cin>>opt;
        if(opt=='+'){
                string num;
                cout<<"Call Number: ";
                cin>>num;
                if(validPhoneNumber(num)){
                    PhoneCall myCall(num);
                    activePhone.newPhoneCall(num);
                    cout<<"Calling ";
                        loading();
                    cout<<" \a\aCall received"<< endl;
                    cout << endl;
                }else{
                    cout<<"INVALID PHONE NUMBER\n"<< endl;
                    continue;
                    }
        }else if(opt=='x' || opt=='X'){
            break;
        }else{
            cout<<"Please Enter A Valid Option: "<< endl;
        }
    }while(true);

        char chk;
        cout<<"\nView Call History (y/n) : ";
        cin>>chk;
        if(chk=='y'){
            viewCallHistory(activePhone);
            }

        alphaPerson.phoneBox.push_back(activePhone);
}

        

void useContactsApp()


void useContactsApp(){
    //vector< PhoneBook >tempBook;
    char chk;
    cout<<"\n\t\t[PhoneBook]\n"<< endl;
    string fileName=activePhone.getPhoneNumber()+".txt";
    activePhone.myPhoneBook=addPhoneBookEntry(fileName);
    cout<<"\nView Contact List (y/n): ";
    cin>>chk;
    cout<<"\n\t\t\tContact List\n"<< endl;
    if(chk=='y'){
        int len=activePhone.myPhoneBook.size();
    cout<< len<< endl;
        for(int i=0;i< len;i++){
             PhoneBook entry=activePhone.myPhoneBook[i];
            cout<<"\t\t"<< entry.getContactName()<<" : "<< entry.getContactNumber()<< endl;
        }
    }else{

    }
    cout<< endl;
}

        

void viewPersonDetails()

    //access all the features of Contacts/ PhoneBook

//view details of a Person
void viewPersonDetails(){
 char chk;
    cout<<"View Phone Details of (y/n) "<< alphaPerson.getPersonName()<<" : ";
    cin >>chk;
    printf("\n\n");
    if(chk=='y'){
        cout<<"Total Credit Available :"<< alphaPerson.getTotalCredit()<<" tk"<< endl;
        cout<<"Average Call Length: "<< alphaPerson.getAvgCallLength()/60<< endl;
        cout<< "Max Call Number: "<< alphaPerson.getMaxCallNumber()<< endl;
    }
}

  

void registerPerson()

    void registerPerson(){
    int regPerson;
    printf("\nHow many Person you want to register : ");
    cin>>regPerson;
    flushLine();
    printf("\n\n");

    for(int i=0;i< regPerson;i++){
        string name;
        cout<<"["<< i+1<<"]Person Name: ";
        getline(cin,name);
        RegisterPerson::setRegisterPerson(name);
    }
    RegisterPerson::writeRegisterPerson();
}