实验一

#ifndef COMPLEX_HPP
#define COMPLEX_HPP
#include <iostream>
#include <math.h>
class Complex{
public:
Complex():real(0.0),imag(0.0){}
Complex(int r,int i):real(r),imag(i){}
Complex(double r,double i):real(r),imag(i){}
Complex(int r):real(r),imag(0.0){}
Complex(double r):real(r),imag(0.0){}
Complex(const Complex &c):real(c.real),imag(c.imag){}
~Complex(){};
double get_real() const{return real;}
double get_imag() const{return imag;}
friend Complex add(const Complex &c1,const Complex &c2);
void show() const;
void add(const Complex &c);
friend bool is_equal(const Complex &c1,const Complex &c2);
friend double abs(const Complex &c);
private:
double real;
double imag;
};
void Complex::add(const Complex &c){
real+=c.real;
imag+=c.imag;
}
void Complex::show() const{
if(imag>0) std::cout<<real<<'+'<<imag<<'i';
else if(imag<0) std::cout<<real<<imag<<'i';
else if(real==0) std::cout<<imag<<'i';
else std::cout<<real;
}
bool is_equal(const Complex &c1,const Complex &c2){
if (c1.imag==c2.imag)
return true;
else
return false;
}

Complex add(const Complex &c1,const Complex &c2){
Complex c;
c.imag=c1.imag+c2.imag;
c.real=c1.real+c2.real;
return c;
}

double abs(const Complex &c){
return sqrt(c.imag*c.imag+c.real*c.real);
}

#endif

 

 

 

 

 

 

 

 

 

 

#ifndef USER_HPP
#define USER_HPP
#include<iostream>
#include<string>
using namespace std;
class User{
public:
User(string n):name(n),password("111111"){num++;}
User(string n,string p,string e):name(n),password(p),email(e){num++;}
~User(){};
void set_email();
void change_passwd ();
void print_info();
static void print_n();

private:
string name;
string password;
string email;
static int num;
};
int User::num=0;
void User::set_email(){
string o;
cout<<"Enter email:";
cin>>o;
email=o;
cout<<"success"<<endl;
}
void User::change_passwd (){
string o;
int k=0;
cout<<"Enter old password:";
cin>>o;
while(k!=2){
if(o==password){
cout<<"Enter new password:";
cin>>password;
break;
}
else {
cout<<"password input error. please re-enter again:";
cin>>o;
}
k++;
}
cout<<"please try after a while!!"<<endl;
}
void User::print_info(){
cout<<"name:\t"<<name<<endl;
cout<<"passwd:\t"<<"******"<<endl;
cout<<"email:\t"<<email<<endl;
}
void User::print_n(){
cout<<"there are "<<num<<" users."<<endl;
}

#endif

 

posted @ 2021-10-26 18:57  yxg208  阅读(42)  评论(3)    收藏  举报