This project is maintained by abrarShariar
View On Github




  RegisterPerson.h

This header file deifnes the class RegisterPerson



Brief Description:


- Contains the feature to register a new Person

- Contains the functionality to read names and index of registered Person saved in a .txt file

- All members are static


Static Members [public]

  • int totalRegistered
  • void setRegisterNumber()
  • void setRegisterPerson(string name)
  • void writeRegisterPerson()

  • Containers [public]

  • map<int,string> personMap
  • map<int,string> readRegisterPerson()

  • Code

    
    /*
        This File contains The class RegisterPerson
        Read and write names of registered person into a .txt file using 
    */
    #include< map>
    #include< iostream>
    #include< fstream>
    #include< sstream>
    using namespace std;
    
    class RegisterPerson{
        public:
            static void setRegisterNumber();
            static map< int,string> personMap;
            static int totalRegistered;
            static void setRegisterPerson(string name);
            static void writeRegisterPerson();
            static map< int,string> readRegisterPerson();
    };
    
    
    int RegisterPerson::totalRegistered=0;
    map RegisterPerson::personMap;
    
    void RegisterPerson::setRegisterPerson(string name){
        personMap[totalRegistered]=name;
        totalRegistered++;
    }
    void RegisterPerson::writeRegisterPerson(){
            ofstream write;
            write.open("Person/Registered_Person.txt");
            for(auto it=personMap.begin();it!=personMap.end();it++){
                write<first<<" : "<second< RegisterPerson::readRegisterPerson(){
            map< int, string> readMap;
            ifstream read;
            stringstream ss;
            int index;
            string name,num;
            string temp;
    
            read.open("Person/Registered_Person.txt");
            while(getline(read,temp))
            {
                int found=temp.find_first_of(":");
                num=temp.substr(0,found);
                name=temp.substr(found+2,temp.length()-1);
                ss<>index;
                readMap[index]=name;
            }
            read.close();
            return readMap;
    }
    
    //-------------------------------------------------