标签:const string double void a1 Complex 实验报告
#include<iostream> #include<math.h> using namespace std; class Complex { private: double a,b; public: Complex(); Complex(double a1); Complex(double a1,double b1); Complex(const Complex &p);//复制构造函数 double get_real() const{ return a;} double get_imag() const{ return b;} void show()const; void add(Complex &q); friend Complex add(const Complex &c1,const Complex &c2); friend bool is_equal(const Complex &c1,const Complex &c2); friend double abs(const Complex &q); }; Complex::Complex():a(0),b(0){ } Complex::Complex(double a1) { a=a1; b=0; } Complex::Complex(double a1,double b1) { a=a1; b=b1; } Complex::Complex(const Complex &p) { a=p.a; b=p.b; } void Complex::add(Complex &q) { a=a+q.a; b=b+q.b; } void Complex::show() const { double x,y; x=get_real(); y=get_imag(); if(x==0&&y==0) cout<<x; else if(x==0&&y!=0) cout<<y<<"i"; else if(y==0&&x!=0) cout<<x<<endl; else if(x!=0&&y<0) cout<<x<<y<<"i"; else if(x!=0&&y>0) cout<<x<<"+"<<y<<"i"; } Complex add(const Complex &c1,const Complex &c2) { Complex c3; c3.a= c1.a+c2.a; c3.b=c1.b+c2.b; return c3; } bool is_equal(const Complex &c1, const Complex &c2) { if(c1.a==c2.a&&c1.b==c2.b) return true; else return false; } double abs(const Complex &p) { double c3; c3=sqrt(p.a*p.a+p.b*p.b); return c3; }
#include <iostream> #include <string> using namespace std; class User { private: string name; string password; string email; static int n; public: User(string name1); User(string nameq, string password1, string email1); ~User() = default; void set_email() ; void change_passwd() ; void print_info() ; static void print_n() { cout << "there are " << n << " users." << endl; } }; void User::set_email() { string h; cout << "Enter email address: "; cin >> h; email = h; cout << "email is set successfully" << endl; } void User::change_passwd() { string passwd1,passwd2; int t,i; cout<<"Enter old password:"; t=0; for(i=1;i<=3;i++) { cin>>passwd1; if(passwd1==password) { cout << "Enter new password: "; cin>>passwd1; cout << "new password is set successfully..." << endl; break; } else { t++; if(t==3) { cout << "password input error.Please try after a while." << endl; break; } else cout << "password input error. Please re-enter again: "; } } } void User::print_info() { cout << "name: " << name << endl; cout << "password: ******" << endl; cout << "email: " << email << endl; } 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++; }
标签:const,string,double,void,a1,Complex,实验报告 来源: https://www.cnblogs.com/wyr-jssql/p/15463672.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。