版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上 第一章1-2#include<iostream>using namespace std;int main()double a,b,c;cout<<"請(qǐng)輸入長:"cin>>a; cout<<"請(qǐng)輸入寬:"cin>>b; cout<<"請(qǐng)輸入高:" cin>>c;double s,v;s=a*b*2+b*c*2+a*c*2;v=a*b*c;cout<<"長方體的表面積s="<<s<
2、;<endl;cout<<"長方體的體積v="<<v<<endl;return 0;1-7#include<iostream>#include<cmath>using namespace std;int main()double n,y;cout<<"請(qǐng)輸入n:"cin>>n;y=pow(1.0+1.0/n),n);cout<<"y="<<y<<endl;return 0;1-8#include<iost
3、ream>#include<cmath>using namespace std;int main()double x,y;cout<<"請(qǐng)輸入一個(gè)大于0的數(shù)x:"cin>>x;y=sin(x)-log(x)+sqrt(x)-5;cout<<"y="<<y<<endl;return 0;1-9#include<iostream>#include<cmath>using namespace std;int main()double x,y;cout<&
4、lt;"請(qǐng)輸入x:"cin>>x;if(x*x-3*x+2)<=0)return 1;elsey=x/(sqrt(x*x-3*x+2); cout<<"y="<<y<<endl;return 0; 第二章2-2#include <iostream>using namespace std;int main()double c,f;cout<<"請(qǐng)輸入一個(gè)攝氏溫度: "<<endl;cin>>c;f=9.0*c/5.0+32;cout&l
5、t;<"對(duì)應(yīng)于的華氏溫度為: "<<endl<<f<<endl;return 0;2-3#include<iostream>#include<cmath>using namespace std;int main()double x,y;cout<<"輸入x:"cin>>x;y=sin(x*x)/(1-cos(x);cout<<"y="<<y<<endl;return 0;2-5#include<iostr
6、eam>#include<cmath>using namespace std;int main()int m,n,k;double i,j;cout<<"請(qǐng)輸入三個(gè)整數(shù):"cin>>m>>n>>k;i=m+n+k;j=i/3;k=j+0.5;cout<<"和為:"<<i<<endl;cout<<"平均值為:"<<j<<endl;cout<<"平均值的四舍五入整數(shù)值:"
7、<<k<<endl;return 0;2-7#include <iostream>using namespace std;int main()char ch;for(int i=0;i<3;i+)cout<<"請(qǐng)輸入一個(gè)字母: "<<endl;cin>>ch;if(ch>='A'&&ch<='Z')ch=ch-'A'+'a'cout<<"大小寫轉(zhuǎn)換后為: "<<e
8、ndl<<ch<<endl;else if(ch>='a'&&ch<='z')ch=ch-'a'+'A'cout<<"大小寫轉(zhuǎn)換后為: "<<endl<<ch<<endl;elsech=ch;cout<<"大小寫轉(zhuǎn)換后為: "<<endl<<ch<<endl;return 0; 第三章3-4#include<iostream>#inc
9、lude<cmath>using namespace std;int main()double y,u;int i=1,n;cout<<"請(qǐng)輸入n:"cin>>n;if(n<0)cout<<"輸入不合法"<<endl;else if(n=0)cout<<"y="<<1<<endl;elsewhile(i<=n,i+)u=u*i;cout<<"y="<<u<<endl;ret
10、urn 0;3-5#include<iostream>using namespace std;int main()int u=0;int i=1;int n;int k=1;cout<<"請(qǐng)輸入n:"cin>>n;while(k<=n)u=u+i;i=i+2;k+;cout<<"和為:"<<u<<endl;return 0;3-10#include<iostream>#include<cmath>using namespace std;int main(
11、)double u=0,k=1,i=1;int n;cout<<"請(qǐng)輸入n:"cin>>n;while(i<=n)u=u+k;i=i+1;k=k*i;cout<<"結(jié)果為:"<<u<<endl;return 0;3-13#include<iostream>#include<cmath>using namespace std;int main()int a,n,k,u=0,i=1,j=1;cout<<"請(qǐng)輸入a,n:"cin>&g
12、t;a>>n;k=a;while(i<=n)u=u+k;k=k+10*j*a;j=j*10;i=i+1;cout<<"結(jié)果為:"<<u<<endl;return 0; 第四章4-1#include <iostream>using namespace std;int main()int M44=5,6,7,9,2,8,5,4,3,7,16,15,1,4,8,11,;int Mt44;int i,j;for(i=0;i<4;i+)for(j=0;j<4;j+)Mtij=Mji;cout<<
13、"矩陣a的轉(zhuǎn)置陣為:"<<endl;for(i=0;i<4;i+)for(j=0;j<4;j+)cout<<Mtij<<"t"cout<<endl;return 0;4-3#include <iostream>#include <cmath>using namespace std;int fac(int n)int result=1;while(n>1)result*=n;n=n-1;return result;int main()int n;cout<<
14、;"請(qǐng)輸入行數(shù):"<<endl;cin>>n;for(int l=0;l<n;l+)for(int m=0;m<=l;m+)cout<<fac(l)/(fac(m)*fac(l-m)<<"t"cout<<endl;return 0;4-7#include <iostream>#include <cstring>using namespace std;char * my(char * string)char * ptr=string;while(*ptr!=0)
15、ptr+;doptr-;while(*ptr=' ');*(+ptr)=0;return string;int main()char str100;cout<<"請(qǐng)輸入一個(gè)末尾帶空格的字符串"<<endl;cin.get(str,100);cout<<"截取前的原始字符串是:"<<endl<<""<<str<<""<<endl;cout<<"截取空格后的字符串是:"<
16、<endl;cout<<""<<my(str)<<""cout<<endl;return 0;4-8#include <iostream>#include <cstring>using namespace std;char *myltrim(char *string)char * ptr=string;while(*ptr=' ')ptr+;strcpy(string,ptr);return string;int main()char str100;cout&l
17、t;<"請(qǐng)輸入開頭帶空格的字符串"<<endl;cin.get(str,100);cout<<"截取前的原始字符串是:"<<endl<<""<<str<<""<<endl;cout<<"截取空格后的字符串是:"<<endl;cout<<""<<myltrim(str)<<""cout<<endl;
18、return 0; 第五章5-2#include <iostream>using namespace std;int main()char ch;for(int i=0;i<3;i+)cout<<"請(qǐng)輸入一個(gè)字母: "<<endl;cin>>ch;if(ch>='A'&&ch<='Z')ch=ch-'A'+'a'cout<<"大小寫轉(zhuǎn)換后為: "<<endl<<ch<&
19、lt;endl;else if(ch>='a'&&ch<='z')ch=ch-'a'+'A'cout<<"大小寫轉(zhuǎn)換后為: "<<endl<<ch<<endl;elsech=ch;cout<<"大小寫轉(zhuǎn)換后為: "<<endl<<ch<<endl;return 0;5-4#include <iostream>int GCD(int x, int y);int
20、 LCM(int x, int y, int z);int main(void)using namespace std;cout << "請(qǐng)輸入兩個(gè)正整數(shù):n"int x;int y;cout << "第一個(gè)正整數(shù):"cin >> x;cout << "第二個(gè)正整數(shù):"cin >> y;int G_CD = GCD(x, y);/ 最大公約數(shù)int L_CM = LCM(x, y, G_CD);/ 最小公倍數(shù) = 兩數(shù)乘積除以最大公約數(shù)cout << "
21、最大公約數(shù)是:" << G_CD << endl;cout << "最小公倍數(shù)是:" << L_CM << endl;return 0;int GCD(int x, int y)int z = x % y;while (z != 0)x = y;y = z;z = x % y;return y;int LCM(int x, int y, int z)return x * y / z;5-5#include<iostream>#include<cmath>using namespac
22、e std;int mtk(int n)int r,s,t,q;r=n/100;s=n%10;t=n%100;q=t/10;t=r+s+q;return t;int main()for(int i=201;i<1000;i+)if(mtk(i)=5)cout<<i<<endl;return 0;5-9#include<iostream>#include<cmath>using namespace std;bool is_prime(int n) if(n<2) return false; for (int i=2;i*i<=n;
23、i+) if(n % i = 0) return false; return true; int main() int n;cout<<"請(qǐng)輸入一個(gè)數(shù)n:" cin>>n; if (is_prime(n) cout<<"該數(shù)是一個(gè)素?cái)?shù)"<<endl; else cout<<"該數(shù)不是一個(gè)素?cái)?shù)"<<endl; return 0; 第六章6-5#include "stdio.h" int main() int m; char *months=&qu
24、ot;January","February","March","April","May","June","July","August","September","October","November","December" printf("Input Month:"); scanf("%d",&m); printf(&q
25、uot;The month is:%s",*(months+m-1);6-6#include <iostream>using namespace std;int main() char a20; int i=0; cout<<"請(qǐng)輸入一串字符:n" cin>>a; for(;ai;i+) if(ai>'a'&&ai<'z') ai-=32; else if(ai>'A'&&ai<'Z') ai+=32; for
26、(i=0;ai;i+) cout<<ai; cout<<endl; return 0; 6-7#include <iostream>using namespace std;int main()char str100;char *ptr=str;int total,capital,small,numeral,others;total=capital=small=numeral=others=0;cout<<"請(qǐng)輸入字符串:"<<endl;cin.get(ptr,100);while(*ptr!=0)total+;if
27、(*ptr>='A'&&*ptr<='Z')capital+;else if(*ptr>='a'&&*ptr<='z')small+;else if(*ptr>='0'&&*ptr<='9')numeral+;else others+;ptr+;cout<<"該字符串含有的大寫字母?jìng)€(gè)數(shù):"<<capital<<endl;cout<<"該字符
28、串含有的數(shù)字字符個(gè)數(shù):"<<small<<endl;cout<<"該字符串含有的其它字符個(gè)數(shù):"<<numeral<<endl;cout<<"該字符串含有的其它字符個(gè)數(shù):"<<others<<endl;cout<<"該字符串總共含有的字符個(gè)數(shù):"<<total<<endl;return 0;6-16#include <iostream>#include <cmath>us
29、ing namespace std;double integral(double a,double b,double (*fun)(double),int n)double h=(b-a)/n;double sum=(*fun)(a)+(*fun)(b)/2;int i; for(i=1;i<n;i+)sum+=(*fun)(a+i*h);sum*=h;return sum;double yici(double r)double y=r;return y;double erci(double s)double t=s*s;return t;double sanci(double u)do
30、uble v=u*u*u;return v;int main()double a=0,b=1;cout<<"sin(x)結(jié)果是"<<integral(a,b,sin,1000)<<endl;cout<<"x結(jié)果是"<<integral(a,b,erci,1000)<<endl;cout<<"x*x結(jié)果是"<<integral(a,b,yici,1000)<<endl;cout<<"x*x*x結(jié)果是"
31、;<<integral(a,b,sanci,1000)<<endl;cout<<"exp(x)結(jié)果是"<<integral(a,b,exp,1000)<<endl;return 0; 第七章7-1#include <iostream>#include <cstring>using namespace std;class Dogchar name20;int age;char sex;float weight;public:void Register(char * Name,int Age,c
32、har Sex,float Weight);char * GetName()return name;int GetAge()return age;char GetSex()return sex;float GetWeight()return weight;void Speak()cout<<"Arf!Arf!"<<endl;void Dog:Register(char * Name,int Age,char Sex,float Weight)strcpy(name,Name);age=Age;sex=Sex;weight=Weight;int mai
33、n()char name20,sex;int age;float weight;Dog dog1;cout<<"Please input name, age, sex and weight"<<endl;cin>>name>>age>>sex>>weight;dog1.Register(name,age,sex,weight);cout<<"Dogs name:"<<dog1.GetName()<<endl;cout<<"Do
34、gs age:"<<dog1.GetAge()<<endl;cout<<"Dogs sex:"<<dog1.GetSex()<<endl;cout<<"Dogs weight:"<<dog1.GetWeight()<<endl;cout<<"Dog speak:"dog1.Speak();return 0;7-2#include <iostream>using namespace std;const dou
35、ble pi=3.14;class Circlepublic:void set();void show(); double circumference();double area();private:int x,y;double r;void Circle:set()cout<<"請(qǐng)輸入圓心坐標(biāo)和圓的半徑"<<endl;cin>>x;cin>>y;cin>>r;void Circle:show()cout<<"該圓為"<<endl;cout<<"圓心
36、("<<x<<","<<y<<")"<<endl;cout<<"半徑"<<r<<endl; double Circle:circumference()return 2*pi*r;double Circle:area()return pi*r*r;int main()Circle c;c.set();c.show();cout<<"圓的周長為"<<c.circumference()<
37、<endl;cout<<"圓的面積為"<<c.area()<<endl;return 0;7-4#include <iostream> using namespace std;class Addresschar Name30;char StreetAddress30;char City30;char Postcode30; public:Address(char*a,char*b,char*c,char*d)strcpy(Name,a); strcpy(StreetAddress,b); strcpy(City,c);
38、strcpy(Postcode,d);void Changename(char*a)strcpy(Name,a);void Display()cout<<Name<<"address:"<<endl;cout<<Postcode<<" "<<City<<" "<<StreetAddress<<endl;int main()char name30;char streetaddress30;char city30;char post
39、code30;cin>>name>>streetaddress>>city>>postcode;Address x(name,streetaddress,city,postcode);x.Display();cin>>name;x.Changename(name);x.Display();return 0;7-5class Point3Ddouble x,y,z;public:point3D(double _x,double _y,double _z) x=_x; y=_y; z=_z;Point3D() double Distanc
40、e(Point3D &p) double a=p.x; double b=p.y; double c=p.z;return sqrt(x-a)*(x-a)+(y-b)*(y-b)+(z-c)*(z-c);int main()double x,y,z,a,b,c;cin>>x>>y>>z>>a>>b>>c;Point3D point1(x,y,z);Point3D point2(a,b,c);cout<<point1.Distance(point2)<<endl;return 0; 第八章8-
41、1#include <iostream> using namespace std;class Pointpublic:int x, y; Point( int a= 0, int b= 0 )x=a;y=b;class ColorPoint : public Pointint r, g, b;public:ColorPoint(int a,int bb,int c,int d,int e):Point(a,bb)r=c;g=d;b=e;void Print()cout<<"x,y="<<x<<","<
42、<y<<endl;cout<<"r*256*256+g*256+b="<<r*256*256+g*256+b<<endl;int main()int a,b,c,d,e;cin>>a>>b>>c>>d>>e;ColorPoint x(a,b,c,d,e);x.Print();return 0;8-2class Personstring ID; /身份證號(hào)string Name; /姓名string Sex; /性別int Age; /年齡public:Perso
43、n(string id, string name, string sex, int age)ID= id;Name= name;Sex= sex;Age= age;virtual void display()cout<<"身份證號(hào):"<<ID<<endl;cout<<"姓名:"<<Name<<endl;cout<<"性別:"<<Sex<<endl;cout<<"年齡:"<<Age<
44、;<endl;class teacher:public Personstring Major; /專業(yè)string Title; /職稱string Course; /主講課程public:teacher(string id, string name, string sex, int age, string major, string title, string course):Person(id,name,sex,age)Major=major;Title=title;Course=course;virtual void display()Person:display();cout&l
45、t;<"專業(yè):"<<Major<<endl;cout<<"職稱:"<<Title<<endl;cout<<"主講課程:"<<Course<<endl;int main()string id,name,sex,major,title,course;int age;cin>>id>>name>>sex>>age>>major>>title>>course;
46、teacher x(id,name,sex,age,major,title,course);x.display();return 0;8-3class truck:public vehicledouble Passenger_load; /載人數(shù)double Payload; /載重量public:truck(double wheels, double weight, double passenger_load, double payload):vehicle(wheels,weight)Passenger_load=passenger_load;Payload=payload;virtual
47、 void Display()vehicle:Display();cout<<"載人數(shù):"<<Passenger_load<<endl;cout<<"載重量:"<<Payload<<endl;int main()double wheels1, weight1, passenger_load1;double wheels2, weight2, passenger_load2, payload;cout<<"輸入小車參數(shù)"<<endl;cin&
48、gt;>wheels1>>weight1>>passenger_load1;car c(wheels1, weight1, passenger_load1);c.Display();cout<<"輸入卡車參數(shù)"<<endl;cin>>wheels2>>weight2>>passenger_load2>>payload;truck t(wheels2, weight2, passenger_load2, payload);t.Display();return 0;8-6cla
49、ss Ellispedouble x, y; /圓心坐標(biāo)double semi_major_axis; /半長軸double semi_minor_axis; /半短軸public:Ellispe(double X, double Y, double Semi_major_axis, double Semi_minor_axis)x=X;y=Y;semi_major_axis=Semi_major_axis;semi_minor_axis=Semi_minor_axis;void Display()cout<<"圓心坐標(biāo)為"<<x<<&q
50、uot; "<<y<<endl;cout<<"面積為"<<area()<<endl;double area()return pi*semi_major_axis*semi_minor_axis;int main()double x, y, semi_major_axis, semi_minor_axis;double areas;cin>>x>>y>>semi_major_axis>>semi_minor_axis;Ellispe e(x, y, semi_
51、major_axis, semi_minor_axis);e.Display();return 0; 第九章9-1class Mammalpublic:virtual void Speak()cout<<"I am a mammal."<<endl;class Dog:public Mammalpublic:virtual void Speak()cout<<"I am a dog."<<endl;int main()Mammal ma1,*p;Dog dog1;p=&ma1;p->Speak
52、();p=&dog1;p->Speak();return 0;9-3class Motorprotected: int number_person;int number_tyre;int horsepower;char manufacturers30;char owner30;public:Motor(int _number_person,int _number_tyre,int _horsepower,char *_manufacturers,char *_owner)number_person=_number_person;number_tyre=_number_tyre;h
53、orsepower=_horsepower;strcpy(manufacturers,_manufacturers);strcpy(owner,_owner);virtual void Display()cout<<"number_person:"<<number_person<<endl;cout<<"number_tyre:"<<number_tyre<<endl;cout<<"horsepower:"<<horsepower<&
54、lt;endl;cout<<"manufacturers:"<<manufacturers<<endl;cout<<"owner:"<<owner<<endl;class Car:public Motorpublic:Car(int _number_person,int _number_tyre,int _horsepower,char *_manufacturers,char *_owner):Motor(_number_person, _number_tyre, _horsepo
55、wer,_manufacturers,_owner)void Display()cout<<"I am a Car"<<endl;Motor:Display();class Bus:public Motorint number;public:Bus(int _number_person,int _number_tyre,int _horsepower,char *_manufacturers,char *_owner,int _number):Motor(_number_person, _number_tyre, _horsepower,_manuf
56、acturers,_owner)number=_number;void Display()cout<<"I am a Bus"<<endl;Motor:Display();cout<<"number:"<<number<<endl;class Bus:public Motorint number;public:Bus(int _number_person,int _number_tyre,int _horsepower,char *_manufacturers,char *_owner,int
57、_number):Motor(_number_person, _number_tyre, _horsepower,_manufacturers,_owner)number=_number;void Display()cout<<"I am a Bus"<<endl;Motor:Display();cout<<"number:"<<number<<endl;class Truck:public Motorint weight;public:Truck(int _number_person,int
58、_number_tyre,int _horsepower,char *_manufacturers,char *_owner,int _weight) :Motor(_number_person, _number_tyre, _horsepower,_manufacturers,_owner)weight=_weight;void Display()cout<<"I am a Truck"<<endl;Motor:Display();cout<<"weight:"<<weight<<endl;i
59、nt main()Motor *p;int number_person,number_tyre,horsepower,number,weight;char manufacturers30;char owner30;cin>>number_person>>number_tyre>>horsepower>>manufacturers>>owner;Car car(number_person,number_tyre,horsepower,manufacturers,owner);p=&car;p->Display();cin&
60、gt;>number;Bus bus(number_person,number_tyre,horsepower,manufacturers,owner,number);p=&bus;p->Display();cin>>weight;Truck truck(number_person,number_tyre,horsepower,manufacturers,owner,weight);p=&truck;p->Display();return 0;9-4#include<iostream>#include<cmath>using
61、 namespace std;const double PI=3.;class Shapepublic:virtual double CalculateArea()=0;virtual double CalculatePerim()=0;virtual void Display()cout<<"Area:"<<CalculateArea()<<endl;cout<<"Perim:"<<CalculatePerim()<<endl;class Square:public Shapedouble edge;public:Square(
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2134電大成本會(huì)計(jì)歷年真題及答案
- 彩妝知識(shí)培訓(xùn)課件圖片
- 2024食品配料研發(fā)實(shí)驗(yàn)室員工保密條款合同范本3篇
- 2025年度企業(yè)IT運(yùn)維外包服務(wù)及數(shù)據(jù)備份恢復(fù)合同3篇
- 福建省南平市嵐下中學(xué)2020年高三英語期末試卷含解析
- 2024瓷磚經(jīng)銷商墻地磚銷售合同
- 2024年小班區(qū)域教案
- 2025年度交通安全責(zé)任協(xié)議范本3篇
- 2024鋁材行業(yè)信息化建設(shè)與數(shù)據(jù)共享合同3篇
- 2024高層次人才聘用協(xié)議書
- 2025年湖北武漢工程大學(xué)招聘6人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2024-2025學(xué)年北京房山區(qū)初三(上)期末英語試卷
- 2024年三年級(jí)英語教學(xué)工作總結(jié)(修改)
- 【數(shù) 學(xué)】2024-2025學(xué)年北師大版數(shù)學(xué)七年級(jí)上冊(cè)期末能力提升卷
- 遼寧省沈陽市皇姑區(qū)2024-2025學(xué)年九年級(jí)上學(xué)期期末考試語文試題(含答案)
- 咖啡廳店面轉(zhuǎn)讓協(xié)議書
- 期末(試題)-2024-2025學(xué)年人教PEP版英語六年級(jí)上冊(cè)
- 鮮奶購銷合同模板
- 泰山產(chǎn)業(yè)領(lǐng)軍人才申報(bào)書
- 封條模板A4直接打印版
- 水運(yùn)工程質(zhì)量檢驗(yàn)標(biāo)準(zhǔn)(JTS_257-2008)附表格
評(píng)論
0/150
提交評(píng)論