Using a programming language of your choice, write a complete and fully functional program that uses reference and pointer types to swap two integer numbers. The two numbers are read in separately by the program’s user. Use a proper prompt for each number read in.
a. Use one function that uses formal parameter reference type to swap the two numbers
b. Use another function that uses formal parameter pointer type to swap the two numbers.
c. In the main or driver function, call these two functions with the actual arguments received from the program’s user
d. Display immediately the result of the swapping after each function call in the calling function (the main function or the driver) before the next function call to see whether the numbers are swapped. Use the proper display messages.
Code:
#include<iostream>
#include<iomanip>
using namespace std;
// function to swap variables using reference
void swap_ref(int& n1, int& n2)
{
int temp;
temp = n1;
n1 = n2;
n2 = temp;
}
//function to swap variables using pointers
void swap_ptr(int *p, int *q)
{
int temp;
temp=*p;
*p = *q;
*q=temp;
}
int main()
{
//variable to store the input values
int x,y;
//temporary variables
int t1,t2;
// user input from the user
cout<<"Enter a integer point number: ";
cin>> x;
cout<<"\nEnter another integer point number: ";
cin>>y;
//copying the input values to temporary variables
t1=x;
t2=y;
cout<<"\n\nSwapping the variables using reference\n";
// the value of x and y before swapping
cout<<"\n\nBefore Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
//calling the function
swap(x,y);
//the value of x,y after swapping
cout<<"\n\nAfter Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
// reinitialize the value of x and y to user input values
x=t1;
y=t2;
cout<<"\n\nSwapping the variables using pointers\n";
// the value of x and y before swapping
cout<<"\nBefore Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
//calling the function
swap_ptr(&x,&y);
//the value of x,y after swapping
cout<<"\n\nAfter Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
// function to swap variables using reference
void swap_ref(int& n1, int& n2)
{
int temp;
temp = n1;
n1 = n2;
n2 = temp;
}
//function to swap variables using pointers
void swap_ptr(int *p, int *q)
{
int temp;
temp=*p;
*p = *q;
*q=temp;
}
int main()
{
//variable to store the input values
int x,y;
//temporary variables
int t1,t2;
// user input from the user
cout<<"Enter a integer point number: ";
cin>> x;
cout<<"\nEnter another integer point number: ";
cin>>y;
//copying the input values to temporary variables
t1=x;
t2=y;
cout<<"\n\nSwapping the variables using reference\n";
// the value of x and y before swapping
cout<<"\n\nBefore Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
//calling the function
swap(x,y);
//the value of x,y after swapping
cout<<"\n\nAfter Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
// reinitialize the value of x and y to user input values
x=t1;
y=t2;
cout<<"\n\nSwapping the variables using pointers\n";
// the value of x and y before swapping
cout<<"\nBefore Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
//calling the function
swap_ptr(&x,&y);
//the value of x,y after swapping
cout<<"\n\nAfter Swapping\n"<<endl;
cout<<"The value of x is :
"<<setprecision(2)<<fixed<<x<<endl;
cout<<"The value of y is :
"<<setprecision(2)<<fixed<<y;
return 0;
}

Using a programming language of your choice, write a complete and fully functional program that uses...
Last Coding Question! C++ is the programming language used This one is very difficult. My to do list is as follows: // This program uses a function to swap the values in two variables. /*TO DO: change the function swapNums to use two pointer parameters instead of two reference parameters, and then modify the complete program accodingly. */ #include <iostream> using namespace std; // Function prototype void swapNums(int&, int&); /***** main *****/ int main() { int num1 = 5, num2...
Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code. 1 // Lab 6 swapNums.cpp -- Using Value and Reference Parameters 2 // This program uses a function to swap the values in two variables . 3 // PUT YOUR NAME HERE. 4 #include <iostream> 5 using namespace std; 6 7 // Function prototype 8 void swapNums(int, int); 9 10 /***** main *****/ 11 int main() 12 { 13 int num1 = 5, 14...
answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...
81. The following function call doesn’t agree with its prototype: cout << BoxVolume( 10, 5 ); int BoxVolume(int length = {1}, int width = {1}, int height = {1}); T__ F__ 82. The following function is implemented to swap in memory the argument-values passed to it: void swap(int a, int b) { int temp; temp = a; a = b; b = temp; ...
In
c++ programming, can you please edit this program to meet these
requirements:
The program that needs editing:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int cal_avg(char* filenumbers, int n){
int a = 0;
int number[100];
ifstream filein(filenumbers);
if (!filein) {
cout << "Please enter a a correct file to read in the
numbers from";
}
while (!filein.eof()) {
filein >> number[a];
a++;
}
int total = number[0];
for (a = 0; a < n; a++) {...
I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...
THIS IS FOR C++ PROGRAMMING USING VISUAL
STUDIO
THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING
#include "pch.h"
#include
#include
using namespace std;
// Function prototype
void displayMessage(void);
void totalFees(void);
double calculateFees(int);
double calculateFees(int bags) {
return bags * 30.0;
}
void displayMessage(void) {
cout << "This program calculates the total
amount of checked bag fees." << endl;
}
void totalFees() {
double bags = 0;
cout << "Enter the amount of checked bags you
have." << endl;
cout <<...
Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...
Project Execute Tools AStyle Window Help 456 TDM-GCC 4.9.2 32-bit Profiling I"l practicel swapNums-KEY.cpp This progran uses a function to swop the values in two variables. 1 3 TO DO: 4 change the function swap Nuns to use two pointer parameters instead of two reference parameters, and 5 then modify the complete program accodingly <iostream > #include 8 9 using namespace std; 10 void swapNums (int&, int&) 12 int main() 13 14 15 int numl5, num2 = 7; 16 cout...
Create a program with the main function and one additional function. The additional function asks for input from the user and returns the output back to the main function for display. This is for c++ and here is my code, could you guys please tell me what I am missing from the instructions. Thank you #include <iostream> using namespace std; int sum (int, int); int main() { int n1, n2, total; cout << "Enter two numbers...