Skip to content

Instantly share code, notes, and snippets.

@rsmahmud
Last active January 16, 2017 16:39
Show Gist options
  • Save rsmahmud/79a9c3b1846e5623886662dc91fce8d0 to your computer and use it in GitHub Desktop.
Save rsmahmud/79a9c3b1846e5623886662dc91fce8d0 to your computer and use it in GitHub Desktop.
/**
* Create a class named 'rotation'. it contains 4 variables of int type.
* Write a function to rotate their values with pass by ref. approach.
*/
#include<iostream>
#include<conio.h>
using namespace std;
class rotation{
private:
int x,y,z,w;
public:
void input(){
cout<<"Enter 4 integers : ";
cin>>x>>y>>z>>w;
}
void display(){
cout<<"Value of x : "<<x<<endl;
cout<<"Value of y : "<<y<<endl;
cout<<"Value of z : "<<z<<endl;
cout<<"Value of w : "<<w<<endl;
}
void fun(){
ROTATION(&x,&y,&z,&w);
}
void ROTATION(int*x,int*y,int*z,int*w){
cout<<endl<<"Rotating..."<<endl;
int temp;
temp = *w;
*w = *z;
*z = *y;
*y = *x;
*x = temp;
}
};
int main(){
class rotation rr;
rr.input();
cout<<endl<<"Before rotation :"<<endl;
cout<<"-----------------"<<endl;
rr.display();
rr.fun();
cout<<endl<<"After rotation :"<<endl;
cout<<"-----------------"<<endl;
rr.display();
return getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment