当前位置:网站首页>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;
}
}
边栏推荐
- Centos7 installing MySQL and configuring InnoDB_ ruby
- The first batch of job hunting after 00: don't misread their "different"
- [binary tree] 993 Cousins in Binary Tree
- Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
- P1347 sorting (TOPO)
- Software development in 2022: five realities CIOs should know
- Common events for elements
- Full analysis of embedded software testing tool tpt18 update
- 虫子 STM32 中断 (懂的都懂)
- AI 视频云 VS 窄带高清,谁是视频时代的宠儿
猜你喜欢

Google Earth engine (GEE) - long time series monthly VCI data extraction, analysis and area calculation (Mexico as an example)

Avltree - arbre de recherche binaire équilibré

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

Compilation, installation and global configuration section description of haproxy

It supports running in kubernetes, adds multiple connectors, and seatunnel version 2.1.2 is officially released!

会话和守护进程

Analysis on the current situation of the Internet of things in 2022

2022年的软件开发:首席信息官应该知道的五个现实

Efficient remote office experience | community essay solicitation

mysql如何删除表的一行数据
随机推荐
8 key indicators to measure technology debt in 2022
电商如何借助小程序发力
【一起上水硕系列】Day Three - preview4
Pytoch --- use pytoch's pre training model to realize four weather classification problems
基于FPGA的VGA协议实现
[two points] leetcode1011 Capacity To Ship Packages Within D Days
Review the SQL row column conversion, and the performance has been improved
AI video cloud: a good wife in the era of we media
12 excellent practices of wireless network security
Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
Pyspark, paid for data cleaning and uploading to the database
Prince language on insect date class
After Huawei online battle service players quickly match, different players receive different lists of players in the same room
IDEA-导入模块
[tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
PTA:7-86 集合的模拟实现(函数模板)
Why APP But Not WebPage
怎么使用Shell脚本实现监测文件变化
Software development in 2022: five realities CIOs should know
什么是元数据