面向对象的程序设计第五次作业
#include <bits/stdc++.h>
using namespace std;
struct Point
{
int x;
int y;
};
void displayMenu() {
for (int i = 0; i < 32; ++i)
cout << "*";
cout << endl;
cout << " 1.Circle(圆)" << endl;
cout << " 2.Rectangle(长方形)" << endl;
cout << " 0.Exit(退出)" << endl;
for (int i = 0; i < 32; ++i)
cout << "*";
cout << endl;
cout << "Please select the shape:";
}
void getTwoPoints(struct Point * P1, struct Point * P2) {
}
void printPoint(struct Point *) {
}
void drawCircle(struct Point * P1, struct Point * P2) {
if (P2 -> x - P1 -> x == P2 -> y - P1 -> y) {
cout << "Draw a circle at center (" << (P1 -> x + P2 -> x) / 2 << "," << (P2 -> y + P1 -> y) / 2 << ")" << "with radius " << (P2 -> x - P1 -> x) / 2 << endl;
}
else {
cout << "Not a circle, select again" << endl;
}
}
void drawRectangle(struct Point * P1, struct Point * P2) {
cout << "Draw a rectangle at toleft(" << P1 -> x << "," << P1 -> y << "), whose width is " << P2 -> x - P1 -> x << " and height is " << P2 -> y - P1 -> y << endl;
}
int main () {
int choice;
struct Point startP, endP;
while (choice) {
displayMenu();
cin >> choice;
switch (choice) {
case 1:
cout << "Please input the coordinate(x,y)of the start point:";
cin >> startP.x >> startP.y;
cout << "Please input the coordinate(x,y)of the end point:";
cin >> endP.x >> endP.y;
if (endP.x <= startP.x || endP.y <= startP.y){
cout << "输入点的坐标存在问题,请重新输入!" << endl;
break;
}
//getTwoPoints(&startP, &endP);
drawCircle(&startP, &endP);
break;
case 2:
cout << "Please input the coordinate(x,y)of the start point:";
cin >> startP.x >> startP.y;
cout << "Please input the coordinate(x,y)of the end point:";
cin >> endP.x >> endP.y;
if (endP.x <= startP.x || endP.y <= startP.y){
cout << "输入点的坐标存在问题,请重新输入!" << endl;
break;
}
//getTwoPoints(&startP, &endP);
drawRectangle(&startP, &endP);
break;
case 0:
cout << "Good Bye!\n";
break;
default:
cout << "Not supported! Please select again!\n";
break;
}
}
return 0;
}
/*
1
5 20
15 30
1
5 20
15 25
2
3 10
20 30
3
0
*/
#include <bits/stdc++.h>
using namespace std;
struct Rule
{
double money;
double rate;
};
void showMenu() {
cout << "请输入规则的条数:" << endl;;
}
double computeTax(struct Rule rules[], int n, double income) {
double ans = 0;
for (int i = n; i >= 1; i--) {
if (income > rules[i].money) {
ans += (income - rules[i].money) * rules[i].rate / 100;
while (i - 1) {
ans += (rules[i].money - rules[i - 1].money) * rules[i - 1].rate / 100;
i--;
}
break;
}
}
return ans;
}
int main () {
showMenu();
int N = 0;
cin >> N;
struct Rule rule[10];
for (int i = 1; i <= N; ++i) {
cout << "请输入第" << i << "条规则:";
cin >> rule[i].money >> rule[i].rate;
}
double income;
cout << "请输入您的收入:";
cin >> income;
while (income != -1) {
cout << "您的收入是:" << income << ",";
cout << "应缴所得税:" << fixed << setprecision(2) << computeTax(rule, N, income) << "元。";
cout << endl;
cout << "请输入您的收入:";
cin >> income;
}
cout << "再见" << endl;
}
3
800 3
2000 4
5000 3
0
800
801
2000
1999
5000
10000
-1
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
更多精彩

