C How To Program, Global Edition
C How To Program, Global Edition
8th Edition
ISBN: 9781292110974
Author: Paul 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
We want to get an idea of how many tickets we have and what our issues are. Print the ticket ID number, ticket description, ticket priority, ticket status, and, if the information is available, employee first name assigned to it for our records. Include all tickets regardless of whether they have been assigned to an employee or not. Sort it alphabetically by ticket status, and then numerically by ticket ID, with the lower ticket IDs on top.
Figure 1 shows an ASM chart representing the operation of a controller. Stateassignments for each state are indicated in square brackets for [Q1, Q0].Using the ASM design technique:(a) Produce a State Transition Table from the ASM Chart in Figure 1.(b) Extract minimised Boolean expressions from your state transition tablefor Q1, Q0, DISPATCH and REJECT. Show all your working.(c) Implement your design using AND/OR/NOT logic gates and risingedgetriggered D-type Flip Flops. Your answer should include a circuitschematic.
A controller is required for a home security alarm, providing the followingfunctionality. The alarm does nothing while it is disarmed (‘switched off’). It canbe armed (‘switched on’) by entering a PIN on the keypad. Whenever thealarm is armed, it can be disarmed by entering the PIN on the keypad.If motion is detected while the alarm is armed, the siren should sound AND asingle SMS message sent to the police to notify them. Further motion shouldnot result in more messages being sent. If the siren is sounding, it can only bedisarmed by entering the PIN on the keypad. Once the alarm is disarmed, asingle SMS should be sent to the police to notify them.Two (active-high) input signals are provided to the controller:MOTION: Asserted while motion is detected inside the home.PIN: Asserted for a single clock cycle whenever the PIN has beencorrectly entered on the keypad.The controller must provide two (active-high) outputs:SIREN: The siren sounds while this output is asserted.POLICE: One SMS…
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
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,