Create a new file in c++ and save it as lab11_XYZ.cpp (replace XYZ with your initials). Create ANOTHER new file (in C++) and save it as swap_XYZ.h (replace XYZ with your initials).   Use the swap_XYZ.h header file to define a set of functions for swapping two items of the same type. Given the following prototypes, define (overloaded) swap functions void swap(int&, int&);  //swap two integers void swap(double&, double&);  //swap two doubles void swap(float&, float&);  //swap two floats void swap(char&, char&);  //swap two characters void swap(string&, string&);  //swap two strings The header file should contain the following: header comments (similar to normal program header comments) function prototypes (provided above) function definitions (for you to do...) In general, a swap works like this: void swap(type first&, type second&){    type temp = first; first = second; second = temp; } Once your header file (H file) is complete, make sure to include it in your main CPP program. Use double quotes instead of angle brackets. Make sure the H file is located in the same folder as the CPP file. #include <iostream>#include "swap_XYZ.h" using namespace std;   Write a driver program to test your header file. The program should test each version of the swap function and display the results. The program should display a hello message consider using displayMessage()! for each version of swap() provide or prompt for two items display which version is being called display values before swap call swap function display values after swap display a goodbye message use displayMessage() again!

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section8.3: Random File Access
Problem 6E
icon
Related questions
Question

Create a new file in c++ and save it as lab11_XYZ.cpp (replace XYZ with your initials).

Create ANOTHER new file (in C++) and save it as swap_XYZ.h (replace XYZ with your initials).

 

Use the swap_XYZ.h header file to define a set of functions for swapping two items of the same type.

Given the following prototypes, define (overloaded) swap functions

  • void swap(int&, int&);  //swap two integers
  • void swap(double&, double&);  //swap two doubles
  • void swap(float&, float&);  //swap two floats
  • void swap(char&, char&);  //swap two characters
  • void swap(string&, string&);  //swap two strings


The header file should contain the following:

  • header comments (similar to normal program header comments)
  • function prototypes (provided above)
  • function definitions (for you to do...)

In general, a swap works like this:

void swap(type first&, type second&){    type temp = first; first = second; second = temp;

}

Once your header file (H file) is complete, make sure to include it in your main CPP program. Use double quotes instead of angle brackets. Make sure the H file is located in the same folder as the CPP file.

#include <iostream>#include "swap_XYZ.h"

using namespace std;

 

Write a driver program to test your header file. The program should test each version of the swap function and display the results.

The program should

  • display a hello message consider using displayMessage()!
  • for each version of swap()
    • provide or prompt for two items
    • display which version is being called
    • display values before swap
    • call swap function
    • display values after swap
  • display a goodbye message use displayMessage() again!

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Stack operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr