Huazhong University of Science and Technology SPOC Programming Questions Chapter 3

1 Calculate the piecewise function (10 points)
topic content:

There is a function as shown:

Write a program, input the value of x, calculate the corresponding output of the y value (with 2 decimal places).

Input format:

Enter the value of variable x

Output format:

Output the calculated result y, and keep 2 decimal places

Input sample:

3

Sample output:

y = 2.00

Time limit: 500ms Memory limit: 32000kb

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
    
    
double x,y;
cin>>x;
if(x<4) y=(x+7)/(2*x-1);
else if(x>=4&&x<70) y=3*x*x+5;
else y=x-sqrt(4*x-1);
cout<<"y="<<setiosflags(ios::fixed)<<setprecision(2)<<y<<endl;
return 0;

}

2 Determine the triangle and calculate the area (10 points)
Question content:

Write a program to judge whether a triangle can be formed according to the three sides of the input triangle. If it can form a triangle, output its area and triangle type (equilateral, isosceles, right angle, isosceles right angle, general triangle, not forming triangle).

When outputting the triangle type, copy the above text directly, do not output any other extra characters. The output area value retains 2 decimal places.

Input format:

Enter the three sides of the triangle, enter a number and end with a carriage return.

Output format:

First output the area of ​​the triangle, then wrap the line and then output the triangle type. The triangle type is one of equilateral, isosceles, right angle, isosceles right angle, general triangle, and non-formed triangle.

Input sample:

3

4

5

Sample output:

area=6.00

Right triangle

Time limit: 500ms Memory limit: 32000kb

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
    
    double p,a,c,b;
cin>>a>>b>>c;
p=(a+b+c)/2;
if(p>a&&p>b&&p>c)
{
    
    cout<<"area="<<setiosflags(ios::fixed)<<setprecision(2)<<sqrt(p*(p-a)*(p-b)*(p-c))<<endl;
if(a==b&&a==c)
cout<<"等边三角形"<<endl;
else if((a==b||b==c||a==c)&&(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b))
cout<<"等腰直角三角形"<<endl;
else if(a==b||b==c||a==c)
cout<<"等腰三角形"<<endl;
else if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b)
cout<<"直角三角形"<<endl;
else cout<<"一般三角形"<<endl;
}
else cout<<"不构成三角形"<<endl;


}

3Calculate the actual bonus value (10 points)
topic content:

Set bonus tax rate r, n represents bonus):

Enter the bonus value from the keyboard, calculate and output the corresponding tax rate and actual bonus value.

The calculation method of tax payable is that if the bonus is less than 1000, no tax is paid, r is 0, if it is greater than or equal to 1000 but less than 3000, it is taxed at 3%, if it is greater than or equal to 3000 but less than 5000, it is taxed at 5%, if it is greater than or equal to 5000 but less than 10000 is taxed at 7%, if it is greater than or equal to 10000, it is taxed at 10%. Both the bonus value and the actual bonus earned are kept at 2 decimal places during output.

Input format:

Enter bonus value

Output format:

Output the tax rate, bonus value, and actual bonus value in one line, separated by English commas, and be careful not to have extra spaces.

Keep 2 decimal places when outputting. (The comma between the two numbers is the English comma)

Input sample:

3000

Sample output:

Tax rate r=5%, bonus value n=3000.00, actual bonus s=2850.00

Time limit: 500ms Memory limit: 32000kb

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
    
    double r,n;
cin>>n;
if(n<1000)
r=0;
else if(n<3000)
r=0.03;
else if(n<5000)
r=0.05;
else if(n<10000)
r=0.07;
else r=0.10;
cout<<"税率r="<<100*r<<"%"<<",奖金值n="<<setiosflags(ios::fixed)<<setprecision(2)<<n<<",实际所得奖金s="<<setiosflags(ios::fixed)<<setprecision(2)<<n-n*r<<endl;


}

Guess you like

Origin blog.csdn.net/weixin_51236357/article/details/112075063