首页 > 其他分享 >实验二

实验二

时间:2022-10-13 21:23:13浏览次数:42  
标签:const double imag Complex 实验 c1 void

#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

相关文章

  • 实验二
    实验任务四    main.cpp#include"Complex.hpp"#include<iostream>usingstd::cout;usingstd::endl;voidtest(){ usingnamespacestd;Complexc1(......
  • 实验5:开源控制器实践——POX
    h1pingh2截图h2和h3的tcpdump抓包结果截图L2_learning模块代码流程图......
  • 实验4:开源控制器实践——OpenDaylight
    一、实验目的能够独立完成OpenDaylight控制器的安装配置;能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环境Ubuntu20.04Desktopamd64三、实验......
  • 实验4:开源控制器实践——OpenDaylight
    实验4:开源控制器实践——OpenDaylight一、实验目的能够独立完成OpenDaylight控制器的安装配置;能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环境......
  • 实验4:开源控制器实践——OpenDaylight
    实验4:开源控制器实践——OpenDaylight一、实验目的能够独立完成OpenDaylight控制器的安装配置;能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环境......
  • 实验二
    任务四Complex.hpp#include<iostream>#include<cmath>usingnamespacestd;classComplex{public:Complex(doublea=0.0,doubleb=0.0):real{a},imag{......
  • 数码管显示程序~实验板上的数码管从左到右逐个显示“0”、“1”、“2”、“3”
    1DAT_74164BITP0.6;头文件:74ALS164芯片的数据输入端接单片机引脚的p062CLK_74164BITP0.7;74LS164芯片的时钟端接单片机引脚......
  • 实验二
    实验4hpp#pragmaonce#include<iostream>usingnamespacestd;classComplex{public:Complex();Complex(doublereal0,doubleimag0=0);Complex......
  • 实验二
    Complex.hpp#include<iostream>#include<cmath>usingnamespacestd;classComplex{public:Complex(doublea=0,doubleb=0):real{a},imag{b}{};......
  • 实验5:开源控制器实践——POX
    建立拓扑hub验证h1pingh2都能收到h1pingh3都能收到switch验证h1pingh2仅h2收到h1pingh3仅h3收到流程图进阶重新建立拓扑,无流表,编写POX模块Send......