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!

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 Answer

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: create a file in c++. Download the attached CreateRandomNumbersFile.cpp file, open it in Dev C++, an...

A: Program Instructions:Include necessary header files, declare local variables, and display a hello me...

Q: Let L1 = L (a∗baa∗) and L2 = L (aba∗). Find L1/L2.

A: Solution:Given that,Input: L1= L(a*baa*) and L2 = L(aba*) Output: Determine the L1/L2.We take all st...

Q: For problem 10RQ for Business Informaiton Systems book by Paige Baltzan, the question asked what is ...

A: The terms Collective intelligence, Knowledge management and Crowdsourcing are related to each other ...

Q: Find dfa’s that accept the following languages: (a) L (aa∗ + aba∗b∗). (b) L (ab (a + ab)∗ (a + aa)).

A: We will solve part (a) L (aa∗ + aba∗b∗) first. To get the DFA, we need to draw the NFA of the given ...

Q: Develop pseudocode for the problem of reading in the radius of a circle (r), calculate the area of t...

A: The program will have the following steps:Receive the input as a parameter passed to the function wh...

Q: Write a class AnalyzeNumbers which asks the user to enter the number of inputs andstores them in an ...

A: Program plan:Define the class “AnalyzeNumbers”.Define the “main()” method.Create object for “Scanner...

Q: Find regular grammars for the following languages on {a, b}: L = {w : na (w) and nb (w) are both eve...

A: Regular grammar for the language L = {W: na (w) and nb (w) are both even} is as follows:

Q: what are some of the technical advanteges that a firm can benenfit from selling their products on Am...

A: Technical advantages of selling the product in amazon rather than in own e-commerce website:The mark...

Q: How do you convert 172.16.20.55 to binary format?

A: 172.16.20.55 represents IP address in decimal format. In order to convert it into binary format we n...