Professional Documents
Culture Documents
B.1 Software Code Written by Student and Input and Output: P1. Code
B.1 Software Code Written by Student and Input and Output: P1. Code
Part B
(Students must submit the soft copy as per following segments within two hours of
the practical. The soft copy must be uploaded on the Blackboard or emailed to the
concerned lab in charge faculties at the end of the practical in case the there is no Black
board access available)
P1.
Code:
#include<iostream>
class number
int num;
public:
number(int n)
num=n;
void display()
{
cout<<"\n\nNumber="<<num;
};
void number::operator++()
num=num+1;
int main()
number ob(6);
ob.display();
++ob;
ob.display();
//ob++;
//ob.display();
return 0;
Output:
P2.
Code:
#include<iostream>
class box
int x,y,z;
public:
box(){}
x=a;
y=b;
z=c;
box a;
a.x=x+b.x;
a.y=y+b.y;
a.z=z+b.z;
return a;
void display()
cout<<"\n\tx="<<x<<"\n\ty="<<y<<"\n\tz="<<z;
};
int main()
box ob3=ob1+ob2;
cout<<"ob1 : ";
ob1.display();
cout<<"\n\nob2 : ";
ob2.display();
cout<<"\n\nob3 : ";
ob3.display();
return 0;
Output:
P3.
Code:
#include<iostream>
class Dollars
double Dollar;
public:
Dollars()
Dollar =0.0;
Dollars(double x)
Dollar = x;
display();
}
void display()
};
class Rupees
double Rupee;
public:
Rupees()
cin>>Rupee;
Rupees(double a)
Rupee=a;
cout<<"\n\n"<<Rupee<<"\n\n";
operator Dollars()
display();
return (Rupee/66.58);
}
void display()
};
int main()
int R;
cin>>R;
Rupees q=R;
Dollars ob=q;
return 0;
Output:
B.2 Conclusion:
Learnt to implement static or compile time polymorphism using operator
overloading.
a) ::
True. User defined data types cannot be implicitly converted, a casting operator
must be defined in the source class or a constructor with an object of source type
class must be defined in the destination class.
It depends on what type the casting is being done to. It can be a user defined return type
or a pre-defined return type too.