C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
Question
Book Icon
Chapter 23, Problem 23.3E
Program Plan Intro

Program Plan-

  • 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
Check Mark

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…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education