Without further ado, let's go to the program!
1. BMI index detection
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int x,a;
double c,b;
cin>>x>>a>>b;//a 体重kg b身高m
c=round(a*1.0/(b*2));
if(x==1&&c>=17.9&&c<=23.9)
{
cout<<"正常"<<" "<<c;
}
if(x==1&&c<17.9)
{
cout<<"低体重"<<" "<<c;
}
if(x==1&&c>=24&&c<=27.9)
{
cout<<"超重"<<" "<<c;
}
if(x==1&&c>28)
{
cout<<"肥胖"<<" "<<c;
}
if(x==0&&c>=17.2&&c<=23.9)
{
cout<<"正常"<<" "<<c;
}
if(x==0&&c<17.2)
{
cout<<"低体重"<<" "<<c;
}
if(x==0&&c>=24&&c<=27.9)
{
cout<<"超重"<<" "<<c;
}
if(x==0&&c>28)
{
cout<<"肥胖"<<" "<<c;
}
}
2. The system program runs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int print()
{
printf(" ╪╪╪╪╪╪╧╧╧╧╧╧╧╧╪╪╪\n");
printf("╔═══╧╧C语言关机程序 ╧╧══╗\n");
printf("║※1.实现10分钟内的定时关闭计算机║\n");
printf("║※2.立即关闭计算机 ║\n");
printf("║※3.注销计算机 ║\n");
printf("║※4.退出系统 ║\n");
printf("╚════════════════╝\n");
return 0;
}
int main()
{
system("title C语言关机程序");//设置cmd窗口标题
system("mode con cols=48 lines=25");//窗口宽度高度
system("color 0B");
system("date /T");
system("TIME /T");
char cmd[20]="shutdown -s -t";
char t[5]="0";
print();
int c;
scanf("%d",&c);
getchar();
switch(c)
{
case 1:printf("您想在多少秒后自动关闭计算机?(0~600)\n");scanf("%s",t);
system(strcat(cmd,t));break;
case 2:system("shutdown -p");break;
case 3:system("shutdown -l");break;
case 0:break;
default:printf("Error!\n");
}
system("pause");
exit(0);
}
3. Drawing numbers
#include<bits/stdc++.h>
using namespace std;
int a[1001]={0};
int main()
{
int x,y,z;
cout<<"参选人数 选出的人数"<<endl;
cin>>y>>z;
srand(time(0));
for(int i=1;i<=z;i++)
{
a[i]=rand()%y;
}
for(int i=1;i<=z;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
4. Shutdown command
#include<stdlib.h>
using namespace std;
int main()
{
system("shutdown -s -t 60");
}
5. Naming
#include<bits/stdc++.h>
using namespace std;
int main()
{
int b,c;
char a[100][20]={"理","儒","家","嘉",
"与","轩","俊","宁","携","龙","麒",
"神","花","虎","思","灵","聪","横",
"人","一","阴","阳","化","混","易",
"化","铭","书","殊","坤","努"};
srand(time(0));
b=rand()%30;
c=rand()%30;
printf("%s%s",a[b],a[c]);
return 0;
}
6. Cancel shutdown command
#include<stdlib.h>
using namespace std;
int main()
{
system("shutdown -a");
}
7. Delete files
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
system("del d:\\123.txt");
return 0;
}
8. Body fat percentage test
#include<iostream>
#include<cmath>
using namespace std;
int main()//1是男 2是女
{
double A,B,c,d;
int x,a,b;//x是男女,a是腰围,b是体重
cin>>x>>a>>b;
if(x==1)
{
A=a*1.0*0.74;
B=b*1.0*0.082+44.74;
d=A-B;
c=round(d/b*100);
}
if(x==0)
{
A=a*1.0*0.74;
B=b*1.0*0.082+34.89;
d=A-B;
c=round(d/b*100);
}
if(x==1&&c>=15&&c<=18)
{
cout<<"体脂正常"<<" "<<c;
}
if(x==1&&c<15)
{
cout<<"偏瘦"<<" "<<c;
}
if(x==1&&c>18)
{
cout<<"偏胖"<<" "<<c;
}
if(x==0&&c>=20&&c<=25)
{
cout<<"体脂正常"<<" "<<c;
}
if(x==0&&c<20)
{
cout<<"偏瘦"<<" "<<c;
}
if(x==0&&c>25)
{
cout<<"偏胖"<<" "<<c;
}
return 0;
}
9. Statistics score
#include<bits/stdc++.h>
using namespace std;
struct student
{
string name;
int score1;
int score2;
int score3;
int score4;
};
student a[101];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name;
cin>>a[i].score1;
cin>>a[i].score2;
cin>>a[i].score3;
a[i].score4+=a[i].score1;
a[i].score4+=a[i].score2;
a[i].score4+=a[i].score3;
}
for(int i=1;i<=n;i++)
{
cout<<a[i].name<<" ";
cout<<a[i].score1<<" ";
cout<<a[i].score2<<" ";
cout<<a[i].score3<<" ";
cout<<a[i].score4<<" ";
}
return 0;
}