
C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)
10th Edition
ISBN: 9780134583006
Author: Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
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.
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
Design and draw a high-level "as-is" process diagram that illustrates a current process related to a product or service offered through the SSDCI.gov database.
Compare last-mile connections for connecting homes and businesses to the Internet
Explain wireless networking standards
Chapter 13 Solutions
C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)
Ch. 13 - (Write C ++ statements) Write a statement for each...Ch. 13 - (Inputting Decimal, Octal and Hexadecimal Values)...Ch. 13 - Prob. 13.8ECh. 13 - (Printing with field Widths) Write a program to...Ch. 13 - (Rounding) Write a program that prints the value...Ch. 13 - (Length of a String) Write a program that inputs a...Ch. 13 - (Converting Fahrenheit to Celsius) Write a program...Ch. 13 - In some programming language, string are entered...Ch. 13 - Prob. 13.14ECh. 13 - Prob. 13.15E
Knowledge Booster
Similar questions
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr

Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning