Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Force
- {
- double mass;
- double acceleration;
- public:
- Force(double m, double a);
- Force(const Force&);
- ~Force();
- double Mass(void){
- return mass;
- }
- };
- Force::Force(double m, double a)
- {
- mass = m;
- acceleration = a;
- cout<<"Passing through the constructor with arguments\n";
- }
- Force::Force(const Force &g)
- {
- mass = g.mass;
- acceleration = g.acceleration;
- cout<<"Passing through copy constructor.\n";
- }
- Force::~Force()
- {
- cout<<"Passing through the destrctor.\n";
- }
- void idle1(Force f)
- {
- cout<<"Entering function idle ONE \n\n";
- }
- Force idle2(Force &f)
- {
- cout<<"Entering function idle TWO \n\n";
- return f;
- }
- Force idle3(Force *f)
- {
- cout<<"Entering function idle Three\n\n";
- return (*f);
- }
- int main()
- {
- cout<<" f1"<<endl;
- Force f1(0.0,0.0);
- cout<<" f2"<<endl;
- Force f2(4.3, 9.9);
- f1 = Force(f2); // using the copy constructor to copy attribute values
- //from source object f2 into destination object f1
- cout<<"Calling idle1"<<endl;
- idle1(f1);
- cout<<"f3"<<endl;
- Force f3(7.5, 9.8);
- cout<<"f4"<<endl;
- Force f4(0.0,0.0);
- cout<<"f4 <-copy<-f3"<<endl;
- f4 = Force(f3);
- cout<<"calling idle2"<<endl;
- Force f5 = idle2(f4);
- cout<<"Calling idle3"<<endl;
- Force f6 = idle3(&f4);
- cout<<"The mass of the final force (#6): "<< f6.Mass() <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement