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.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
(FRP7) Write a function that reads data from a file. The file has already been opened and verified. The data should be saved in the array of type ship. The size of the array is passed in the int parameter and the number of records read is return in the last parameter, by reference. The file should be read until end of file has been reached or the array is full.
struct ship{ string shipCaptain; string shipName;
};
The function prototype isvoid readFile( ifstream&, ship[ ], int, int& );
ifstream - The already open file
ship[ ] - array of structs where the data from the file will be stored.
int - the size of the array.
int& - the number of records read from the file. This value is set by the function before returning
return- the number of records read from the file, returned by the function.
The amount of data in the file is unknown but there is no bad data. The file format is the shipsName followed by the shipsCaptiain .
Example:
MillenniumFalcon HansSolo
State whether the following are true or false. If the answer is false, explain why.a) A pointer that’s declared to be void can be dereferenced.
state the statement either true or false.
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
- (10) Question 2.2 NOTE: Pointers must be used to solve the following problem. You will 8 marks if pointers are not used, even if the solution is correct. Write a function createPassword() with no return value to randomly select 8 capital letters from the alphabet. The function receives the address of the first characters of the password string as parameter. Hint: Declare a characters string that contains all the capital letters of the alphabet and use the index values of the characters in the string for random selection of characters, e.g. 5 char alpha [27] = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; char *pAlpha = alpha;arrow_forwardC++ Programming. Topic: Working with pointers and dynamic memory. Indicators. Working with dynamic memory. Dynamic arrays and their use as function parameters. Task : Describe a void function named Swap(x,y) that swaps the values stored in the variables x and (x is a real type parameter and is both input and output). Using this function , for the given variables of real type a, b, c, d, one should sequentially replace the values of the pairs (a, b), (c, d) and (b, c) and let a, b, c, d be new values .arrow_forward(Reading Phone Numbers with and Overloaded Stream Extraction Operator) In Fig. 18.5,the stream extraction and stream insertion operators were overloaded for input and output of objectsof the PhoneNumber class. Rewrite the stream extraction operator to perform the following errorchecking on input. The operator>> function will need to be reimplemented.a) Input the entire phone number into an array. Test that the proper number of charactershas been entered. There should be a total of 14 characters read for a phone number ofthe form (800) 555-1212. Use ios_base-member-function clear to set failbit for improper input.arrow_forward
- Write in C++ Language. (Employee Record): Create a class named 'Staff' having the following members: Data members - Id – Name - Phone number – Address - AgeIt also has a function named 'printSalary' which prints the salary of the staff.Two classes 'Employee' and 'Officer' inherits the 'Staff' class. The 'Employee' and 'Officer' classes have data members 'Top Skill' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a officer by making an object of both of these classes and print the same.arrow_forward(Replace strings) Write the following function that replaces the occurrence of a substring old_substring with a new substring new_substring in the string s. The function returns true if string s is changed, and otherwise, it returns false. bool replace_strings (string& s, const string& old_string, const string& new_string) Write a test program that prompts the user to enter three strings, i.e., s, old string, and new_string, and display the replaced string.arrow_forward.“Dangling and wild pointers are known to be problems with pointers”. Justify the given statement with the helpof suitable examplearrow_forward
- The following describes the difference between void and NULL pointers: Make proper use of examples to bolster your argument.arrow_forward(Complex Class) Write a program that accomplishes each of the following:a) Create a user-defined class Complex that contains the private integer data members realand imaginary and declares stream insertion and stream extraction overloaded operatorfunctions as friends of the class.b) Define the stream insertion and stream extraction operator functions. The stream extraction operator function should determine whether the data entered is valid, and, ifnot, it should set failbit to indicate improper input. The input should be of the form3 + 8ic) The values can be negative or positive, and it’s possible that one of the two values is notprovided, in which case the appropriate data member should be set to 0. The streaminsertion operator should not be able to display the point if an input error occurred. Fornegative imaginary values, a minus sign should be printed rather than a plus sign.d) Write a main function that tests input and output of user-defined class Complex, usingthe overloaded…arrow_forward3- It is not possible to change the value of the pointer. (True or False). 4- If the following lines of code have errors, correct them; otherwise, write "no errors." for (int i=2; i<5; i++) { int s=1*2; } cout << s; 5- A function cannot be called from inside another function. (True or False). 6- How to make a function return multiple values? 7- Every class member is by default. (public, private, not public nor private) 8- Create an instance of the following class and call its methods. class Exam{ int grade; public: void seta (int b) (grade=b; } int geta () {return grade; } 9- When the word const is put before the variable definition, what does that mean? 10- How to concatenate two strings in C++ language? C++arrow_forward
- Language: C++ Create a class called publication that stores the title (char array) and price (float) of a publication. From this class derive two classes: book, which adds a page count (int) and tape, which adds a playing time in minutes (float). Each of the three classes should have a getdata() function to get its data from the user using input from the keyboard and a putdata() function to display the data.Write a main function that creates an array of pointers to publication. In a loop, ask the user for data about a particular type of book or tape to hold data. Put the pointer to the object in the array. When the user has finished entering data for all the books and tapes, display the resulting data for all the books and tapes entered, using a for loop and a single statement such as: pubarr[j] -> putdata(); To display the data from each object in the array.arrow_forwardThe following is the difference between void and NULL pointers: Use relevant examples to back up your statement.arrow_forwardDon't use vector array .using ifstream and ofstream. C++ programarrow_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