Mô tả:
>) + Toán tử xuất (<<) SOLUTION 2: #include #include class complex { private: float real,image; public: complex(float r=0,float i=0); complex operator+(complex c); complex operator-(complex c); friend complex operator+(float x,complex c); friend ostream& operator<<(ostream &out,complex c); friend istream& operator>>(istream &inp,complex& c); }; complex::complex(float r,float i) { real=r; image=i; } complex complex::operator+(complex c) { complex temp; temp.real=real+c.real; temp.image=image+c.image; return temp; } complex complex::operator-(complex c) { } complex temp; temp.real=real-c.real; temp.image=image-c.image; return temp; complex operator+(float x, complex c) { complex temp; temp.real=c.real+x; temp.image=c.image; return temp; } ostream& operator<<(ostream &out,complex c) { cout<>(istream &inp,complex &c) { cout<<" Nhap vao phan thuc:"; cin>>c.real; cout<<" Nhap vao phan ao:"; cin>>c.image; return inp; } void main() { complex c,c1,c2,c3; float x; cin>>c; cin>>c1; c2=c+c1; cout<<" Cong hai so phuc :"<>x; c3=c3+x; cout<< c3; getch(); } ------------------------------------------------------------------------- PROGRAM 3: Xây dựng lớp xaukytu có các thành phần sau : - Các thuộc tính : char * str, int length - Hàm tạo không tham số - Hàm tạo một tham số ( char * s) - Hàm hiển thị xâu và độ dài xâu Hàm nối xâu để cộng hai xâu (xaukytu Hàm huỷ . Viết chương trình kiểm tra SOLUTION 3: File xaukytu.h #ifndef xaukytu_h #define xaukytu_h class xaukytu { private: int length; char * str; public: xaukytu(char * s); xaukytu(); void htxau(); xaukytu noixau(xaukytu s1); ~xaukytu(); }; #endif File xaukytu.cpp #include #include "xaukytu.h" #include #include xaukytu::xaukytu() { str=" "; length=0; cout<<" xau rong"< #include class vector { private: int n; float *v; public: vector();//ham thiet lap khong tham so vector(int size);//ham thiet lap mot tham so vector(int size,float * a);//ham thiet lap hai tham so void display(); ~vector();//ham huy }; vector::vector() { cout<<" Su dung ham thiet lap khong tham so :"<>n; v=new float[n]; cout<<" Xin cap phat mot vung bo nho cho "<>v[i]; } } vector::vector(int size) { cout<<" Su dung ham thiet lap mot tham so :"<>v[i]; } } vector::vector(int size,float * a) { cout<<" Su dung ham thiet lap hai tham so :"< #include #include class tamgiac { private: int a,b,c; float dientich(); int kttamgiac(); public: void nhap(); void in(); }; void tamgiac::nhap() { do { cout<<"Nhap canh a:";cin>>a; cout<<"Nhap canh b:";cin>>b; cout<<"Nhap canh c:";cin>>c; }while(a+b23), phút(0->59), giây(0>59); Hàm thành phần setTime(int,int,int) để xác lập thời gian Hàm hiển thị giờ theo định dạng 24 tiếng (vd : 23:54:40); Hàm hiển thị giờ theo định dạng 12 tiếng( vd : 11:54:40 PM); Hàm tăngGiây()để tăng thời gian mỗi lần lên một giây. Chú ý các trường hợp tăng sang phút tiếp theo, tăng sang giờ tiếp theo,tăng sang ngày tiếp theo. Viết chương trình chính khai báo một đối tượng thời gian là 23:59:58 và thực hiện tăng thời gian 5 giây đồng thời hiển thị thời gian cho mỗi lần tăng. SOLUTION 6: #include #include class time { private: int hour; int minute; int second; void incHour(); void incMinute(); public: void setTime(int,int=0,int=0); void setHour(int); void setMinute(int); void setSecond(int); void print12h(); void print24h(); void incSecond(); }; void time::incHour() { hour++; if(hour==24) hour=0; } void time::incMinute() { minute++; if(minute==60) { minute=0; incHour(); } } void time::incSecond() { second++; if(second==60) {