include<iostream>
include<time.h>
include<ctime> //調(diào)用clock_t函數(shù)
include<cstdlib> //調(diào)用rund()函數(shù)
using namespace std;
enum Color{BLACK,WHITE,BLUE=100,RED}; //枚舉:定義新變量
main()
{
clock_t start,finish;
double totaltime;
start=clock();
//時(shí)間函數(shù)
/*int j;
int i;
char ch;
cout<<"請(qǐng)輸入學(xué)生成績(jī)判斷成績(jī)等級(jí)。"<<endl;
loop:cin>>i;
for(j=1;j<1000;j++)
{
if(i>100 || i<0)
{
cout<<"成績(jī)輸入錯(cuò)誤,請(qǐng)重新輸入!"<<endl;
goto loop; // goto loop : 分號(hào) 指到達(dá)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<<"此子不及格,請(qǐng)復(fù)讀!"<<endl;
}
cout<<"程序運(yùn)行1000次的時(shí)間!"<<endl;
finish=clock();
totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
cout<<"\n此程序的運(yùn)行時(shí)間為"<<totaltime<<"秒!"<<endl;
cout<<"輸入Y繼續(xù)判斷,輸入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 從零開(kāi)始,依次遞增
cout <<"Color hat = "<< hat << endl; //輸出: color hat = 101 前一位數(shù)+1
*/
//肆 表達(dá)式
//int a,b,c,d;
//a=10,b=5; //逗號(hào)表達(dá)式
//b = (a=5)+(++a); //求值順序 ?會(huì)由于計(jì)算機(jī)或編程軟件的不同,產(chǎn)生 不同編譯結(jié)果
//c = (a>b)? a:b ; //三元操作符
//cout<<"c = "<<c<<endl;
//cout <<"b = "<<b<< endl;
//d = (a =0,b=1,c=2,c=3); //× 最好不要這樣用,復(fù)雜且不易于理解,易犯錯(cuò)。。
//cout <<"d = "<<d<<endl;
/* 伍 運(yùn)算
int c,d,e,f;
c = 1|2-3;
d = 1&2|3; //先加減后三目運(yùn)算 & ,|, ^ 優(yōu)先級(jí)依次降低
e = 1^2&-3;
f = 1|2&3;
cout<<"c = "<<c<<endl;
cout<<"d = "<<d<<endl;
cout<<"e = "<<e<<endl;
cout<<"f = "<<f<<endl;
*/
//陸 程序語(yǔ)句 ①控制語(yǔ)句 ②表達(dá)式語(yǔ)句 ③空語(yǔ)句 ④語(yǔ)句塊
//①控制語(yǔ)句 又叫流程控制語(yǔ)句 判斷 循環(huán) 多路選擇語(yǔ)句 if switch case: while goto loop
//② 表達(dá)式語(yǔ)句 進(jìn)行表達(dá)式計(jì)算的語(yǔ)句 --i;也算語(yǔ)句 有運(yùn)算符和結(jié)束符
//③空語(yǔ)句 只有分號(hào),沒(méi)有其他語(yǔ)句
//④語(yǔ)句塊 多個(gè)語(yǔ)句構(gòu)成語(yǔ)句塊
/* switch 選擇語(yǔ)句
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; //沒(méi)有break的話進(jìn)入下一個(gè)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; //缺省態(tài)
}
/
/循環(huán)語(yǔ)句
int total=0;
int money;
while(total<500)
{
cout<<"錢還不夠500,再給點(diǎn)錢吧!"<<endl;
cin>>money;
total+=money;
if((500-total)>0)
cout<<"還差"<<500-total<<"錢"<<endl;
}
cout<<"現(xiàn)在有"<<total<<"錢,O(∩_∩)O哈哈~"<<endl;
/
/ 柒
int c = 0;
long t = time(NULL);
t +=5;
while(time(NULL)<t) //在5秒鐘數(shù)多少數(shù)
{
cout<<++c<<endl; //定時(shí)器 sleep
}
/
/
int n = 5 ,i=1;
while(n > 0)
{
long t = time(NULL);
t +=1;
while(time(NULL)<t) ; //每秒輸入一個(gè)數(shù)字,輸入5秒 //定時(shí)器 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 循環(huán) 與菜單的結(jié)合,可以先讀出菜單,再進(jìn)行選擇
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 僅在循環(huán)和switch 中有用。反復(fù)循環(huán),直到輸入0,退出
{
cin>>sq;
total = sqsq;
if(total==0)
break;
cout<<sq<<"的平方為"<<total<<endl;
}
/
/int i=1,n;
cout<<"班級(jí)有幾名同學(xué)"<<endl;
cin>>n;
int math[n],total=0;
for(i;i<n+1;i++) //循環(huán)n+1 -i 次
{
cout<<"輸入數(shù)學(xué)成績(jī)"<<endl;
cin>>math[i];
total= math[i]+total;
cout<<"第"<<i<<"同學(xué)的成績(jī)?yōu)椋?<<math[i]<<endl;
}
cout<<n<<"名同學(xué)的總成績(jī)?yōu)?"<<total<<endl;
cout<<n<<"名同學(xué)的平均成績(jī)是:"<<total/n<<endl;
*/
/* 、拾
int a,b,table;
for(a=1;a<10;a++)
{
for(b=1;b<=a;b++)
cout<<b<<""<<a<<"="<<ab<<" "; //九九乘法表 第二個(gè)for循環(huán) 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++; //僅使用一個(gè)for循環(huán)。
}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此程序的運(yùn)行時(shí)間為"<<totaltime<<"秒!"<<endl;
return 0;
}