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
What is the definition of operator and function overloading? Is there anything beneficial about it?
What do you mean by function overloading? Can you explain it with code?
Kindly give proper explanation and output I will rate your answer  Write a program in C++ that uses member functions like get data and set data and make a parameterized constructor,,, default constructor also to find tha area of a box(like cube) (.h&.pp)
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning