Professional Documents
Culture Documents
Objective(s) :
Lab 3 Tasks:
Task 1 :
#include<iostream>
using namespace std;
class Sphere
{
double pi;
public: Sphere()
{
pi=3.14;
}
~Sphere()
{
cout<<"destructor"<<endl;
}
double area(int r)
{ double area;
area=4*pi*r*r;
cout<<area;
return 0;
}
};
int main()
{ double radius;
Sphere s;
cout<<"Enter the radius"<<endl;
cin>>radius;
s.area(radius);
system("pause");
return 0;
}
class Clock{
int hours,min,sec;
public:
Clock(){
hours=min=sec=0;
}
~Clock(){
cout<<"Destructor"<<endl;
}
Clock(int h,int m,int s)
{
hours=h;
min=m;
sec=s;
cout<<hours<<":"<<min<<":"<<sec<<endl;
}
};
int main()
{ Clock t;
int hh,mm,ss;
cout<<"Enter hours : "<<endl;
HH:
cin>>hh;
if(hh<0||hh>12){
cout<<"Enter valid hours : ";
goto HH;}
cout<<"Enter minutes : "<<endl;
MM:
cin>>mm;
if(mm<0||mm>59){
cout<<"Enter valid minutes : ";
goto MM;
}
cout<<"Enter seconds : "<<endl;
SS:
cin>>ss;
if(ss<0||ss>59){
cout<<"Enter valid seconds : ";
goto SS;
}
Clock(hh,mm,ss);
system("pause");
return 0;
}
TASK 3:
#include<iostream>
Task 4 :
#include<iostream>
using namespace std;
class Time
{
int hours,minutes,seconds;
public:
Time( int = 0, int = 0, int = 0 );
void input()
};
int main()
{
Time t;
t.setTime(11,59,59);
Time t1= t;// copy constructor
cout<<"normal constructor"<<endl;
t.printUniversal();
cout<<"copy constructor"<<endl;
t1.printUniversal();
system("pause");
return 0;
}
Total 40 Signature
Note : Attempt all tasks and get them checked by your Lab Instructor.