Gaurab Oop 6 PDF
Gaurab Oop 6 PDF
#include<math.h>
class Vector{
int arr[3];
public:
Vector(int
array[]){ for(int
i=0;i<3;i++)
arr[i]=array[i];
void
displayVector(){ for
(int i=0;i<3;i++)
cout<<arr[i]<<" ";
};
int main()
vec.displayVector();
return 0;
#include<iostream>
using namespace std;
class Time{
private:
float hour;
int m;
public:
Time(){}
Time(float
min){ float
hr=min/60;
hour=int(hr);
m=60*(hr-hour);
void
Display(){ cout<<hour<<"hour"<<m<<"minute
s";
}
};
int
main(){ float
min=254; Time x;
x=min;
x.Display();
return 0;
r.
private:
float h, m;int minute,s;
public:
Time(){}
Time(float
sec){ float m=
sec/60; float
hour=m/60;
h=int(hour);
minute=60*(hour-h);
s=sec-(h*60*60+minute*60);
}
void
display(){ cout<<h<<"hour"<<minute<<"minute"<<s<<"seconds
";
}
};
int
main(){ float
sec=4000; Time
t;
t=sec;
t.display();
return 0;
Day D
December 31.
The constructor for the class should take as parameter an integer representing the day
of the year, and the class should have a member function print() that prints the day
in the month–day format. The class should have an integer member variable to represent
the day, and should have static member variables holding strings that can be used
t.
#include <iostream>
#include <string>
using namespace std;
class
DayOfYear{ private:
int day;
static string m[12];
public:
DayOfYear(int d){
if(d < 1 || d > 365){
}
else
day = d;
}
void print(){
for(int counter = 0; counter < 12;
break;
else{
day -= numOfDays[counter];
month++;
}
}
cout << m[month] << day;
}
};
string DayOfYear::m[12] = {"January ", "February ", "March ", "April ",
"May ", "June ", "July ", "August ",
int main()
{
int x;
return 0;
#include<iostream>
class
Celsius{ priv
ate:
float cel;
public:
Celsius(){
cout<<"Enter temperature in Celsius:"; cin>>cel;
Celsius(float
c){ cel = c;
float getCel(){
return cel;
};
class
Fahrenheit{
private:
float f;
public:
Fahrenheit(){f = 0;}
Fahrenheit(Celsius cel){
void show(){
cout << f;
};
int
main(){ Celsius
celsius;
Fahrenheit fahrenheit;
fahrenheit = Fahrenheit(celsius);
cout<<"Temperature in Fahrenheit:";
fahrenheit.show();
return 0;
}
.
#include<iostream>
#include<math.h>
using namespace std;
class polar
{
public:
float r,th;
polar(){}
polar(int a,int b)
{
r=a;
th=b;
}
void show()
{
cout<<"In polar form:\nr="<<r<<" and theta="<<th;
}
};
class rectangular
{
float x,y;
public:
rectangular(){}
rectangular(polar p)
{
x=p.r*cos(p.th);
y=p.r*sin(p.th);
}
void show()
{
cout<<"\nIn Rectangular form:\nx="<<x<<"and y="<<y;
}
};
int main()
{
polar p(5.5,3.2);
p.show();
rectangular r;
r=p;
r.show();
#include<iostream>
using namespace std;
class
LongDate{ private:
int yymmdd;
public:
LongDate(int
longdate){ yymmdd=longdate;
}
int
returnLongDate(){ retur
n yymmdd;
}
};
class Date{
private:
int year, month, day;
public:
Date(){}
Date(LongDate
value=ld.returnLongDate()/10000;
year= value;
year=year+2000;
value=ld.returnLongDate()%10000;
value=value/100; month=value;
day=ld.returnLongDate()%100;
}
void showDate(){
cout<<"The date in format is: "<< year<<" /" << month<<"/"<<day;
}
};
int main()
{
LongDate ld(151115);
Date d;
d=ld;
d.showDate();
return 0;
8.
rs.
s’
#include <iostream>
#include <string>
using namespace std;
class
NumDays{ private:
double hours;
double days;
public:
NumDays(double h =
0){ hours = h;
days = h/(8.00);
}
double
getHours(){ ret
urn hours;
}
double getDays(){
return days;
}
void setHours(double
h){ hours = h;
days = h/(8.00);
}
void setDays(double
d){ days = d;
hours = d*(8.00);
}
}
return hours-right.hours;
}
NumDays operator++(){
++hours;
days = hours/(8.00);
return *this;
}
NumDays
operator++(int){ hours
++;
days = hours/(8.00);
return *this;
}
NumDays operator--(){
--hours;
days = hours/(8.00);
return *this;
NumDays operator--
(int){ hours--;
days = hours/(8.00);
return *this;
}
};
int main()
{
cout << obj1.getHours() << " hours = " <<obj1.getDays() << " days.\n";
cout << obj2.getHours() << " hours = " <<obj2.getDays() << " days.\n";
cout << endl << "Adding hours... " << obj1 + obj2 << " hours.\n";
cout << endl << "Subtracting hours... " << obj2 - obj1 << "
hours.\n\n";
obj1++;
cout << obj1.getHours() << " hours = " <<obj1.getDays() << " days.\n";
obj2--;
cout << obj2.getHours() << " hours = " <<obj2.getDays() << " days.\n";
return 0;