include<iostream>
include<time.h>
include<ctime> //调用clock_t函数
include<cstdlib> //调用rund()函数
using namespace std;
enum Color{BLACK,WHITE,BLUE=100,RED}; //枚举:定义新变量
main()
{
clock_t start,finish;
double totaltime;
start=clock();
//时间函数
/*int j;
int i;
char ch;
cout<<"请输入学生成绩判断成绩等级。"<<endl;
loop:cin>>i;
for(j=1;j<1000;j++)
{
if(i>100 || i<0)
{
cout<<"成绩输入错误,请重新输入!"<<endl;
goto loop; // goto loop : 分号 指到达loop处
}
else if(i<=100 && i>90)
cout<<"此子为甲等!"<<endl;
else if(i<=90 && i>80)
cout<<"此子为乙等!"<<endl;
else if(i<=80 && i>70) //把你的程序代码插入到这里面
cout<<"此子为丙等!"<<endl;
else if(i<=80 && i>60)
cout<<"此子为丁等!"<<endl;
else
cout<<"此子不及格,请复读!"<<endl;
}
cout<<"程序运行1000次的时间!"<<endl;
finish=clock();
totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
cout<<"\n此程序的运行时间为"<<totaltime<<"秒!"<<endl;
cout<<"输入Y继续判断,输入N退出"<<endl;
cin >>ch;
if(ch == 'y'|| ch == 'Y')
goto loop;
if(ch == 'n'|| ch== 'N')
/
/
//叁 枚举 枚举类型为整形
Color cloth = WHITE;
Color hat= RED;
cout <<"Color cloth = "<< cloth << endl; //输出: color hat = 1 从零开始,依次递增
cout <<"Color hat = "<< hat << endl; //输出: color hat = 101 前一位数+1
*/
//肆 表达式
//int a,b,c,d;
//a=10,b=5; //逗号表达式
//b = (a=5)+(++a); //求值顺序 ?会由于计算机或编程软件的不同,产生 不同编译结果
//c = (a>b)? a:b ; //三元操作符
//cout<<"c = "<<c<<endl;
//cout <<"b = "<<b<< endl;
//d = (a =0,b=1,c=2,c=3); //× 最好不要这样用,复杂且不易于理解,易犯错。。
//cout <<"d = "<<d<<endl;
/* 伍 运算
int c,d,e,f;
c = 1|2-3;
d = 1&2|3; //先加减后三目运算 & ,|, ^ 优先级依次降低
e = 1^2&-3;
f = 1|2&3;
cout<<"c = "<<c<<endl;
cout<<"d = "<<d<<endl;
cout<<"e = "<<e<<endl;
cout<<"f = "<<f<<endl;
*/
//陆 程序语句 ①控制语句 ②表达式语句 ③空语句 ④语句块
//①控制语句 又叫流程控制语句 判断 循环 多路选择语句 if switch case: while goto loop
//② 表达式语句 进行表达式计算的语句 --i;也算语句 有运算符和结束符
//③空语句 只有分号,没有其他语句
//④语句块 多个语句构成语句块
/* switch 选择语句
int s;
cout<<"1--good moring"<<endl;
cout<<"2--good afternoon"<<endl;
cout<<"3--good evering"<<endl;
cout<<"choose 1--3"<<endl;
cin >>s;
switch( s)
{
case 1:
{
int s = 100;
cout<<s<<endl; //没有break的话进入下一个case:
}
cout<<"1--good moring"<<endl;
case 2:cout<<"2--good afternoon"<<endl;break;
case 3:cout<<"3--good evering"<<endl;break;
default:cout<<"choose 1--3"<<endl;break; //缺省态
}
/
/循环语句
int total=0;
int money;
while(total<500)
{
cout<<"钱还不够500,再给点钱吧!"<<endl;
cin>>money;
total+=money;
if((500-total)>0)
cout<<"还差"<<500-total<<"钱"<<endl;
}
cout<<"现在有"<<total<<"钱,O(∩_∩)O哈哈~"<<endl;
/
/ 柒
int c = 0;
long t = time(NULL);
t +=5;
while(time(NULL)<t) //在5秒钟数多少数
{
cout<<++c<<endl; //定时器 sleep
}
/
/
int n = 5 ,i=1;
while(n > 0)
{
long t = time(NULL);
t +=1;
while(time(NULL)<t) ; //每秒输入一个数字,输入5秒 //定时器 sleep
}
cout<<i++<<endl;
n--;
}
/
/ 捌
int i;
do{
cout<<"显示菜单"<<endl;
cout<<"1.上衣"<<endl;
cout<<"2.裤子"<<endl;
cout<<"3.袜子"<<endl;
cout<<"4.鞋子"<<endl;
cout<<"输入选择"<<endl;
cin>>i;
}while(i>4|| i<1); //do while 循环 与菜单的结合,可以先读出菜单,再进行选择
switch(i)
{
case 1: cout<<"上衣颜色."<<endl;break;
case 2: cout<<"裤子颜色"<<endl;break;
case 3: cout<<"袜子颜色"<<endl;break;
case 4: cout<<"鞋子颜色"<<endl;break;
default: break;
}
*/
/玖
int sq,total;
for(;;) // break 仅在循环和switch 中有用。反复循环,直到输入0,退出
{
cin>>sq;
total = sqsq;
if(total==0)
break;
cout<<sq<<"的平方为"<<total<<endl;
}
/
/int i=1,n;
cout<<"班级有几名同学"<<endl;
cin>>n;
int math[n],total=0;
for(i;i<n+1;i++) //循环n+1 -i 次
{
cout<<"输入数学成绩"<<endl;
cin>>math[i];
total= math[i]+total;
cout<<"第"<<i<<"同学的成绩为:"<<math[i]<<endl;
}
cout<<n<<"名同学的总成绩为:"<<total<<endl;
cout<<n<<"名同学的平均成绩是:"<<total/n<<endl;
*/
/* 、拾
int a,b,table;
for(a=1;a<10;a++)
{
for(b=1;b<=a;b++)
cout<<b<<""<<a<<"="<<ab<<" "; //九九乘法表 第二个for循环 b<=a
cout<<"\n"<<endl;
}
/
/ int j=1;
for (int i = 1; i <= 9; )
{
cout<<j<<"*"<<i<<"="<<i * j<<" ";
if (j >= i)
{
cout<<"\n"<<endl;
j = 1;
i++; //仅使用一个for循环。
}else{
j++;
}
}
*/
/*for(int i=0;i<10;i++)
cout<<rand()%100<<endl; //需要头文件#include<cstdlib>
*/
finish=clock();
totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
cout<<"\n此程序的运行时间为"<<totaltime<<"秒!"<<endl;
return 0;
}