版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第2章程序控制結(jié)構(gòu)
2.1選擇控制
2.2循環(huán)控制
2.3判斷表達式的使用
2.4轉(zhuǎn)向語句
小結(jié)語句是程序的基本語法成分。程序設(shè)計語言的語句按功能可以分成三類:
聲明語句指示編譯器分配內(nèi)存,或者提供程序連接信息
操作語句描述對數(shù)據(jù)的處理
控制語句用于控制程序的執(zhí)行流程。所有程序都只能包含三種控制結(jié)構(gòu): 順序結(jié)構(gòu)、選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)第2章程序控制結(jié)構(gòu)對給定的條件進行判斷,并根據(jù)判斷的結(jié)果選擇不同的操作
2.1選擇控制條件運算表達式
根據(jù)判斷條件,決定表達式的值 不改變程序語句執(zhí)行流程
比較條件運算1.if語句的形式和執(zhí)行流程if(表達式)語句;2.1.1if語句語句形式(1)執(zhí)行流程false(0)true(非0)
表達式
語句2.1.1if語句false(0)true(非0)
表達式
語句1.if語句的形式和執(zhí)行流程if(表達式)語句;2.1.1if語句語句形式(1)執(zhí)行流程
表達式
語句true(非0)2.1.1if語句false(0)true(非0)
表達式
語句1.if語句的形式和執(zhí)行流程if(表達式)語句;2.1.1if語句語句形式(1)執(zhí)行流程
表達式
false(0)2.1.1if語句2.1.1if語句35abmax例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句35abmax3例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句35abmax3例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句35abmax3例:
:max=a;if(b>a)
max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句35abmax5例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句35abmax5
max=5輸出例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句73abmax例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句73abmax7例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句73abmax7例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句73abmax7
max=7輸出例:
:max=a;if(b>a)max=b;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句1.if語句的形式和執(zhí)行流程語句形式(2)if(表達式)語句1
;
else語句2
;執(zhí)行流程false(0)true(非0)
表達式
語句1語句22.1.1if語句2.1.1if語句1.if語句的形式和執(zhí)行流程語句形式(2)if(表達式)語句1
;
else語句2
;執(zhí)行流程false(0)true(非0)
表達式
語句1語句2true(非0)
表達式
語句12.1.1if語句2.1.1if語句1.if語句的形式和執(zhí)行流程語句形式(2)if(表達式)語句1
;
else語句2
;執(zhí)行流程false(0)true(非0)
表達式
語句1語句2false(0)
表達式
語句22.1.1if語句2.1.1if語句例:
:if(b>a)max=b;elsemax=a;cout<<"max="<<max<<endl;:35abmax2.1.1if語句2.1.1if語句35abmax例:
:if(b>a)
max=b;elsemax=a;cout<<"max="<<max<<endl;:2.1.1if語句2.1.1if語句例:
:if(b>a)
max=b;
elsemax=a;cout<<"max="<<max<<endl;:35abmax52.1.1if語句2.1.1if語句例:
:if(b>a)max=b;elsemax=a;cout<<"max="<<max<<endl;:35abmax5
max=5輸出2.1.1if語句2.1.1if語句例:
:if(b>a)
max=b;elsemax=a;cout<<"max="<<max<<endl;:73abmax2.1.1if語句2.1.1if語句例:
:if(b>a)max=b;
elsemax=a;cout<<"max="<<max<<endl;:73abmax72.1.1if語句2.1.1if語句例:
:if(b>a)max=b;elsemax=a;cout<<"max="<<max<<endl;:73abmax7
max=7輸出2.1.1if語句2.1.1if語句例:
:if(b>a)max=b;elsemax=a;cout<<"max="<<max<<endl;:73abmax7
max=7輸出試一試用條件表達式修改該程序2.1.1if語句2.1.1if語句2.if語句的嵌套
if語句中的執(zhí)行語句如果又是另一個if語句,稱為嵌套if語句
if與else的配對關(guān)系:C++規(guī)定,else總是與它接近的if配對使用復(fù)合語句,可以改變條件語句的執(zhí)行流程2.1.1if語句2.1.1if語句例2-1
編寫程序計算貨物運費。設(shè)貨物運費每噸單價p(元)與運輸距離s(公里)之間有如下關(guān)系:p=輸入要托運的貨物重量為w噸,托運距離s公里,計算總運費t:
t=p*w*s2.1.1if語句2.1.1if語句控制流圖truefalsetruetruetruefalsefalsefalseS<100?S<200?S<300?S<400?P=30P=20P=22.5P=25P=27.5t=p*w*s2.1.1if語句2.1.1if語句truefalsetruetruetruefalsefalsefalseS<100?S<200?S<300?S<400?P=30P=20P=22.5P=25P=27.5t=p*w*s//例2-1計算貨物運費#include<iostream>#include<iomanip>usingnamespacestd;intmain(){doublet,p,w,s;
cout<<"Pleaseinputweight(ton):";
cin>>w;
cout<<"Pleaseinputdistsnce(kilometre):";
cin>>s;if(s<100)p=30;elseif(s<200)p=27.5; elseif(s<300)p=25; elseif(s<400)p=22.5; elsep=20;t=p*w*s;
cout<<"Thecostis:"<<setprecision(2)<<t<<'$'<<endl;}想一想:幾個else分支語句的次序可以改變嗎?2.1.1if語句//例2-1計算貨物運費#include<iostream>#include<iomanip>usingnamespacestd;intmain(){doublet,p,w,s;
cout<<"Pleaseinputweight(ton):";
cin>>w;
cout<<"Pleaseinputdistsnce(kilometre):";
cin>>s;if(s<100)p=30;elseif(s<200)p=27.5; elseif(s<300)p=25; elseif(s<400)p=22.5; elsep=20;t=p*w*s;
cout<<"Thecostis:"<<setprecision(2)<<t<<'$'<<endl;}truefalsetruetruetruefalsefalsefalseS<100?S<200?S<300?S<400?P=30P=20P=22.5P=25P=27.5t=p*w*s2.1.1if語句
例如:
cin>>s;if(s<300)p=25;elseif(s<100)p=30;elseif(s<400)p=22.5;elseif(s<200)p=27.5;elsep=20;t=p*w*s;
若輸入s:150
輸出t值等于多少?為什么?2.1.1if語句2.1.1if語句例2-2
輸入三個整數(shù),按從小到大順序輸出。解法一
數(shù)據(jù)排序。先找出最小值,放在a中,然后找次小值,放在b中:
1.對a、b進行比較,把小值放于a;
ifa>bab
//a<b2.
對a、c進行比較,把小值放于a;
ifa>cac
//a<c,a<b3.對
b、c進行比較,把小值放于b;
ifb>cbc
//a<b&&b<c4.輸出a,b,c的值。2.1.1if語句2.1.1if語句例2-2
輸入三個整數(shù),按從小到大順序輸出。a
7
5
2bca>b:ab
a
5
7
2bca
2
7
5bc
2
7a>c:ac
2b>c:bc
a
2
5
7bca<ba<b,a<ca<b&&b<c2.1.1if語句2.1.1if語句例2-2
輸入三個整數(shù),按從小到大順序輸出。#include<iostream>usingnamespacestd;intmain(){inta,b,c,t;
cout<<"Pleaseinputthreeintegernumbers:";
cin>>a>>b>>c;if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}
cout<<a<<""<<b<<""<<c<<endl;}注意語句塊結(jié)構(gòu)2.1.1if語句2.1.1if語句例2-2
輸入三個整數(shù),按從小到大順序輸出。#include<iostream>usingnamespacestd;intmain(){inta,b,c,t;
cout<<"Pleaseinputthreeintegernumbers:";
cin>>a>>b>>c;if(a>b)
{t=a;a=b;b=t;}if(a>c)
{t=a;a=c;c=t;}if(b>c)
{t=b;b=c;c=t;}
cout<<a<<""<<b<<""<<c<<endl;}注意語句塊結(jié)構(gòu)2.1.1if語句2.1.1if語句 if(E1) if(E2)S1
elseS2if(E1)
{if(E2)S1
}elseS2分析S1和S2的執(zhí)行條件:E1&&E2
執(zhí)行S1E1&&!E2
執(zhí)行S2E1&&E2
執(zhí)行S1
!E1
執(zhí)行S2注意括號的作用2.if語句的嵌套2.1.1if語句3.應(yīng)用舉例(1)
把輸入字符轉(zhuǎn)換為小寫字母。對輸入字符進行判斷,如果是大寫字母,則轉(zhuǎn)換為小寫字母;否則,不轉(zhuǎn)換。//例2-3#include<iostream>usingnamespacestd;intmain(){charch;
cout<<"ch=";
cin>>ch;if(ch>='A'&&ch<='Z')ch+=32;
cout<<ch<<endl;}2.1.1if語句3.應(yīng)用舉例//例2-3
#include<iostream>usingnamespacestd;intmain(){charch;
cout<<"ch=";
cin>>ch;if(ch>='A'&&ch<='Z')
ch+=32;
cout<<ch<<endl;}輸入大寫字母(1)
把輸入字符轉(zhuǎn)換為小寫字母。對輸入字符進行判斷,如果是大寫字母,則轉(zhuǎn)換為小寫字母;否則,不轉(zhuǎn)換。2.1.1if語句3.應(yīng)用舉例//例2-3#include<iostream>usingnamespacestd;intmain(){charch;
cout<<"ch=";
cin>>ch;if(ch>='A'&&ch<='Z')ch+=32;
cout<<ch<<endl;}計算ASCII碼偏移值(1)
把輸入字符轉(zhuǎn)換為小寫字母。對輸入字符進行判斷,如果是大寫字母,則轉(zhuǎn)換為小寫字母;否則,不轉(zhuǎn)換。2.1.1if語句3.應(yīng)用舉例//例2-3#include<iostream>usingnamespacestd;intmain(){charch;
cout<<"ch=";
cin>>ch;if(ch>='A'&&ch<='Z')ch+=32;
cout<<ch<<endl;}(1)
把輸入字符轉(zhuǎn)換為小寫字母。對輸入字符進行判斷,如果是大寫字母,則轉(zhuǎn)換為小寫字母;否則,不轉(zhuǎn)換。2.1.1if語句3.應(yīng)用舉例//例2-3#include<iostream>usingnamespacestd;intmain(){charch;
cout<<"ch=";
cin>>ch;
if(ch>='A'&&ch<='Z')ch+=32;
cout<<ch<<endl;}改寫為條件表達式ch=(ch>='A'&&ch<='Z')?ch+32:ch;(1)
把輸入字符轉(zhuǎn)換為小寫字母。對輸入字符進行判斷,如果是大寫字母,則轉(zhuǎn)換為小寫字母;否則,不轉(zhuǎn)換。2.1.1if語句3.應(yīng)用舉例
(2)
求一元二次方程ax2+bx+c=0的根。求根公式:①當a=0時,方程不是二次方程②當b2-4ac=0時,有兩個相同的實根:③當b2-4ac>0時,有兩個不同的實根:④當b2-4ac<0時,有兩個共軛復(fù)根:2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}數(shù)據(jù)說明2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}提示并輸入系數(shù)2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;
if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}不是二次方程2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}a等于0浮點數(shù)的誤差判斷2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;
else
{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}有根2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}求判別式2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;
if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}有兩個相同的實根2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}有兩個不相同的實根2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}有兩個共軛復(fù)根2.1.1if語句#include<iostream> //例2-4#include<cmath>usingnamespacestd;intmain(){doublea,b,c,d,x1,x2,rp,ip;
cout<<"a,b,c=";cin>>a>>b>>c;if(fabs(a)<=1e-8)
cout<<"Itisnotquadratic."<<endl;else{d=b*b-4*a*c;if(fabs(d)<=1e-8)
cout<<"Ithastwoequalrealroots:"<<-b/(2*a)<<endl;elseif(d>1e-8) {x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
cout<<"Ithastwodistinctrealroots:"<<x1<<"and"<<x2<<endl; } else{rp=-b/(2*a);ip=sqrt(-d)/(2*a);
cout<<"Ithastwocomplexroots:"<<endl;
cout<<rp<<"+"<<ip<<"i"<<endl;
cout<<rp<<"-"<<ip<<"i"<<endl; } }}a,b,c=021Itisnotquadratic.a,b,c=121Ithastwoequalrealroots:-1a,b,c=151Ithastwodistinctrealroots:-0.208712and–4.791288a,b,c=234Ithastwocomplexroots:-0.75+1.198958i-0.75-1.198958i2.1.1if語句根據(jù)一個整型表達式的值決定程序分支2.1.2switch語句一般形式:
switch(表達式){case常量表達式1:語句1
case常量表達式2:語句2
…
case常量表達式n:語句ndefault:語句n+1}注:
表達式類型為非浮點型
各常量表達式類型要與之匹配各常量表達式要求各不相等default子句可選。缺省時,沒有匹配值switch語句為空語句標號2.1.2switch語句根據(jù)一個整型表達式的值決定程序分支2.1.2switch語句表達式語句1語句2語句3語句n語句n+1=常量1=常量2=常量3=常量n=常量n+1執(zhí)行流程2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}觀察不同輸入時的輸出結(jié)果2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;
switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2switch語句例2-5根據(jù)考試成績的等級打印出百分制分數(shù)段。#include<iostream>usingnamespacestd;intmain(){chargrade;
cout<<"Inputgradeofscore(a_d):"<<endl;
cin>>grade;switch(grade){case'a':cout<<"85__100\n";case'b':cout<<"70__84\n";case'c':cout<<"60__69\n";case'd':cout<<"<60\n";default:cout<<"error\n";}}輸入a輸出85__10070__8460__6960error2.1.2switch語句2.1.2
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年廣告代理與廣告客戶合同
- 2024年國際光纖網(wǎng)絡(luò)建設(shè)合同
- 2024年個體工商戶與雇工彈性工作合同
- 2024正式的服裝代理合同書
- 2024年家政服務(wù)雇傭協(xié)議
- 2024年合同條款革新:構(gòu)建新范式
- 2024年企業(yè)咨詢服務(wù)及管理培訓合同
- 2024年城市垃圾處理與環(huán)保合同
- 2024年國際版權(quán)許可使用合同(文學作品)
- 2024賓館裝修合同樣式
- 醫(yī)學Ev3頸動脈支架和保護傘課件
- 民事案件卷宗范本
- 風險分級管控清單(完整版)
- 醫(yī)院服務(wù)-PPT課件
- 《保健按摩師》(四級)理論知識鑒定要素細目表
- 《船舶柴油機》教案48頁
- SYB創(chuàng)業(yè)培訓全課件(ppt)
- 扣眼穿刺的護理體會
- 試驗設(shè)計與數(shù)據(jù)處理(第二版)李云雁(全書ppt)PPT課件
- 七年級數(shù)學上冊《同類項》課件_華東師大版
- 烹飪工藝與營養(yǎng)專業(yè)(高專)教學計劃
評論
0/150
提交評論