Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help on how to answer this: The other functions in the Time.cpp file do not need to be answered only the Time::read function,

I need help on how to answer this:

The other functions in the Time.cpp file do not need to be answered only the Time::read function, just trying to figure out how to do this

I got this from here:https://github.com/Seneca-244200/OOP-Project#setting-istream-to-a-fail-state

Time::read

std::istream& read(std::istream& istr); 

Reads the time from a stream in H:M format. It makes sure that the two integers (hours and minute) are greater than zero and separated by ":", otherwise it will set theistreamobject to afailure state.

This function does not react to any invalid data, instead, it will work exactly how istream works;It will put the istream in a failure state if anything goes wrongby following these steps:

  • reads the integer for the hours usingistrand if the value is negative, it setsthe istream object to a failure state.
  • reads one character and makes sure it is':'. If it is not':', it will setthe istream object to a failure state.
  • reads the integer for the minutes usingistrand if the value is negative, itsets the istream object to a failure state.

setting istream to a fail state

To set the istream to a fail state manually call the following method of istream:

setstate(ios::failbit); 

Note: Do not clear or flush theistreamobject since this method complies with theistreamstandards. The caller of this function may check the state of theistreamobject to make sure that the read was successful if needed.

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