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
"""3. Write a function validSolution/ValidateSolution/valid_solution()that accepts a 2D array representing a Sudoku board, and returns trueif it is a valid solution, or false otherwise. The cells of the sudokuboard may also contain 0's, which will represent empty cells.Boards containing one or more zeroes are considered to be invalid solutions.The board is always 9 cells by 9 cells, and every cell only contains integersfrom 0 to 9. (More info at: http://en.wikipedia.org/wiki/Sudoku)""" # Using dict/hash-tablefrom collections import defaultdict def valid_solution_hashtable(board):    for i in range(len(board)):        dict_row = defaultdict(int)        dict_col = defaultdict(int)        for j in range(len(board[0])):            value_row = board[i][j]            value_col = board[j][i]            if not value_row or value_col == 0:                return False            if value_row in dict_row:                return False            else:                dict_row[value_row] += 1.
Is it correct to say that a function that accepts an array as a parameter has access to the original array or that it just has access to a copy of it?
c) Write a version of enqueue that checks for a full array. If the array is full, the function simply returns false. If the array is not full, the behaviour is the same as the original enqueue, except that the function also returns true.
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