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.15E
Program Plan Intro
Program Plan:
- Make a header file Point.h
- Declare header definition- include necessary header files and then create point class declaration.
- Make stream insertion and stream extraction overloaded function as friend to the class.
- Declare two private integers to store number point as xCoordinate and YCoordinate.
- End point header.
- Create “Point.cpp” file for defining function of header “Point.h”.
- Include all necessary header file and also "point.h" for making point class declared in header file available here.
- Overload the stream insertion operator, to display xCoordinate and YCoordinate.
- Overload the stream extraction operator, to check if input is in form "(x,y)” or not.
- Declare array p to get input from stream, extractx and extracy to extract value of xCoordinate and YCoordinate from the stream.
- Determine the size of stream "p".
- Set initial value of fail to 1.
- Check if first and last character of input is '(' and ')' respectively, if not se fail to 1.
- In the else part. run two loops to get x and y value of point which is seperated by ','.
- Run for loop from position 1 till ',' is found or till counter 'i' reaches size of input 'p'. Which means no ',' is entered, thus wrong input.
- Check if character is digit or not, if not a digit, then set fail=1, else extrcat value in extractx.
- After execution of for loop, check if “fail ==1 (some incorrect input) or i != size (which means no comma found)”. If both cases are false, then use a similar for loop to extract value of y.
- Check if “fail==1” (some wrong input) and set ios::failbit and clear the input.
- If fail is still 0, then put values of extractx and extact y in xCoordinate and YCoordinate respectively.
- Return the input.
- Make "Main.cpp" to write main function, which must include "point.h"
- Declare "p" as object of point class.
- Use cin>>p which itself will call overloaded extraction and check for input.
- Check the rdstate for goodbit, if failbit not set then display point using cout<<p. which will again call insertion overload for display.
- Else error message is displayed.
- Return and exit.
Program Description:
Write a point class, which checks for valid input data by overloading stream insertion and stream extraction operator functions.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Indicate whether the following is true or false:Only pointers and references are permissible for use with dynamically bound virtual functions.
What is wrong in the following function?
What is the output of following code.
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
- 1. Inspect the code and in your own interpretation, describe the reason call to functionChangeIt_1(n) will not change x in main()? 2. Inspect the code and in your own interpretation, describe the reason parameter n inChangeIt_2(int *n) is a pointer, and statement in the function is *n = 6 ? 3. Write a function called void swap with two parameters, which will receive the addressof x and y as pointer. The function should swap the value of x and y only if x is larger thany. Print the value of x and y after the function call. 4. Write a function called double getAverage(int *array, int SIZE), whereit accept the array as pointer, and return the average of the array. Print the returnedvalue from this function. Always use *array rather than subscript to access the arrayvalue.arrow_forwardOverload the following operators. > < <=arrow_forwardIs that right?For functions that are flexibly bound, you need pointers or references.arrow_forward
- 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 functionarrow_forward3. What is the function of the Unload Me statement?arrow_forwardc++, anyone able to help with this, no vectors, no sstream, no pointers, also need a toLower function loop within to account for case insensivity, NEED ASAP pleasearrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning