OOPp (Bài 2)(số phức) constructor desstructor getter-setter bài tậ

// file.h// #pragma once #include<iostream> using namespace std; class So_Phuc { private: int phan_thuc,phan_ao; public: // khởi tạo mặc định So_Phuc(void); So_Phuc(int ); So_Phuc(int ,int );// khởi tạo 2 tham so ~So_Phuc(void);// phá hủy void Xuat(); }; //file.cpp// #include "So_Phuc.h" // hàm khởi So_Phuc::So_Phuc(void) { phan_thuc=0; phan_ao=0; } So_Phuc::So_Phuc(int a,int b) { phan_thuc=a; phan_ao=b; } So_Phuc::So_Phuc(int a) { phan_thuc=a; phan_ao=0; } void So_Phuc::Xuat() { cout<<phan_thuc<<"+"<<phan_ao; cout<<endl; } So_Phuc::~So_Phuc(void) { } /// file main #include"So_Phuc.h" int main() { So_Phuc a; a.Xuat(); So_Phuc b(2); b.Xuat(); So_Phuc c(3,4); c.Xuat(); So_Phuc d(c); d.Xuat(); So_Phuc e(-5,6); e.Xuat(); So_Phuc f(-7); f.Xuat(); system("pause"); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.