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
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.
in c++ write a code that: Define an enumeration type triangleType that has the values scalene, isosceles, equilateral, and noTriangle.Write a function triangleShape that takes as parameters three numbers, each of which represents the length of a side of the triangle. The function should return the shape of the triangle. (Note: In a triangle, the sum of the lengths of any two sides is greater than the length of the third side.)Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle.
please use c#  (Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. explain each step well
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