C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
Question
Book Icon
Chapter 13, Problem 13.14E
Program Plan Intro

Program Plan:

  • Insert required header Files
  • Create new file PhoneNumber.h.
  • Make a class PhoneNumber and declare extraction and insertion operators as friend to class.
  • Declare three string variable “ areacode ”, “ exchange ”, “ line ” and one character array “ phno ” to get phone number in an array.
  • End header class.
  • Close and save header file.
  • Create new file Phonenumber.cpp. This will contain definitions and modification required in extraction operator ">>".
  • Include header files, must include PhoneNumber.h
  • Overload the insertion operator to display areacode, exchange and line.
  • Make changes the extraction operator definition.
  • use "getline()" function to get input into "phno". The "getline()" function is used to identify psaces also.
  • Use if construct to check various conditions
  • Check for length of input entered which should be 14, use input.clear(ios::failbit) to set failbit.
  • Check that areacode does not start with either 0 or 1, if it does then use input.clear(ios::failbit) to set failbit.
  • Check that exchange does not start with either 0 or 1, if it does then use input.clear(ios::failbit) to set failbit.
  • Check that middle digit of areacode should be either 0 or 1, if not then use input.clear(ios::failbit) to set failbit.
  • If all the conditions are false, this means that input is correct, thus put them into areacode, exchange and line of number object passed through the function.
  • return input
  • end function
  • Make new C++ file for main() function.
  • Include header files, must include PhoneNumber.h.
  • Start main function.
  • Declare an object of PhoneNumber class phone.
  • Display message to enter phone number.
  • Use cin>>phone which will call overloaded extraction operator.
  • Check whether state returned is goodbit(incase failbit is not set in the function) then display phone number else display error.
  • Return and exit.

Program Description:

Program to get correct input by overloading extraction operator.

Blurred answer
Students have asked these similar questions
- in this exercise, please do not include and use string class. The function is using only array notation and manipulation.- string functions such as strlen is not allowed.- it should not have multiple return statements in the same function- there should be no global variable.- the function should not traverse the arrays more than once (e.g. looping through the array once only) A C++ PROGRAM named "isTheLastNumberTheMax" that accepts an array of integers and its size. It will return true if the last number in the array is the maximum number in that array and false otherwise. In addition, it also returns another boolean to indicate whether this list contains more than one maximum value.For example, if this is called with the array of {10, 20, 30, 40, 50}, it will return true and falseIf this is called with the array of {50, 10, 20, 30, 40, 50}, it will return true and true. A C++ PROGRAM named "changeCase" that takes an array of characters terminating by NULL character (C-string) and…
- in this exercise, please do not include and use string class. The function is using only array notation and manipulation.- string functions such as strlen is not allowed.- it should not have multiple return statements in the same function- there should be no global variable.- the function should not traverse the arrays more than once (e.g. looping through the array once only) write a c++ program named "isTheLastNumberTheMax" that accepts an array of integers and its size. It will return true if the last number in the array is the maximum number in that array and false otherwise. In addition, it also returns another boolean to indicate whether this list contains more than one maximum value.For example, if this is called with the array of {10, 20, 30, 40, 50}, it will return true and falseIf this is called with the array of {50, 10, 20, 30, 40, 50}, it will return true and true.
I need the answer quickly   What is the meaning of the following declaration? int(*p[5])(); a) p is pointer to functionb) p is array of pointer to functionc) p is pointer to such function which return type is the arrayd) p is pointer to array of function
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr