PLEASE COMPLETE THE MISSING CODE FOR THE 2 GIVEN FUNCTIONS in the attached screenshot (using C++ ) ostream& print(ostream& ostr, bool toFile = true) const; If the current object is in a valid state it...



PLEASE COMPLETE THE MISSING CODE FOR THE 2 GIVEN FUNCTIONS in the attached screenshot (usingC++)



ostream& print(ostream& ostr, bool toFile = true) const;


If the current object is in a valid state it inserts the values of the Contact information in two different formats based on the value of thetoFileargument:



  • iftoFileis true, prints the data in comma separated format:

    • prints the name

    • print comma

    • print the phone number using the private function



  • iftoFileis false prints the data in the following format:

    • In 50 characters, left justified and padded with dots ('.')

    • prints the name

    • print the phone number using the private function



  • At the end it returns theostrreference



istream& read(istream& istr);


Reads the Contact information in followng format:



  • name

  • comma

  • (

  • area code

  • )

  • space

  • exchange code

  • dash ('-')

  • number


Example: Luke Skywalker,(647) 555-9475


set implementation


In local variables read each part and if data is invalid set theistrto failure:



  • using istream::get() read the name up toMaxNameLengthor a comma (do not extract comma)

  • extract a comma. (usingextractCharprivate function)

  • extract an open parentheses'('character (usingextractCharprivate function)

  • extract the area code into a local variable (istr >> value;)

  • extract a close parentheses')'(usingextractCharprivate function)

  • extract a space character (usingextractCharprivate function)

  • extract the exchange code into a local variable

  • extract a dash character'-'(usingextractCharprivate function)

  • extract the number into a local variable

  • extract a new line character'\n'(usingextractCharprivate function)

  • ifistris not in a failure state

    • all data were read successfully, use thesetprivate function to set values of the object to read value



  • ifistris in a failure state, don't do anything a leave the Contact to its original values.

  • at the end return theistrreference


std::ostream& Contact::print(std::ostream& ostr, bool toFile = true) const {
if (*this)
{
if (toFile)
{


}
else
{


}
}
return ostr;
}
std::istream& Contact::read(std::istream& istr) {
char name[MaxNameLength];
int ac = -1, ec = -1, num;
//read name using
istr.get(name, MaxNameLength, ',');


// extract a comma;
extractChar(istr, ',');


//read ac
//read ec
//read num


}

Oct 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here