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. 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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions