当前位置:网站首页>PTA: spacing of 7-69 data
PTA: spacing of 7-69 data
2022-06-23 04:26:00 【Sy_ Faker】
Plural Complex There are two data members :a and b, Represent the real part and imaginary part of a complex number respectively , There are several constructors and an overload -( minus sign , Used to calculate the distance between two complex numbers ) Member function of . It is required to design a function template
template < class T >
double dist(T a, T b)
Yes int,float,Complex Or other types of data , Returns the spacing between two data .
The above class name and function template form , Must be in accordance with the requirements of the topic , Do not modify
Input format :
Each action is an operation , The first number in each line is the element type ,1 Is an integer element ,2 Is a floating point element ,3 by Complex type , If integer element , Then enter two integer data , If it is a floating-point element , Then enter two floating-point data , if Complex Type element , Enter two Complex Type data (a1 b1 a2 b2), Input 0 Mark the end of input .
Output format :
For each input , Output one spacing value per line .
sample input :
1 2 5
3 2 4 5 9
2 2.2 9.9
0
sample output :
3
5.83095
7.7
#include<iostream>
#include<cmath>
using namespace std;
class Complex
{
int a;
int b;
public:
Complex()
{
a=0;
b=0;
}
Complex(int x,int y)
{
a=x;
b=y;
}
float operator -(Complex&c)
{
return (sqrt((a-c.a)*(a-c.a)+(b-c.b)*(b-c.b)));
}
};
template<class T>
double dist(T a,T b)
{
return fabs(a-b);
}
int main()
{
int type;
cin>>type;
int i1,i2;
float f1,f2;
int x1,x2,y1,y2;
while(type!=0)
{
switch(type)
{
case 1:
cin>>i1>>i2;
cout<<dist(i1,i2)<<endl;
break;
case 2:
cin>>f1>>f2;
cout<<dist(f1,f2)<<endl;
break;
case 3:
cin>>x1>>y1>>x2>>y2;
Complex c1(x1,y1),c2(x2,y2);
cout<<c1-c2<<endl;
break;
}
cin>>type;
}
}
边栏推荐
- Basic skills of x64dbg
- QMainWindow
- 虫子 STM32 中断 (懂的都懂)
- 电商如何借助小程序发力
- [tcapulusdb knowledge base] [list table] example code for replacing the data at the specified location in the list
- What if the self incrementing IDs of online MySQL are exhausted?
- Half search method
- IDEA-导入模块
- 【LeetCode】179. Maximum number
- What is the digital "true" twin? At last someone made it clear!
猜你喜欢

Efficient remote office experience | community essay solicitation

深度学习 TensorFlow入门

粒子动画背景登录页面particles.js

MySQL common instructions
![[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation](/img/eb/0d4caf0babbe14f51f4dbf1b9ae65d.png)
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation

The first batch of job hunting after 00: don't misread their "different"

mysql存储引擎之Myisam和Innodb的区别

深度学习 简介

Black horse PostgreSQL, why is it black in the end

QMainWindow
随机推荐
node+express如何操作cookie
A summary of PostgreSQL data types. All the people are here
Imitation 360 desktop suspended ball plug-in
How the innovative use of adobe international certification 𞓜 3D changes the entire industry
Twitter cooperates with Shopify to introduce merchant products into twitter shopping
背景彩带动画插件ribbon.js
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation
在线JSON转CSharp(C#)Class工具
[two points] leetcode1011 Capacity To Ship Packages Within D Days
如何保证应用程序的安全性
怎么用好MySQL索引
Twitter与Shopify合作 将商家产品引入Twitter购物当中
Software development in 2022: five realities CIOs should know
AI 视频云 VS 窄带高清,谁是视频时代的宠儿
顺序表查找
Redis启动有问题
x64dbg 基本使用技巧
MySQL optimization, the SQL execution is very stuck, and the SQL structure will not be changed until it ends in 10 seconds
1-1 introduction to VMWare
mysql如何删除表的一行数据