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
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
Please pay attention to the required data types in the description. Thetuple, list and vector classes and their objects are not allowed to be used. 1. Define a new C++ class named “PayStub” that manages pay information: number of hours (integer), hourly pay rate (double). The total payout amount will be calculated based on overtime. Any hour that ismore than 40 hours will be paid at 1.5 pay rate. For example, with the hourly pay rate of $10.0 and if the number of hours is 40, the payout amount will be 400 and if the number of hours is 50 it will be (40 * 10)+ (10 * 15) = 550Please note that because the payout is a calculated value, it should not be part of the data members to make the object as small as possible. The class must provide at least the following two methods:• toString method that returns the string containing all the information about the paystub including the total payout amount. For example, here is the output for different paystubs:40 hours at $10.0 an hourHOURS(40)…
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.
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