Question: Can you please check my code? everything works fine except the get id part, my program aborted after check the condition for m_id. Employee::Employee(std::istream& istr)

Can you please check my code? everything works fine except the get id part, my program aborted after check the condition for m_id.

Employee::Employee(std::istream& istr) { // get name getline(istr, m_name, ','); m_name = removeSpace(m_name);

//get age getline(istr, m_age, ','); m_age = removeSpace(m_age); if (!isInteger(m_age)) { throw std::invalid_argument(m_name + "++Invalid record!"); }

// get id getline(istr, m_id,','); m_id = removeSpace(m_id); /* if (!m_id.empty()|| m_id[0] != 'E') { throw std::invalid_argument(m_name + "++Invalid record!"); }*/ if (m_id.empty() || m_id.front() != 'E') throw std::invalid_argument(m_name + "++Invalid record!"); }

instruction for this code:

a custom constructor that receives an object of type std::istream& as parameter. This constructor should be able to read a single record from the stream, extract all the information about a single Employee and store it in the attributes. Each record has the following format:

TAG,NAME,AGE,EMPLOYEE ID 
  • TAG, is a single character representing the type of person: e or E for Employee. Any other tag is considered invalid. The tag is handled in Utilities.
  • NAME, the name of the employee
  • AGE, an integer containing the official age of the employee. If the content of this field is not a number, then the field is considered invalid and should throw a message made up of the name of the employee and "++Invalid record!"
  • EMPLOYEE ID, represents the Employee ID at the College. It should start with letter E Any other character is considered invalid should throw a message made up of the name of the employee and "++Invalid record!".
  • any space at the beginning/end of each field should be removed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!