C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 21, Problem 21.15E
a.
Program Plan Intro
- Declare variable xCoordinate and yCoordinate of type int as private member of class.
- Provide declaration of ostream and istream operator as friend function.
Program Description: To create point class having two integer data membersxcoordinate and ycoordinate and provide declaration for stream insertion and stream extraction overloaded operator functions.
b.
Program Plan Intro
Program Plan:
- Define overloaded insertion operator <<. Inside the definition use an if-else statement to check if the failbit was set or not.
- If not then display the value of xCoordinate and yCoordinate data members of point class else display the message that wrong input was entered.
- Also inside the else part use call clear function of clear the failbit.
- Define overloaded extraction operator>>. Inside the definition use ignore function to ignore the first bracket, then read the first interger value , then again use ignore to ignore the comma and extra space, next read the ycoordinatevalue and finally use ignore to skip the last closing bracket.
Program Description: To implement the overloaded insertion and extraction functions of class point in file point.cpp.
c.
Program Plan Intro
Program Plan:
- Include header file point.h
- Declare a variable A of type Point.
- Use cin statement to read the value of point in variable A.
- Use cout statement to display the value of variable A if correct value was entered.
Program Description: To write a driver program to test the Point class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
state the statement either true or false.
X Whether the following
statement is TRUE or
FALSE?
When an object is returned by a function, a temporary
object is automatically created to hold the return value.
Indicate whether the following is true or false:Only pointers and references are permissible for use with dynamically bound virtual functions.
Chapter 21 Solutions
C How to Program (8th Edition)
Ch. 21 - (Write C++ Statements) Write a statement for each...Ch. 21 - (Inputting Decimal, Octal and Hexadecimal Values)...Ch. 21 - Prob. 21.8ECh. 21 - Prob. 21.9ECh. 21 - Prob. 21.10ECh. 21 - Prob. 21.11ECh. 21 - (Converting Fahrenheit to Celsius) Write a program...Ch. 21 - In some programming languages, strings are entered...Ch. 21 - Prob. 21.14ECh. 21 - Prob. 21.15E
Knowledge Booster
Similar questions
- - Create a struct called Complex for performing arithmetic with complex numbers. Write a driver program to test your struct. Complex numbers have the form: realPart + imaginaryPart * iwhere i is the square root of -1Use double variables to represent data of the struct. Provide a function that enables an object of this struct to be initialized when it is declared. The function should contain default values in case no initializers are provided. Also provide functions for each of the following:a) Addition of two Complex numbers: The real parts are added together and the imaginary parts are added together.b) Subtraction of two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.c) Printing Complex numbers in the form (a, b) where a is the real part and b is the imaginary partSubmit one file which contains all code above: the structure…arrow_forwardWrite 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_forwardC++ programming Language Write a program that converts a number entered in Roman numerals todecimal form. Program should consist of a class, say romanType. Anobject of romanType should do the following:a. Store the number as a Roman numeral.b. Convert and store the number into decimal form.c. Print the number as a Roman numeral or decimal number as requested by the user. (Write two separate functions—one to print the number as aRoman numeral and the other to print the number as a decimal number.)The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1Remember, a larger numeral preceding a smaller numeral means addition,so LX is 60. A smaller numeral preceding a larger numeral means subtraction, so XL is 40. Any place in a decimal number, such as the 1s place, the10s place, and so on, requires from zero to four Roman numerals. (The program must include implementation files, .cpp and .h )arrow_forward
- #include <iostream> #include <fstream> using namespace std; /* This program declares a class called Inventory that has itemnNumber (which contains the id number of a product) and numOfItem (which contains the quantity on hand of the corresponding product)as private data members.The program will read these values from a file and store them in an array of objects (of type Inventory). It will then print these values to the screen. Example: Given the following data file: 986 8 432 24 This program reads these values into an array of objects and prints the following: Item number 986 has 8 items in stock Item number 432 has 24 items in stock */ const NUMOFPROD = 10; // This holds the number of products a store sells class Inventory {public: void getId(int item); // This puts item in the private data member // itemNumber of the object that calls it. void getAmount(int num); // This puts num in the private data member // numOfItem of the object that calls it.…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_forward- In C++ using Visual Studio - Seperate the files if there is any .cpp, .main or .h files. PART 1Read the contents of the text file and store them in a C++ data structure called std::map<string, int>This map is a collection of sorted <key, value> pairsIn this case, the keys are unique words found in the text file, and the values represent the number of times each word appearsFor example, since the word "cat" appears twice in the file, then map["cat"] = 2 PART 2Iterate through the map and print each key in the order they appearThis will give you a sorted list of unique wordsHere's the expected result: "a big cat does everything feeding goats helping injured juvenile kangaroos locating missing notorious objects playing quietly reading superb tales upvoting videos with xylophone yielding zebras" PART 3Iterate through the map again, this time printing each associated valueThe values represent how many times each word was found in the text filePay attention to the sequence of…arrow_forward
- help with c++ paste indented code plzz Have to use given main function to test your answer Q2: Continue with House class:a) Copy the previous program to a new file.b) Write Constructor with two parameter, and assign to location, and price.c) Write default constructor, initialize location to “TBD”, price to 0, Implement constructor delegationd) implement a non-member function names output that will print all information of House object. Use following main() to test your class. int main(){House a("1234 qcc st, Bayside, NY",1000000); output(a); House b; output(b); } Output from given main: Location: 1234 qcc st, Bayside, NY Price: 1000000 Location: TBD Price: 0\ ANSWER:arrow_forwardTrue False questions :arrow_forwardNonearrow_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