


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、.實(shí)驗(yàn)名稱:分支結(jié)構(gòu)程序設(shè)計(jì)1、編寫一個(gè)程序,輸入某雇員的每周工作時(shí)間(以小時(shí)計(jì))和每小時(shí)的工資數(shù),計(jì)算并輸出他的工資。若雇員每周工作小時(shí)超過40 小時(shí),則超過部分按原工資的1.5 倍計(jì)算。若雇員每周工作小時(shí)超過60 小時(shí),則超過60 的部分按原工資的3 倍計(jì)算。要求:( 1)要求有輸入提示和輸出提示,如輸入雇員的工作時(shí)間和每小時(shí)的工資值時(shí),可以提示:“Please input employee s work time and wage_per_hour: ” 輸出時(shí),提示:“ The employee s wage : ”。( 2)寫出雇員在各種周工作時(shí)間情況下的輸入數(shù)據(jù)和輸出數(shù)據(jù)。2、編程
2、計(jì)算圖形的面積。程序可計(jì)算圓形、長方形、正方形的面積,運(yùn)行時(shí)先提示用戶選擇圖形的類型,然后,要求用戶對(duì)圓形輸入半徑值,要求用戶對(duì)長方形輸入長和寬的值,要求用戶對(duì)正方形輸入邊長的值,計(jì)算出面積的值后將其顯示出來。1、打開 VC 環(huán)境。2、輸入以下程序代碼:#include <iostream.h>void main()int salary,hour;/(1)定義每小時(shí)工資數(shù)及每周工作時(shí)數(shù)的變量double week;/(2) 定義每周的工資數(shù)變量cout<<"Please inputemployee's work time and wage_per_ho
3、ur:"/(3) 輸入提示信息cin>>hour>>salary;/(4)輸入每小時(shí)工資數(shù)及每周工作時(shí)數(shù)if (hour<=40)/(5) 判斷工作時(shí)數(shù)是否小于40week=salary*hour;/(6) 計(jì)算小于 40 情況的周工資數(shù)if (hour<=60&&hour>40)/(7) 判斷工作時(shí)數(shù)是否在40 至 60 之間week=salary*(hour-40)*1.5+salary*40;/(8) 計(jì)算周工資數(shù)if (hour>60) /(9)判斷工作時(shí)數(shù)是否大于60 之間week=salary*40+sala
4、ry*20*1.5+salary*(hour-60)*3;/(10) 計(jì)算周工資數(shù)cout<<"The employee's wage :"<<week<<endl;/(11) 輸出周工資數(shù)實(shí)驗(yàn) 2 的參考程序:#include <iostream>using namespace std;const float PI = 3.1416;int main()int iType;float radius, a, b, area;cout << " 圖形的類型為 ?(1-圓形 2-長方形 3-正方形 )
5、:" cin >> iType;switch(iType)1/12.case 1:cout << " 圓的半徑為: "cin >> radius;area = PI * radius * radius;break;case 2:cout << " 矩形的長為: "cin >> a;cout << " 矩形的寬為: "cin >> b;area = a * b;break;case 3:cout << " 正方形的邊長為:
6、 "cin >> a;area = a * a;break;default:cout << " 不是合法的輸入值 !"<<endl;cout<<" 面積為: "<<area<<endl;實(shí)驗(yàn)名稱:循環(huán)結(jié)構(gòu)程序設(shè)計(jì)1、 編寫一個(gè)程序,循環(huán)提示從鍵盤輸入數(shù)值,找出這些數(shù)值中的最大值和最小值。2、編寫程序?qū)崿F(xiàn)階乘之和1! 2!+3!+ +m!。要求如下:( 1)求階乘之和小于100000 的最大 m值并輸出m及和值。( 2)根據(jù)求解結(jié)果,輸出完整的階乘表達(dá)式,如:1!+2!+3!
7、=9。3、編寫一個(gè)程序,實(shí)現(xiàn)計(jì)算一個(gè)整數(shù)的各位數(shù)字之和,如輸入2568, 該程序能實(shí)現(xiàn)計(jì)算8+6+5+2 的值并輸出。1、#include<iostream.h>void main()int num,data,max,min,i;cout<<" 輸入數(shù)據(jù)的個(gè)數(shù): "cin>>num;cout<<" 輸入初始值 :"cin>>data;max=min=data;for(i=1;i<num;i+)cout<<" 輸入數(shù)據(jù) :"cin>>data;if
8、(max<data)max=data;2/12.else if(min>data)min=data;cout<<"Max="<<max<<" Min="<<min<<endl;2、#include <iostream.h>void main()int m,sum,i,fac;sum=0;fac=1;m=1;while(1) / 求階乘 ,找出階乘的最小m 值fac=fac*m;sum+=fac;if(sum>100000)m-;sum=sum-fac;cout<
9、;<" 滿足不等式的最小值 ="<<m<<"和值 ="<<sum<<endl;break;m+;for(i=1;i<m;i+)/此循環(huán)完成輸出格式,根據(jù)m 值求階乘cout<<i<<"!+"cout<<i<<"!="<<sum<<endl;3、#include <iostream.h>void main()int num,residue,sum=0;cout<<
10、"Enter an integer:"cin>>num;while(1)residue=num%10;sum+=residue;num/=10;if(num!=0)/控制輸出格式cout<<residue<<"+"3/12.elsecout<<residue<<"="<<sum<<endl;break;實(shí)驗(yàn)名稱:函數(shù)1、由鍵盤輸入兩個(gè)整數(shù),求兩個(gè)數(shù)的最大公約數(shù)和最小公倍數(shù)。要求:( 1)最大公約數(shù)和最小公倍數(shù)分別由函數(shù)實(shí)現(xiàn)。( 2)在主函數(shù)中調(diào)用所寫函
11、數(shù),給出在運(yùn)行程序時(shí)的輸入數(shù)據(jù)和輸出數(shù)據(jù)。2、輸入三個(gè)數(shù),驗(yàn)證是否構(gòu)成一個(gè)三角形,如果能,通過海倫公式s=(其中 p=( a+b+c)/2) ,計(jì)算三角形面積,要求:( 1)實(shí)現(xiàn)判斷三個(gè)數(shù)是否構(gòu)成三角形和計(jì)算面積由函數(shù)實(shí)現(xiàn)。( 2)編寫主函數(shù)對(duì)編寫的函數(shù)進(jìn)行測(cè)試。1、#include<iostream.h>int gCD(int data1,int data2) /求最大公約數(shù)int residue;if(data1<data2)/data1 大于 data2int temp;temp=data1;data1=data2;data2=temp;doresidue=data1%
12、data2;data1=data2;data2=residue;while(residue!=0);return (data1);int lCM(int data1,int data2)/求最小公倍數(shù)return (data1*data2)/gCD(data1,data2);int main()int d1,d2;cout<<" 輸入兩個(gè)整數(shù) "4/12.cin>>d1>>d2;cout<<d1<<","<<d2<<" 的最大公約數(shù)是: "<&l
13、t;gCD(d1,d2)<<endl; cout<<d1<<","<<d2<<" 的最小公倍數(shù)是: "<<lCM(d1,d2)<<endl; return 0;2、bool isTriangle(float a,float b,float c)實(shí)現(xiàn)判斷 a,b,c 能否構(gòu)成三角形的三條邊,并編寫主調(diào)函數(shù)。/設(shè)計(jì)一個(gè)函數(shù),對(duì)傳遞給它的double 型數(shù)值進(jìn)行四舍五入作為int 型值返回。#include<iostream.h>bool isTriangle(fl
14、oat a,float b,float c)return (a+b>c&&a+c>b&&b+c>a);double TriangleArea(float a,float b,float c)double p=(a+b+c)/2;double s=sort(p*(p+a)*(p+b)*(p+c);return p;int main()float a,b,c;cout<<" 輸入三條邊 :"cin>>a>>b>>c;if(!isTriangle(a,b,c)cout<<
15、" 不能構(gòu)成三角形:"<<endl;elsecout<<" 能構(gòu)成三角形:"<<endl;cout<< ”三角形面積 =”<< TriangleArea(a,b,c);return 0;實(shí)驗(yàn)名稱:類和對(duì)象創(chuàng)建一個(gè)學(xué)生類 Student ,該類中數(shù)據(jù)成員有: 學(xué)號(hào) (sno) 、姓名 (sname) 、年齡 (sage) 、數(shù)學(xué) (math) 、計(jì)算機(jī) (computer) ;實(shí)現(xiàn)相關(guān)功能的成員函數(shù)有:構(gòu)造函數(shù)、析構(gòu)函數(shù)、求每個(gè)學(xué)生的平均成績【平均成績 =(數(shù)學(xué) +計(jì)算機(jī)) /2 】、輸出學(xué)生所有
16、信息。參考程序:#include<iostream.h>#include<string.h>#include<iomanip.h>5/12.class Studentint no;char name;char sex;int age;float math;float computer;public:Student(int no1,char na,char se,int ag,float math,float computer);Student();void set();float average();void display();Student: Stude
17、nt(int no1,char na,char se,int ag,float ma,float com)no=no1;name=na;sex=se;age=ag;computer=com;math=ma;Student:Student()no=0;computer=0;math=0;void Student:set()cout<<" 輸入學(xué)號(hào) "cin>>no;cout<<" 輸入姓名 :"cin>>name;cout<<" 輸入性別 :"cin>>sex;co
18、ut<<" 輸入年齡 :"cin>>age;cout<<" 輸入數(shù)學(xué)成績 :"cin>>math;cout<<" 輸入計(jì)算機(jī)成績 :"cin>>computer;6/12.float Student:average()return (math+computer)/2;void Student:display()cout<<setw(10)<<no<<setw(20)<<name<<setw(10)<
19、<sex; cout<<setw(4)<<age<<setw(5)<<math<<setw(5)<<endl;void main()Student s1,s2(2,'l','m',20,84,70);s1.set ();cout<<" 學(xué)生 1 的平均成績 "<<s1.average() <<endl; cout<<" 學(xué)生 2 的平均成績 "<<s2.average() <<
20、;endl;試驗(yàn) 6-1#include <iostream>using namespace std;const double PI=3.14;class Shapepublic:virtual void Show()=0;virtual void GetArea()=0;virtual void Set(float x,float y)=0;class Rectangle:public Shapeprivate:float Length,Width;float Area;public:Rectangle()Length=0;Width=0;Rectangle(float x,fl
21、oat y)Length=x;7/12.Width=y;void Show();void GetArea();void Set(float x,float y);void Rectangle:Show ()cout<<" 長為: "<<Length<<endl;cout<<" 寬為: "<<Width<<endl;cout<<" 面積為: "<<Area <<endl;void Rectangle:GetArea ()Area=
22、Length*Width;void Rectangle:Set (float x,float y)Length=x;Width=y;class Circle:public Shapeprivate:float x,y;float r;float area;public:Circle()x=0;y=0;r=0;Circle(float a,float b,float c)x=a;y=b;r=c;void Show();void GetArea();void Set(float x1,float y1);8/12.void Circle:Show ()cout<<" 圓心為:
23、 ("<<x<<","<<y<<")"<<endl;cout<<" 半徑為: "<<r<<endl;cout<<" 面積為: "<<area<<endl;void Circle:GetArea()area=PI*r*r;void Circle:Set (float x1,float y1)x=x1;y=y1;int main()Shape *p;Rectangle r1;Ci
24、rcle c1;p=&r1;p->GetArea ();p->Show ();p=&c1;p->GetArea ();p->Show ();return 0;試驗(yàn) 6-2#include <iostream.h>/using namespace std;class Pointprivate:int x;int y;public:Point()x=0;y=0;Point(int a,int b)9/12.x=a;y=b;Point operator+(Point &p1);Point operator-(Point &p1);P
25、oint operator+();Point operator+(int);Point operator-();Point operator-(int);friend istream &operator>>(istream &in,Point &p1);friend ostream &operator<<(ostream &out,Point &p1);Point Point:operator + (Point &p1)Point temp;temp.x =x+p1.x ;temp.y =y+p1.y;return
26、 temp;Point Point:operator - (Point &p1)Point temp;temp.x =x-p1.x ;temp.y =y-p1.y;return temp;Point Point:operator + ()x+;y+;return *this;Point Point:operator + (int)Point temp(*this);x+;y+;return temp;istream &operator>>(istream &in,Point &p1)in>>p1.x;in>>p1.y;retu
27、rn in;10/12.ostream &operator<<(ostream &out,Point &p1)out<<"("<<p1.x<<","<<p1.y<<")"<<endl;return out;int main()Point p1,p2; cin>>p1>>p2; cout<<p1+<<endl; cout<<+p2<<endl; cout<
28、;<p1+p2<<endl; cout<<p1-p2<<endl;return 0 ; /8_4.cpp#include <iostream>using namespace std;class B0 /基類 B0 聲明public:/外部接口virtual void display()/虛成員函數(shù) cout<<"B0:display()"<<endl; void display(int x)/ 同名重載函數(shù) cout<<"B0:display(int x)"<<endl; virtual void show(int x=0) cout<<"B0:show()"<<x<<e
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 種子行業(yè)競(jìng)爭(zhēng)格局與戰(zhàn)略選擇考核試卷
- 藤制品市場(chǎng)營銷渠道建設(shè)考核試卷
- 生物技術(shù)在食品安全生物技術(shù)檢測(cè)中的應(yīng)用考核試卷
- 豆類種植的農(nóng)業(yè)科技創(chuàng)新能力提升考核試卷
- 竹筍采集技術(shù)及其保鮮處理考核試卷
- 稻谷加工產(chǎn)品市場(chǎng)分析與預(yù)測(cè)考核試卷
- 呼吸窘迫護(hù)理
- 環(huán)保設(shè)備研發(fā)、生產(chǎn)、銷售、運(yùn)營與市場(chǎng)調(diào)研合同
- 培訓(xùn)活動(dòng)簡(jiǎn)報(bào)
- 節(jié)能減排技術(shù)標(biāo)準(zhǔn)共同制定與推廣合同
- 2024年內(nèi)蒙古呼和浩特中考化學(xué)真題卷及答案解析
- 2024年09月全國2024廈門國際銀行青年銀行家(分行市場(chǎng)類)校園招考筆試歷年參考題庫附帶答案詳解
- DB32∕T 3219-2017高速公路擴(kuò)建工程技術(shù)標(biāo)準(zhǔn)
- 保護(hù)環(huán)境的課件英文版
- 幼兒園講解海軍知識(shí)
- 2024年官方獸醫(yī)考試題庫及參考答案
- 慢性腎臟病肌少癥診斷治療與預(yù)防專家共識(shí)(2024年版)解讀
- 中建消防專項(xiàng)施工方案
- 污水處理工程的安全管理考核試卷
- 口腔正畸學(xué)??荚囶}+參考答案
- 2024年黑龍江齊齊哈爾市紀(jì)委監(jiān)委擇優(yōu)調(diào)入人員10人管理單位遴選500模擬題附帶答案詳解
評(píng)論
0/150
提交評(píng)論