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. the text
Can you please check my code? everything works fine except the get id part, my program aborted after check the condition for m_id.
the text file is :
e, Sara Joseph,44, E491910 e, William Olver ,25, n456992 e, Jackson Benjamin,64, E789234 e, Mike John,54, E360537
The sample output is :
William Olver++Invalid record! ------------------------------------------------------------------------------------------------------------------------ | Test #1 Persons in the college! | ------------------------------------------------------------------------------------------------------------------------ | Employee | E491910 | Sara Joseph | 44 | | Employee | E789234 | Jackson Benjamin | 64 | | Employee | E360537 | Mike John | 54 | ------------------------------------------------------------------------------------------------------------------------ | Test #2 Persons in the college! | ------------------------------------------------------------------------------------------------------------------------ | Employee | E491910 | Sara Joseph | 44 | | Employee | E789234 | Jackson Benjamin | 64 | | Employee | E360537 | Mike John | 54 | ------------------------------------------------------------------------------------------------------------------------
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!"); }
after run my code, the output didn't catch William Olver++Invalid record! my output is:
------------------------------------------------------------------------------------------------------------------------ | Test #1 Persons in the college! | ------------------------------------------------------------------------------------------------------------------------ |Employee |E491910 |Sara Joseph |44 | |Employee |n456992 |William Olver |25 | |Employee |E789234 |Jackson Benjamin |64 | |Employee |E360537 |Mike John |54 | ------------------------------------------------------------------------------------------------------------------------ | Test #2 Persons in the college! | ------------------------------------------------------------------------------------------------------------------------ |Employee |E491910 |Sara Joseph |44 | |Employee |n456992 |William Olver |25 | |Employee |E789234 |Jackson Benjamin |64 | |Employee |E360537 |Mike John |54 | ------------------------------------------------------------------------------------------------------------------------
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started