Answered step by step
Verified Expert Solution
Question
1 Approved Answer
swapper.cpp : /************************* program: swap two integers **************************/ #include using namespace std; void swapper (int & x, int & y); int main() { int myx=3,
swapper.cpp :
/************************* program: swap two integers **************************/ #include using namespace std; void swapper (int & x, int & y); int main() { int myx=3, myy=4; cout Part 1 --Function Templates Copy this file to your computer. The file: swapper.cpp swapper. cpp contains a "swapper" function that will swap two integer values Your primary tasks for this exercise are: 1. Create a function template which will swap two values of any type. 2. Create a function template which will print any two values passed to it. Steps include: Convert the function "swapper" (from swapper. cpp) into a templated function. . Try and use it for swapping integers. Build and Run the executable. Now, create another templated function which will print any two values passed to it. You can name it "printem". Add a call to "printem" before and after the call to your swap routine (replacing the current "cout" statements). Build and Run the executable. Add variable pairs of different types so that your program can handle o int o char o double Include "swapper" and "printem" calls to ensure that these functions are working for these types as well. Build and Run the executable. Your output should look something like the following: First Value is: 3 Second Value is: 48 AFTER SWAP First Value is: 48 Second Value is: 3 First Value is: 5.5 Second Value is: 8.5 AFTER SWAP First Value is: 8.5 Second Value is: 5.5 First Value is: a Second Value is: b AFTER SWAP First Value is: b Second Value is: a Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started