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ù)
/*int j;
int i;
char ch;
cout<<"請輸入學(xué)生成績判斷成績等級蠕搜。"<<endl;
loop:cin>>i;
for(j=1;j<1000;j++)
{
if(i>100 || i<0)
{
cout<<"成績輸入錯誤妓灌,請重新輸入虫埂!"<<endl;
goto loop; // goto loop : 分號 指到達(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<<"此子不及格闯参,請復(fù)讀!"<<endl;
}
cout<<"程序運行1000次的時間新博!"<<endl;
finish=clock();
totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
cout<<"\n此程序的運行時間為"<<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 從零開始埂淮,依次遞增
cout <<"Color hat = "<< hat << endl; //輸出: color hat = 101 前一位數(shù)+1
*/
//肆 表達(dá)式
//int a,b,c,d;
//a=10,b=5; //逗號表達(dá)式
//b = (a=5)+(++a); //求值順序 倔撞?會由于計算機或編程軟件的不同痪蝇,產(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ù)雜且不易于理解耙册,易犯錯。想际。
//cout <<"d = "<<d<<endl;
/* 伍 運算
int c,d,e,f;
c = 1|2-3;
d = 1&2|3; //先加減后三目運算 & ,|, ^ 優(yōu)先級依次降低
e = 1^2&-3;
f = 1|2&3;
cout<<"c = "<<c<<endl;
cout<<"d = "<<d<<endl;
cout<<"e = "<<e<<endl;
cout<<"f = "<<f<<endl;
*/
//陸 程序語句 ①控制語句 ②表達(dá)式語句 ③空語句 ④語句塊
//①控制語句 又叫流程控制語句 判斷 循環(huán) 多路選擇語句 if switch case: while goto loop
//② 表達(dá)式語句 進行表達(dá)式計算的語句 --i;也算語句 有運算符和結(jié)束符
//③空語句 只有分號畸悬,沒有其他語句
//④語句塊 多個語句構(gòu)成語句塊
/* 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; //缺省態(tài)
}
/
/循環(huán)語句
int total=0;
int money;
while(total<500)
{
cout<<"錢還不夠500蹋宦,再給點錢吧冷冗!"<<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; //定時器 sleep
}
/
/
int n = 5 ,i=1;
while(n > 0)
{
long t = time(NULL);
t +=1;
while(time(NULL)<t) ; //每秒輸入一個數(shù)字,輸入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 循環(huán) 與菜單的結(jié)合俺叭,可以先讀出菜單泰偿,再進行選擇
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<<"班級有幾名同學(xué)"<<endl;
cin>>n;
int math[n],total=0;
for(i;i<n+1;i++) //循環(huán)n+1 -i 次
{
cout<<"輸入數(shù)學(xué)成績"<<endl;
cin>>math[i];
total= math[i]+total;
cout<<"第"<<i<<"同學(xué)的成績?yōu)椋?<<math[i]<<endl;
}
cout<<n<<"名同學(xué)的總成績?yōu)?"<<total<<endl;
cout<<n<<"名同學(xué)的平均成績是:"<<total/n<<endl;
*/
/* 搬俊、拾
int a,b,table;
for(a=1;a<10;a++)
{
for(b=1;b<=a;b++)
cout<<b<<""<<a<<"="<<ab<<" "; //九九乘法表 第二個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++; //僅使用一個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此程序的運行時間為"<<totaltime<<"秒檀葛!"<<endl;
return 0;
}