cau 1: so phuc
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<iostream.h>
struct sp
{double a;
double b;
};
sp operator+(sp q, sp p)
{ sp u;
u.a=q.a+p.a;
u.b=q.b+p.b;
return u;}
sp operator-(sp q, sp p)
{ sp k;
k.a=q.a-p.a;
k.b=q.b-p.b;
return k;}
main()
{sp j,q,h,m;
cout<<"nhap phan thuc cua j";
cin >>j.a;
cout <<"nhap phan ao cua j";
cin >>j.b;
cout <<" nham phan thuc cua q";
cin >>q.a;
cout<<"nhap phan ao cua q";
cin>>q.b;
h=j+q;
m=j-q;
cout<<"tong hai so phuc";
cout<<h.a<<"+"<<h.b<<"i";
cout<<"hieu hai so phuc";
cout<<m.a<<"+"<<m.b<<"i";
}
cau 2 lop diem
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
class diem
{private:
int x;
int y;
public:
void nhap()
{cout<<"nhap toa do diem";
cin>>x>>y;
}
void hien()
{cout<<"toa d diem:";
cout<<x<<y;
}
void thaydoi();
void tungdo()
{cout<<"tung do la:"<<y;}
void hoanhdo()
{cout<<"hoanh do la:"<<x;}
void tinhtien(int delx,int dely)
{x=x+delx;
y=y+dely;
}
};
void diem::thaydoi()
{cout<<"ban muon thay doi toa do";
cout<<"hoanh do x:";cin>>x;
cout<<"tung do y:"; cin>>y;
}
void main()
{diem d;
int k,j;
d.nhap();
d.hien();
d.tungdo();
d.hoanhdo();
cout<<endl<<"Cho gia tri tinh tien theo truc x:";
cin>>k;
cout<<"Cho gia tri tinh tien theo y:";
cin>>j;
d.tinhtien(k,j);
d.hien();
}
cau 2: tam giac
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
class diem
{public:
int x;
int y;
public:
void nhap()
{cout<<"nhap toa do diem";
cin>>x>>y;
}
void hien()
{cout<<"toa d diem:";
cout<<x<<y;
}};
class tamgiac
{private:
diem a,b,c;
public:
void nhaptg()
{cout<<"dinh1";
a.nhap();
cout<<"/n dinh2";
b.nhap();
cout<<"/n dinh3";
c.nhap();
}
void hientg()
{cout<<"dinh";
a.hien();
cout<<" dinh 2";
b.hien();
cout<<"dinh3";
c.hien();
}
void tinhtientheoX()
{int l;
cout<<"ban muon tinh tien bao nhieu theo x";
cin>>l;
a.x=a.x+l;
b.x=b.x+l;
c.x=c.x+l;
cout<<"tam giac moi tinh tien theo x:";
a.hien();
b.hien();
c.hien();
}
void tinhtientheoY()
{int o;
cout<<"ban muon tinh tien bao nhieu theo y";
cin>>o;
a.y=a.y+o;
b.y=b.y+o;
c.y=c.y+o;
cout<<"tam giac moi tinh tien theo y:";
a.hien();
b.hien();
c.hien();
}
};
void main()
{tamgiac a;
a.nhaptg();
a.tinhtientheoX();
a.tinhtientheoY();
a.hientg();}
cau 4 thoiggian
#include<conio.h>
#include<stdio.h>
#include<iostream>
class tg
{private:
int h,p,s;
public:
void nhap()
{cout<<"nhap gio phut giay:";
cin>>h>>p>>s;
}
void hien()
{cout<<"so gio phut giay:";
cout<<h<<":"<<p<<":"<<s;}
tg operator+(tg b)
{tg c;
c.h=h+b.h;
c.p=p+b.p;
c.s=s+b.s;
int t1,t2,t3,t4;
t1=c.s/60;
t2=c.s%60;
c.p=c.p+t1;
c.s=t2;
t3=c.p/60;
t4=c.p%60;
c.p=t4;
c.h=c.h+t3;
return c;
}};
void main()
{tg e,d,f,k;
e.nhap();
d.nhap();
f=e+d;
cout<<"tong gio da cong:";
f.hien();
}