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 23, Problem 23.3E
Program Plan Intro
- To include header files and required namespaces.
- To define function template equalTemplate of type class.
- To define tool function isEqualTo with two values to be compare as arguments using template type EqualTemplate.
- Intiaiize the main() function.
- Prompt user to input two entities of same type.
- Call function isEqualTo to evaluate for eachtype.
Summary Introduction- This program evaluates equality of two entities using function templates.
Program Description- The program uses user defined function: isEqualTo() and evaluates the equality of two entities using function templates.
Expert Solution & Answer
Explanation of Solution
Program:
/* Program toevaluate the equality of two entities using function templates. . */ //header files #include<iostream> usingnamespacestd; //template defined template<classequalTemplate> //evaluates equality boolisEqualTo(equalTemplate input1,equalTemplate input2) { //check for qualtiy if( input1== input2) returntrue; elsereturnfalse; } //initialize main() function intmain() { int intVal1, intVal2; double floatVal1, floatVal2; char charVal1, charVal2; //Integer Comparison cout<<"Input two integer values:"; cin>>intVal1>>intVal2; cout<<intVal1<<" and "<<intVal2<<" are "<<(isEqualTo(intVal1, intVal2)?"Equal":"Not Equal")<<endl; //Double Comparison cout<<"Input two floating-point values:"; cin>>floatVal1>>floatVal2; cout<<floatVal1<<" and "<<floatVal2<<" are "<<(isEqualTo(floatVal1, floatVal2)?"Equal":"Not Equal")<<endl; //Character Comparison cout<<"Input two character values:"; cin>>charVal1>>charVal2; cout<<charVal1<<" and "<<charVal2<<" are "<<(isEqualTo(charVal1, charVal2)?"Equal":"Not Equal")<<endl; return0; }
Sample Output-
Input two integer values:23 44
23 and 44 are Not Equal
Input two floating-point values:23.33 45.5
23.33 and 45.5 are Not Equal
Input two character values: a A
a and A are Not Equal
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Do you have to use the template prefix for each function in the class defini- tion? Do you have to use the template prefix for each function in the class implementation?
(Dynamic Binding vs. Static Binding) Distinguish between static binding and dynamicbinding. Explain the use of virtual functions and the vtable in dynamic binding
- 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…
Chapter 23 Solutions
C How to Program (8th Edition)
Ch. 23 - Prob. 23.3ECh. 23 - (Array Class Template) Reimplement class Array...Ch. 23 - Prob. 23.5ECh. 23 - Explain which is more like a stencil—a class...Ch. 23 - Prob. 23.7ECh. 23 - The compiler performs a matching process to...Ch. 23 - Prob. 23.9ECh. 23 - Prob. 23.10ECh. 23 - Review your answer to Exercise 23.10. Explain why...Ch. 23 - Prob. 23.12E
Knowledge Booster
Similar questions
- - Create a class Rational for performing arithmetic with fractions.Write a driver program to test the class. Provide a constructor thatenables an object of this class to be initialized when it isinstantiated. The constructor should contain default values in caseno initializes are provided and should store the fraction in reducedform. Provide a private function to reduce numbers.Provide Public member functions for each of the followingarithmatic’s functions (addition – subtraction – multiplication –division), printing in the form a/b, printing in floating point formatand final overload the == and != operators to allow comparisons oftwo fraction numbers.Include any additional operations that you think would be useful fora rational number class.Design, implement, and test your class.arrow_forward(Combining Class Time and Class Date) Combine the modified Time class of Exercise 17.7and the modified Date class of Exercise 17.8 into one class called DateAndTime. (In Chapter 19, we’lldiscuss inheritance, which will enable us to accomplish this task quickly without modifying the existing class definitions.) Modify the tick function to call the nextDay function if the time increments into the next day. Modify functions printStandard and printUniversal to output the dateand time. Write a program to test the new class DateAndTime. Specifically, test incrementing thetime into the next day.arrow_forwardCan I please get help writing this in C++ Write a class called Word that stores a word from a product review in a data member called “word.” The class should also contain an integer variable representing the number of times (i.e. frequency) that the word was found in a product review document. The class should have a one-argument constructor that receives a pointer to a c-string (character array) containing the word as its one parameter. (Note that the output of the strtok_s function described above is a pointer to a c-string containing the word that was parsed. This is what you will pass in to the Word constructor.) The Word constructor should also set the frequency of this Word object to 1. Appropriate set and get functions should be included for both the word and frequency data members. Write a class called Review that contains a vector of objects of the Word class. The class should contain functions to add a new Word object to the vector and to print out all of the Words in…arrow_forward
- Go program using method of " Build functions with Reflection to Automate Repetitive Tasks." Output : Calling main.timeMe took 1s Calling main.timeMeToo took 2s 4arrow_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_forwardHelp and show me how to fix an error? def kwargs_to_args_decorator(*args, **kwargs): This question is meant to test your knowledge of creating a decorator that accepts an arbitrary number of positional and keyword arguments, to decorate a function that accepts an arbitrary number of positional and keyword arguments, and alters the arguments before passing them to the decorated function. When the decorated function is invoked, this decorator should modify the arguments the decorated function receives. This decorator should filter out all positional arguments passed to the decorated function, which are found in the positional arguments passed to the decorator when the decorator was initialized. It should also filter out all keyword arguments with keys that are found in the keyword arguments given to the decorator when the decorator was initialized. After performing the modifications to the arguments, the decorator should invoke the decorated function with the modified arguments and…arrow_forward
- In 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_forwardConsider the function void modify(int & x) { x = 10; }Show how to call the modify function so that it sets the integer int i;to 10.arrow_forwardWhat must you be sure of when passing a class object to a function template that uses an operator, such as * or >?arrow_forward
- (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate class defined in Programming Exercise 10.14 – see the textbook - to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person's name. Draw the UML diagram for the classes and implement them. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.arrow_forwardA function template can be overloaded by another function template with the samefunction name. T/Farrow_forwardINSTRUCTIONS: Write a C++ script/code to do the given problems. MOVIE PROBLEM: Write a function that checks whether a person can watch an R18+ rated movie. One of the following two conditions is required for admittance: The person is atleast 18 years old. • They have parental supervision. The function accepts two parameters, age and isSupervised. Return a boolean. Example: acceptIntoMovie(14, true) → true acceptIntoMovie(14, false) → falsearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education