实验任务三
#include<iostream>
#include<math.h>
using namespace std;
class Complex {
public:
    Complex(double x = 0, double y = 0) :real(x), imag(y) {};
    Complex(Complex const& c) :real(c.real), imag(c.imag) {};
    double get_real() const { return real; };
    double get_imag() const { return imag; };
    void show()const;
    void add(Complex const &c1) {
        Complex c;
        c.real = real + c1.real;
        c.imag = imag + c1.imag;
        real = c.real;
        imag = c.imag;
    };
    friend Complex add(Complex c1, Complex c2);
    friend bool is_equal(Complex const c1, Complex const c2);
    friend double abs(Complex c);
private:
    double real;
    double imag;
};
void Complex::show()const {
    {
        if (imag == 0)
            cout << real;
        else if (imag >= 0)
            cout << real << "+" << imag << 'i';
        else
            cout << real << imag << "i";
    };
}
Complex add(Complex c1, Complex c2) {
    Complex c3;
    c3.real = c1.real + c2.real;
    c3.imag = c1.imag + c2.imag;
    return c3;
};
bool is_equal(Complex const c1, Complex const c2) {
    if (c1.real == c2.real && c1.imag == c2.imag)
        return true;
    else return false;
};
double abs(Complex c) {
    return sqrt(c.real * c.real + c.imag * c.imag);
};


 

 






实验任务四
#include<iostream> #include<string> using namespace std; class User { public: User(string name1); User(string name1,string password1,string email1); void set_email(); void change_passwd(); void print_info(); static void print_n(); private: string name,password,email; static int n; }; int User::n=0; User::User(string name1) { name=name1; password="111111"; email=""; n++; } User::User(string name1,string password1,string email1) { name=name1; password=password1; email=email1; n++; } void User::set_email() { string t; cout<<"Enter email address:"; cin>>t; email=t; cout<<"email is set successfully···"<<endl; } void User::change_passwd() { string t0,t1; cout<<"Enter old password:"; for(int i=1;i<=3;i++) { cin>>t0; if(t0==password) { cout<<"Enter new password:"; cin>>t1; password=t1; break; } else if(i<=2) { cout<<"password input error. Please re-enter again:"; } else cout<<"password input error. Please try after a while."<<endl; } } void User::print_info() { cout<<"name:"<<name<<endl; cout<<"passwd:"<<"******"<<endl; cout<<"email:"<<email<<endl; } void User::print_n() { if(n==1) cout<<"there are "<<n<<" user."<<endl; else cout<<"there are "<<n<<" users."<<endl; }