Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions