alirezadot
کاربر تازه وارد
من دوتا برنامه دارم توی visual c++ که اررور میدن میخواستم خواهش کنم اگه کسی میدونه مشکل چیه کمک کنه لطفا
کد:
#include <iostream.h>
#include <iomanip.h>
class time
{
friend time operator-(const time t1,const time t2);
friend time operator+(const time t1,const time t2);
public:
time(int h, int m, int s);
void setTime(int ,int ,int);
const int geth();
const int getm();
const int gets();
void advance(int h, int m, int s);
void reset();
int operator>(const time);
int operator<(const time);
int operator==(const time);
const void print();
private:
int hour,min,sec;
}
time::time(int h,int m, int s)
{setTime(h,m,s);}
void time::setTime(int h,int m,int s)
{
hour = ( h >= 0 && h<24)?h:0;
min = ( m>=0 && m <60)?m:0;
sec = ( s>=0 && s<60)?s:0;
}
const int time::geth(){return hour;}
const int time::getm(){return min;}
const int time::gets(){return sec;}
const void time::print()
{
cout <<"Hour is: "<<hour<<" Minute is: "<<min<<" Second is: "<<sec;
}
time operator+(const time t1,const time t2)
{
time temp(0,0,0);
temp.hour = t2.hour + t1.hour;
temp.min = t2.min + t1.min;
temp.sec = t2.sec + t1.sec;
if(temp.hour > 60)
temp.reset
if(temp.min>60)
temp.min -= 60;temp.hour++;
if(temp.sec>60)
temp.sec -= 60; temp.min++;
return temp;
}
time operator-(const time t1,const time t2)
{
time temp(0,0,0);
temp.hour = t2.hour - t1.hour;
temp.min = t2.min - t1.min;
temp.sec = t2.sec - t1.sec;
return temp;
}
int time::operator > (const time t)
{
int m,h,s,t1,t2;
h = hour * 1000;
m = min * 50;
s = sec * 1;
t1 = h+m+s;
h = t.hour * 1000;
m = t.min * 50;
s = t.sec * 1;
t2 = h+m+s;
if(t1>t2)
return 1;
else
return 0;
}
int time::operator < (const time t)
{
int m,h,s,t1,t2;
h = hour * 1000;
m = min * 50;
s = sec * 1;
t1 = h+m+s;
h = t.hour * 1000;
m = t.min * 50;
s = t.sec * 1;
t2 = h+m+s;
if(t1<t2)
return 1;
else
return 0;
}
int time::operator == (const time t)
{
if(hour==t.hour && min==t.min && sec==t.sec)
return 1;
else
return 0;
}
void time::advance(int h,int m,int s)
{
hour += h;
min += m;
sec += s;
}
void time::reset()
{
hour = 0;
min = 0;
sec = 0;
}
int main()
{
time t1(7,30,10),t2(2,20,15),temp(0,0,0);
cout << "Time T1 is: ";
t1.print();
cout << "Time T2 is: ";
t2.print();
temp = t;
temp.advance(1,10,15);
cout << "Time after advance function: ";
temp.print();
temp = t1 + t2;
cout << "Time after T1+T2 : ";
temp.print();
cout << "T1 == T2 (?) : " << (t1 == t2);
cout << "T1 > T2 (?) : " << (t1 >t2);
cout << "Time T1 after reset function : ";
t1.reset();
t1.print();
return 0;
}
کد:
#include <iostream.h>
#include <iomanip.h>
class point
{
public:
point(int x=0, int y=0, int z=0);
point(const point &);
void setpoint(int, int, int);
const int getx();
const int gety();
const int getz();
void negat();
const void print();
private:
int x,y,z;
}
point::point(int xVal, int yVal, int zVal) : x(xVal),y(yVal),z(zVal)
{}
point::point(const point &p)
{x=p.x;y=p.y;z=p.z;}
void point::setpoint(int xVal,int yVal,int zVal)
{
x=xVal;
y=yVal;
z=zVal;
}
const int point::getx()
{return x;}
const int point::gety()
{return y;}
const int point::getz()
{return z;}
void point::negat()
{
x=-x;
y=-y;
z=-z;
}
const void point::print()
{
cout <<'('<<x<<','<<y<<','<<z<<')';
}
int main()
{
point p1(8,9);
cout << "point 1 is: ";
p1.print();
p1.negat();
cout << "point 1 after negat() function";
p1.print();
return 0;
}