#include<iostream> #include<cmath> using namespace std; class Complex { public: Complex(double a=0,double b=0):real{a},imag{b}{}; Complex(const Complex&c1); ~Complex()=default; double get_real()const {return real;} double get_imag()const {return imag;} void show()const; void add(Complex const &c1); friend Complex add(Complex const&c1,Complex const&c2); friend bool is_equal(Complex const&c1,Complex const&c2); friend double abs(Complex const&c1); private: double real; double imag; }; Complex::Complex(const Complex &c1) { real=c1.real; imag=c1.imag; } void Complex::show()const { if(imag==0) cout<<real; else if(imag<0) cout<<real<<"-"<<abs(imag)<<"i"; else cout<<real<<"+"<<imag<<"i"; } void Complex::add(Complex const&c1) { real+=c1.real; imag+=c1.imag; } Complex add(Complex const&c1,Complex const&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; return false; } double abs(Complex const&c1) { return sqrt(c1.real*c1.real+c1.imag*c1.imag); }
#include<iostream> #include<string> using namespace std; class User{ public: User (string Name, string Passwd = "111111", string Email = "") : name{Name} , passwd{Passwd}, email{Email} {n ++; } void set_email(){ cout << ("Enter email address: "); cin >> email; puts("email is set successfully..."); } void change_passwd(){ string Passwd; cout << ("Enter old password: "); cin >> Passwd; for(int wrong = 1; wrong <= 2 && Passwd != passwd; wrong ++){ cout <<("password input error. Please re-enter again: "); cin >> Passwd; } if(Passwd == passwd){ cout << "Enter new passwd: "; cin >> passwd; puts("new passwd is set successfully..."); } else puts("password input error. Please try after a while."); } void print_info(){ cout << "name: " << name << "\n"; cout <<"passwd: "; for(int i = 0; passwd[i]; i ++) cout << "*"; cout << "\n"; cout << "email: " << email << "\n"; } static void print_n(){ cout << "there are " << n << " users.\n"; } private: string name, passwd, email; static int n; }; int User::n = 0;
标签:const,double,imag,Complex,实验,c1,void From: https://www.cnblogs.com/wuyihaonb/p/16789738.html