Create a new file (in Dev C++) and save it as lab11_XYZ.cpp (replace XYZ with your initials).Create ANOTHER new file (in Dev 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 functionsvoid swap(int&, int&);  //swap two integersvoid swap(double&, double&);  //swap two doublesvoid swap(float&, float&);  //swap two floatsvoid swap(char&, char&);  //swap two charactersvoid swap(string&, string&);  //swap two stringsThe header file should contain the following:header comments (similar to normal program header comments)function definitions (for you to do, based on provided prototypes above...)In general, a swap works like this:void swap(type first&, type second&){  type temp = first;  first = second;  second = temp;}Once your header file is complete, make sure to include it in your main CPP program. Use double quotes instead of angle brackets. Make sure the header file (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 consider using prompt()!display which version is being calleddisplay values before swapcall swap functiondisplay values after swapdisplay a goodbye message use displayMessage() again!Submit the completed H file and the completed CPP file (not the EXE file) back to this assignment

Question
Asked Nov 5, 2019

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

Create ANOTHER new file (in Dev 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 definitions (for you to do, based on provided prototypes above...)

In general, a swap works like this:

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

}

Once your header file is complete, make sure to include it in your main CPP program. Use double quotes instead of angle brackets. Make sure the header file (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 consider using prompt()!
    • display which version is being called
    • display values before swap
    • call swap function
    • display values after swap
  • display a goodbye message use displayMessage() again!

Submit the completed H file and the completed CPP file (not the EXE file) back to this assignment

check_circleExpert Solution
Step 1
  • This C++ program contains header file swap_XYZ.h and cpp file lab11_XYZ.cpp
  • swap functions for int, char, string, float and double are placed in header file.
  • swap functions are called in cpp file.
Step 2
swap_XYZ.h
 
#include <string.h>
#include <iostream>
using namespace std;
 
 
/*
This header file contains swap functions which accepts inputs of type integer, float, double, char and string.
*/
 
//function definitions
 
//swap integer type values
void swap(int& first, int& second)
{
int temp;
temp=first;
first=second;
second=temp;
}
 
//swap double type values
void swap(double& first, double& second)
{
double temp;
temp=first;
first=second;
second=temp;
}
 
//swap float type values
void swap(float& first, float& second)
{
float temp;
temp=first;
first=second;
second=temp;
}
 
//swap character type values
void swap(char& first, char& second)
{
char temp;
temp=first;
first=second;
second=temp;
}
 
//swap string type values
void swap(string& first, string& second)
{
string temp;
temp=first;
first=second;
second=temp;
}
Step 3
lab11_XYZ.cpp
 
#include <iostream>
#include <string.h>
#include "swap_XYZ.h"
using namespace std;
 
//function declarations
void displayMessage(string msg);
double prompt();
char prompt(char ch);
 
int main()
{
//display hello message on screen
displayMessage("Hello!");
 
//input String values and swap them
displayMessage("***************String values swap****************");
string str2,str1;
cout<<"Enter value : ";
getline(cin,str1);
cout<<"Enter value : ";
getline(cin,str2);
cout<<"before swap :"<<str1<<" and "<<str2<<endl;
swap(str1,str2);
cout<<"After swap :"<<str1<<" and "<<str2<<endl;
 
 
//input integer values and swap them
displayMessage("***************Integer values swap****************");
int num1=(int)prompt();
int num2=(int)prompt();
cout<<"before swap :"<<num1<<" and "<<num2<<endl;
swap(num1,num2);
cout<<"After swap :"<<num1<<" and "<<num2<<endl;
 
//input Double values and swap them
displayMessage("***************Double values swap****************");
double num3=prompt();
double num4=prompt();
cout<<"before swap :"<<num3<<" and "<<num4<<endl;
swap(num3,num4);
cout<<"After swap :"<<num3<<" and "<<num4<<endl;
 
//input Float values and swap them
displayMessage("***************Float values swap****************");
float num5=(float)prompt();
float num6=(float)prompt();
cout<<"before swap :"<<num5<<" and "<<num6<<endl;
swap(num5,num6);
cout<<"After swap :"...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: WHAT ARE THE STAKEHOLDERS OF BITCOIN VALUE CHAIN?

A: The stakeholders in bitcoin value chain are:Developers Developers play an important role as they use...

question_answer

Q: Python 3.7.4: The current calendar, called the Gregorian calendar, was introduced in 1582. Every yea...

A: In order to correct given program, make the following changes:Put def main() code above the def leap...

question_answer

Q: consider the udp header 12 03 00 0F 00 1E A3 10.What is the total length of the udp

A: The UPD header basically has 4 parts, each part is of 2 bytes. That means following interpretation o...

question_answer

Q: Hello! I am new to Java and have nearly finished up a project involving a mortgage table, and everyt...

A: According to the question, students need only in output spacing.To display output in proper spacing ...

question_answer

Q: A transitive dependency is equivalent to which of the following?A) A functional dependency between t...

A: Transitive dependencyA transitive dependency in a database is an indirect relationship between value...

question_answer

Q: For the following code segment write the machine language representation of each instruction in bina...

A: Instruction 1:

question_answer

Q: Form boolean equations in POS and SOP forms from the truth table attached (PLEASE EXPLAIN ALL STEPS)...

A: The circuit diagrams that correspond to the following Boolean equations  drawed using an online tool...

question_answer

Q: whats is the length of UDP?

A: The given User Datagram Protocol header is 12 03 00 0F 00 1E A3 10.The UDP (User Datagram Protocol) ...

question_answer

Q: Think of one of your Math homework. How can you use program to reveal the answer? Write a calculatio...

A: Variables in PHP: Variables are used to store values like numbers, characters etc. that is of differ...