C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey 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 solutionStudents 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.
9. Write function getMoveRow to do the following a. Return type integer b. Parameter list i. 1-d character array (i.e. move), size 3 c. Convert the row portion of the player’s move to the associated integer index for the board array d. Example: i. move = ‘b2’ ii. 2 is the row iii. 2 is index 1 in the board array e. Return the row array index that corresponds to the player’s move f. Return a -1 if the row is not valid (i.e. INVALID) 10. Write function getMoveCol to do the following a. Return type integer b. Parameter list i. 1-d character array (i.e. move), size 3 c. Convert the column portion of the player’s move to the associated integer index for the board array d. Example: i. move = ‘b2’ ii. b is the column iii. b is index 1 in the board array e. Return the column array index that corresponds to the player’s move f. Return a -1 if the column is not valid (i.e. INVALID)
I am getting an error when entering the code at the very end. please fix it.
This is the code in C
int…
.“Dangling and wild pointers are known to be problems with pointers”. Justify the given statement with the helpof suitable example
Chapter 13 Solutions
C++ How to Program (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
- (find the minimum valuein an array)write a programthat include a recrusive function "recrusiveMinimum" that takes an integer array and the array size as arguments an return the smallest element of the arraythe function should stop processing and return when it receivesan array of one elementarrow_forwardQuestion: Given an array of integers, find the maximum and minimum elements present in the array. Your task is to write a function that takes an array of integers as input and returns the maximum and minimum elements as a pair of integers..arrow_forward(This is the link to what I have so far) https://onlinegdb.com/YbiMruMpvarrow_forward
- (IN C PLEASE) must attcah output screenshot answer properly write a function to allocate an array of 10 ints using malloc(), and see if the values are initialized to 0. You can use print_array() to check. Define 3 structs: square, rect, and circle. Then, write 3 functions area_sq(), area_rect(), and area_circ() to compute and return the area for the respective shape.arrow_forward3."""Code _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.arrow_forwardQ2: Write a C++ function (call it index_max) that finds the maximum number in the array, that is passed to the function, and returns the max number and its index. For example, if you pass [5,6,8,9,5,2] to the function, you obtain 9 and 3. Write a C++ program and test your function. Take the following notes into consideration when writing your program: 1- Your function should work with any data type. 2- The function should prevent changing the elements of the passed array. 3- You are not allowed to use materials that are not covered in our lectures.arrow_forward
- Please use C++ and make sure it's for a sorted array Write a function, removeAll, that takes three parameters: an array of integers,the number of elements in the array, and an integer (say, removeItem). Thefunction should find and delete all of the occurrences of removeItem in thearray. If the value does not exist or the array is empty, output an appropriatemessage. (Note that after deleting the element, the number of elements in thearray is reduced.) Assume that the array is sorted.arrow_forwardIn c++ , perform insertion into the dynamic array at the start, end, and middle as well and perform array resizing as well. ( Drop code in words , explain the code and drop the screenshot of output as well )arrow_forwardii) Write a explicit custom comparator that sorts the array in descending order. Test the custom comparator taking a random array. C++arrow_forward
- Indicate true or false for the following statements: a. Every element in an array has the same type. b. The array size is fixed after an array reference variable is declared. c. The array size is fixed after it is created. d. The elements in an array must be of a primitive data typearrow_forwardMATCH OUTPUT WITH QUESTION OUTPUT ------------------------------ Write a C++ program to input N integer numbers into a single dimension array. Sort them in ascending order using the bubble sort technique. Print both the given array and the sorted array with suitable headings.Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.Define the sort method in the Sort class. Input Format:The first input consists of an integer which corresponds to the number of elements present in the single dimension array. The next 'n' inputs are the elements in the array. Output Format:The first line output consists of array elements before sorting and the next line of the output consists of array elements after sorting.Refer to sample input and output for formatting specifications.[All text in bold corresponds to input and the rest corresponds to output]…arrow_forwardThe goal is to use the following C++ Functions: Conditional Statement Arrays Looping (Any) To create a system that would do the following functions: Accept an input of five integer numbers in a single array object. Use a loop to get the five integer numbers. Arrange the five numbers from lowest to highest. Output the new array object which displays the arranged integers from highest to lowest.arrow_forward
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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning