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.
(Check test scores) The answers to a true-false test are as follows: T T F F T. Given a two-dimensional answer array, in which each row corresponds to the answers provided on one test, write a function that accepts the two-dimensional array and number of tests as parameters and returns a one-dimensional array containing the grades for each test. (Each question is worth 5 points so that the maximum possible grade is 25.) Test your function with the following data: int score = 0;
30.// programming
Write a function void reverse(int a[ ], int size)
to reverse the elements in array a, the second
parameter size is the number of elements in
array a. For example, if the initial values in
array a is {5, 3, 2, 0}.
After the invocation of
function reverse(), the final array values
should be {0, 2, 3, 5}
In main() function, declares and initializes an
integer array a with{5, 3, 2, 0}, call reverse()
function, display all elements in final array a.
Write the program on paper, take a picture, and upload
it as an attachment.
Or just type in the program in the answer area.
m861144
m861144
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
- Write a function that gets an array as a parameter (address and size) and a number and checks to see if that number exists in the array. The function should report every single occurrence of the number in the array. It should also report how many occurrences were detected in total (use c code)Suggested prototype: void findnReport(int* ar, int size, int num) Example of function output: If array = {2,5,3,5,12,13,14,15,0,5,-1,11,5} and num = 5, Number 5 found in array index 1 Number 5 found in array index 3 Number 5 found in array index 9 Number 5 found in array index 12 Total of 4 occurrences of number 5arrow_forward1. Write a Swift function that takes an array as a parameter and returns a boolean value whether the value 0 is present in the array or not.arrow_forwardWrite and test the “digit” function: Function Prototype: int digit(int n,int k)This function returns the kth digit of the positive integer n. For example, if n is the integer 29,415 that is entered by user , then the call digit(n,0) would return the digit 2, and the call digit(n,2) would returnthe digit 4. do this only by using functions and loops. arrays are not allowed. example :Input: n = 29415 , k = 1 output: 9 Input: n = 2 , k = 1 output: index out of bound (return -1)arrow_forward
- 3) Create a function named "makeThemOdd". The function should accept a parameter named "numberArray". Use the higher order function map() to create a new array that contains all the numbers from the original parameter array but adds 1 to each even number. The new array should only have odd numbers in it. Return the new array. // Use this array to test your function:const testingArray = [1, 2, 4, 17, 19, 20, 21];arrow_forwardIn java there must be at least two calls to the function with different arguments and the output must clearly show the task being performed. (ONLY ARRAYS or ARRAYLIST) Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated. Develop a function that returns true if the elements are in decreasing order and false otherwise. A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks. Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8,…arrow_forward(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_forward
- Question: 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_forwardImplement a function that finds the number of values that are less than 0 and the number of values greater than 0 stored in an array of integers. Assume the array is the partially filled array from the previous question, and uses 0 to indicate the end of values stored in it. (18 pts) Note: the results should be passed back to the caller, not directly displayed in the function. Also note, as the following code template requires, the function’s return type is void. Please finish the function header, and function implementation. Hint.. In the beginning, set the lessThan and greaterThan values to be 0. Then as you scan through the array elements one by one, compare the next array element with 0. If the element is greater, update your greaterThan count; otherwise, if the element is less, update the lessThan count, otherwise do nothing. Continue until you see the value 0. GIVEN CODE: #include <iostream>using namespace std; // Find the number of values stored that is less than 0…arrow_forward[In c#] Write a class with name Arrays . This class has an array which should be initialized by user.Write a method Sum that should sum even numbers in array and return sum. write a function with name numFind in this class with working logic as to find the mid number of an array. After finding this number calculate its factorial.Write function that should display sum and factorial.Don’t use divide operatorarrow_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