Help with swap/pointers

...close
Last edited on
#include "StdAfx.h"
#include "Swap.h"
#include <iostream>
#include <math.h.>
#include <iomanip>
using namespace std;


Swap::Swap(void)
{
}


Swap::~Swap(void)
{
}

void swapDriver () 
{ 
int x; 
int y; 
 cout << "\nPlease enter x: "; 
 cin >> x; 
 cout << "\nPlease enter y: "; 
 cin >> y; 
 cout << "\n Here is the x value: "<< x << " and the y value: " << y; 
 swap  (&x, &y );
 cout << "\n After swap: Here is x: "<< x << " and y: " << y; 
}


this is what i have so far, is this right?
no one has any input?
closed account (D80DSL3A)
Your swap() needs two int pointers as arguments.


Add a new function to your class called swap.
• Add a swapDriver function to your class as well.

It seems that Swap shouldn't be it's own class. You are supposed to add the swap() and swapDriver() methods to an existing class (Finance?).

Can you swap 2 integer values?
1
2
3
4
5
int a=3, b=4;
// swap the values of a and b
int temp = a;
a = b;
b = temp;

Do that using pointers to a and b instead.
bump, any other input?
Topic archived. No new replies allowed.