#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
using namespace std;
int choose;
void shouMenu()
{
cout << "***************************************" << endl;
cout << "完成人:林承 学号:" << endl;
cout << "1字母数字转换" << endl;
cout << "奖金发放" << endl;
cout << "打印月历" << endl;
cout << "打印素数" << endl;
cout << "数据排序" << endl;
cout << "退出" << endl;
cout << "***************************************" << endl;
}
void clearScreen()
{
system("pause");
system("cls");
}
//字母数字转换
void charTele()
{
cout << "请输入电话号码:" << endl;
string phoneNumber;
cin >> phoneNumber;
for (int i = 0;i < phoneNumber.size();i++)
{
char c = phoneNumber[i];
if (c == 'A' || c == 'B' || c == 'C')
{
cout << 2;
}
else if (c == 'D' || c == 'E' || c == 'F')
{
cout << 3;
}
else if (c == 'G' || c == 'H' || c == 'I')
{
cout << 4;
}
else if (c == 'J' || c == 'K' || c == 'L')
{
cout << 5;
}
else if (c == 'M' || c == 'N' || c == 'O')
{
cout << 6;
}
else if (c == 'P' || c == 'Q' || c == 'R' || c == 'S')
{
cout << 7;
}
else if (c == 'T' || c == 'U' || c == 'V' )
{
cout << 8;
}
else if (c == 'W' || c == 'X' || c == 'Y' || c == 'Z')
{
cout << 9;
}
else
{
cout << c;
}
}
}
//奖金发放
void bounsGrant()
{
cout << "请输入本月利润:" << endl;
int profit;
cin >> profit;
double bouns;
if (profit <= 1e5)
{
bouns = profit * 0.1;
}
else if (profit < 2e5)
{
bouns = 1e5 * 0.1 + (profit - 1e5) * 0.075;
}
else if (profit < 4e5)
{
bouns = 1e5 * 0.1 + 1e5 * 0.075 + (profit - 2e5) * 0.05;
}
else
{
bouns = 1e5 * 0.1 + 1e5 * 0.075 + 2e5 * 0.05 + (profit - 4e5) * 0.03;
}
cout << "本月发放奖金:" << bouns << endl;
}
//打印月历
void printMonth()
{
int days;
int week;
cout << "请输入这个月的天数:" << endl;
cin >> days;
cout << "请输入这个月第一天的星期天数" << endl;
cin >> week;
for (int i = 1;i <= 7;i++)
{
switch (i)
{case 1:
cout <<setw(7) << "星期" << "一";
break;
case 2:
cout << setw(7) << "星期" << "二";
break;
case 3:
cout << setw(7) << "星期" << "三";
break;
case 4:
cout << setw(7) << "星期" << "四";
break;
case 5:
cout << setw(7) << "星期" << "五";
break;
case 6:
cout << setw(7) << "星期" << "六";
break;
case 7:
cout << setw(7) << "星期" << "日";
break;
default:
break;
}
}
cout << endl;
bool flag = 0;
int start = 1;
int count1 = 0;
int count2 = 1;
while (start <= days)
{
if (flag == 0&&count2==week)
{
flag = 1;
}
if (flag == 0)
{
count2++;
cout << setw(9)<<' ';
}
count1++;
if (flag == 1)
{
cout << setw(9) << start;
start++;
}
if (count1 == 7)
{
cout << endl;
count1 = 0;
}
}
}
//打印素数
int isPrime()
{
cout << "请输入一个数字:" << endl;
int x;
cin >> x;
if (x == 1)return 0;
if (x == 2)return 1;
for (int i = 2;i * i <= x;i++)
{
if (x % i == 0)return 0;
}
return 1;
}
//整数排序
void sortInt()
{
int n;
cout << "请输入n的值:" << endl;
cin >> n;
vector<int>v;
for (int i = 1;i <= n;i++)
{
cout << "请输入第" << i << "个数:" << endl;
int x;
cin >> x;
v.push_back(x);
}
cout << "排序前的数组为:" << endl;
for (int i = 0;i < v.size();i++)
{
cout << v[i] << " ";
}
cout << endl;
sort(v.begin(), v.end());
cout << "排序后的数组为:" << endl;
for (int i = 0;i < v.size();i++)
{
cout << v[i] << " ";
}
}
int main()
{
shouMenu();
cin >> choose;
while (choose != 6)
{
clearScreen();
if (choose == 1)
{
charTele();
}
else if (choose==2)
{
bounsGrant();
}
else if (choose == 3)
{
printMonth();
}
else if (choose == 4)
{
int flag =isPrime();
if (flag == 1)
{
cout << "该数是素数" << endl;
}
else
{
cout << "该数不是素数" << endl;
}
}
else if (choose == 5)
{
sortInt();
}
clearScreen();
shouMenu();
cin >> choose;
}
clearScreen();
cout << "退出程序" << endl;
return 0;
}
林总作业----
最新推荐文章于 2024-07-18 11:20:52 发布