Data structures and algorithms in C++
Data structures and algorithms in C++
2nd Edition
ISBN: 9780470460443
Author: Goodrich
Publisher: WILEY
Question
Book Icon
Chapter 2, Problem 18R
Program Plan Intro

A class “Pair”

Program plan:

  • Declare the header files and namespace.
  • Create a template class “Pair”,
    • Declare the public access modifier.
      • Declare the generic type variables.
      • Define the public access modifier.
      • Define the constructor to set the initial values.
      • Define the method “display1()” to print the output.
  • Define the “main()” function,
    • Initialize the necessary constant variables.
    • Print the string “Pair 1.”.
    • Construct the first object to pair integer and string values.
    • Call the method to “display1()” to print the pair of integer and string values.
    • Print the string “Pair 2.”.
    • Construct the second object to pair float and long type values.
    • Call the method to “display1()” to print the pair of float and long type values.
    • Print the string “Pair 3.”.
    • Construct the third object to pair double and char type values.
    • Call the method to “display1()” to print the pair of double and char type values.
    • Print the string “Pair 4.”.
    • Construct the fourth object to pair integer and double type values.
    • Call the method to “display1()” to print the pair of integer and double type values.
    • Print the string “Pair 5.”.
    • Construct the fifth object to pair string and char type values.
    • Call the method to “display1()” to print the pair of string and char type values.
    • Return “0”.

Blurred answer
Knowledge Booster
Background pattern image
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