九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOC文檔下載  

《面向?qū)ο蟪绦蛟O(shè)計(jì)》答案.doc

  • 資源ID:8107377       資源大?。?span id="24d9guoke414" class="font-tahoma">116.50KB        全文頁數(shù):20頁
  • 資源格式: DOC        下載積分:9.9積分
快捷下載 游客一鍵下載
會(huì)員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺(tái)登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要9.9積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機(jī)號(hào),方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
支付方式: 支付寶    微信支付   
驗(yàn)證碼:   換一換

 
賬號(hào):
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請(qǐng)使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請(qǐng)知曉。

《面向?qū)ο蟪绦蛟O(shè)計(jì)》答案.doc

實(shí)驗(yàn)一 熟悉VC+IDE開發(fā)環(huán)境一、實(shí)驗(yàn)?zāi)康?、熟悉VC+6.0集成開發(fā)環(huán)境,熟練掌握VC+6.0項(xiàng)目工作區(qū)、各種編輯器、菜單欄和工具欄的使用。2、掌握如何編輯、編譯、連接和運(yùn)行一個(gè)C+程序。3、通過運(yùn)行簡單的C+程序,初步了解C+源程序的結(jié)構(gòu)和特點(diǎn)。二、實(shí)驗(yàn)要求1、分析下列程序運(yùn)行的結(jié)果。程序一:#include <iostream.h>int add(int x,int y=8);void main() int x=4; cout<<add(x)<<"," cout<<add(x,add(add(x,add(x)<<endl;int add(int x,int y) return x+y;/12,28程序二:#include <iostream.h>void main()int *p,i; i=5;p=&i;i=*p+10;cout<<"i="<<i<<endl;/i=15程序三:#include <iostream.h> void main(void)int i=10;int &r=i; r+;cout<<"i="<<i<<", r="<<r<<n;i=88; cout<<"i="<<i<<", r="<<r<<n;/i=11,r=11i=88,r=88程序四:#include <iostream.h> int f(int i) static int k=1; for(;i>0;i-) k +=i; return k; void main() int i; for(i=0;i<5;i+) cout<<f(i)<<" " / 1 2 5 11 21程序五:#include <iostream.h>void func();int n=1; void main() static int a; int b= -9; cout <<"a:"<<a<<" b:"<<b<<" n:" <<n<<endl;b+=4; func();cout <<"a:"<<a<<" b:"<<b<<" n:"<<n<<endl;n+=10; func();void func() static int a=2; int b=5; a+=2;n+=12;b+=5; cout <<"a:" <<a<<" b:" <<b<<" n:" <<n <<endl; / a:0 b:-9 n:1a:4 b:10 n:13a:0 b:-5 n:13a:6 b:10 n:35實(shí)驗(yàn)二 C+對(duì)C的擴(kuò)充一、實(shí)驗(yàn)?zāi)康?、了解在面向?qū)ο蟪绦蛟O(shè)計(jì)過程中C+對(duì)C功能的擴(kuò)充與增強(qiáng),并善于在編寫程序的過程中應(yīng)用這些新功能。2、進(jìn)一步熟悉編輯、編譯、連接和運(yùn)行C+程序的方法。3、進(jìn)一步熟悉C+程序的結(jié)構(gòu)和編程方法。二、實(shí)驗(yàn)要求1、分析下列程序運(yùn)行的結(jié)果。#include <iostream.h>int amount=123; void main()int amount=456; cout<<:amount<<,; cout<<amount<<,; :amount=789; cout<<:amount<<,; cout<<amount<<n; / 123,456,789,4562、編寫一個(gè)程序,用來求2個(gè)或3個(gè)正整數(shù)中的最大數(shù)。用不帶默認(rèn)參數(shù)的函數(shù)實(shí)現(xiàn)。include <iostream>using namespace std;int max(int a,int b,int c) /求3個(gè)整數(shù)中的最大者if (b>a) a=b; if (c>a) a=c; return a; int max(int a, int b) /求兩個(gè)整數(shù)中的最大者if (a>b) return a; else return b;int main( )int a=7,b=-4,c=9; cout<<max(a,b,c)<<endl; /輸出3個(gè)整數(shù)中的最大者 cout<<max(a,b)<<endl; /輸出兩個(gè)整數(shù)中的最大者 return 0;用帶默認(rèn)參數(shù)的函數(shù)實(shí)現(xiàn)。#include <iostream>using namespace std;int main()int max(int a,int b,int c=0); int a,b,c; cin>>a>>b>>c; cout<<"max(a,b,c)="<<max(a,b,c)<<endl; cout<<"max(a,b)="<<max(a,b)<<endl; return 0;int max(int a,int b,int c)if(b>a) a=b; if(c>a) a=c; return a;3、有5個(gè)字符串,要求對(duì)它們按由小到大順序排列,用string方法。#include <iostream>#include <string>using namespace std;int main() int i; string str5="BASIC","C","FORTRAN","C+","PASCAL" void sort(string ); sort(str); cout<<"the sorted strings :"<<endl; for(i=0;i<5;i+) cout<<stri<<" " cout<<endl; return 0;void sort(string s)int i,j; string t; for (j=0;j<5;j+) for(i=0;i<5-j;i+) if (si>si+1) t=si;si=si+1;si+1=t; 4、定義一個(gè)求兩個(gè)數(shù)中較小值的函數(shù)模板min( ),要求在main( )函數(shù)中進(jìn)行調(diào)用求兩個(gè)浮點(diǎn)型數(shù)據(jù)和兩個(gè)整型數(shù)據(jù)中較小的數(shù)。#include "iostream"#include "string"using namespace std;template<typename T>T min(T a,T b) return a<b?a:b;int main() int a=1, b=9; float c=1.23471,d=32.431564; cout<<"The min of "<<a<<" and "<<b<<" is "<<min(a,b)<<endl <<"The min of "<<c<<" and "<<d<<" is "<<min(c,d)<<endl; return 0;實(shí)驗(yàn)三 類和對(duì)象(一)一、實(shí)驗(yàn)?zāi)康?、掌握聲明類的方法,類和類的成員的概念以及定義對(duì)象的方法。2、掌握類的構(gòu)造函數(shù)與析構(gòu)函數(shù)的概念和使用方法。3、初步掌握用類和對(duì)象編制基于對(duì)象的程序。二、實(shí)驗(yàn)要求1、分析下面的程序,寫出其運(yùn)行時(shí)的輸出結(jié)果。#include <iostream>using namespace std;class Datepublic:Date(int,int,int);Date(int,int);Date(int);Date( );void display( );private:int month;int day;int year;DateDate(int m,int d,int y):month(m),day(d),year(y) DateDate(int m,int d):month(m),day(d) year=2005; DateDate(int m):month(m) day=1;year=2005;DateDate( ) month=1;day=1;year=2005;void Datedisplay( )cout<<month<</<<day<</<<year<<endl;int main( ) Date d1(10,13,2005);Date d2(12,30);Date d3(10);Date d4;d1.display( );d2.display( );d3.display( );d4.display( );return 0;/ 10/13/2005 12/30/2005 10/1/2005 1/1/20052、建立一個(gè)名為Student的類,該類有以下幾個(gè)私有成員變量:學(xué)生姓名、學(xué)號(hào)、性別、年齡。還有以下兩個(gè)成員變量:一個(gè)用于初始化學(xué)生姓名、學(xué)號(hào)、性別和年齡的構(gòu)造函數(shù),一個(gè)用于輸出學(xué)生信息的函數(shù)。編寫一個(gè)主函數(shù),聲明一個(gè)學(xué)生對(duì)象,然后調(diào)用成員函數(shù)在屏幕輸出學(xué)生信息。#include "iostream"#include "string"using namespace std;class student public: student(); void display(); private: string sName,sNum; char chSex; int iAge;student:student(string na,string num,char s,int a):sName(na),sNum(num), chSex(s),iAge(a)void student:display() cout << "-THE INFORMATION OF STUDENT-n" cout << "name: "<< sName << endl << "number: "<< sNum<<endl << "sex: "<< chSex << endl << "age: "<< iAge <<endl;int main() student s("WangFang","0811045263",w,20); s.display(); return 0;3、類Person的定義如下,請(qǐng)實(shí)現(xiàn)該類,并在主函數(shù)中創(chuàng)建對(duì)象obj,然后使用構(gòu)造函數(shù)為obj賦予初始值(內(nèi)容自定)。class Person private: char name10; int age; int salary; char tel8;public: Person(char *xname,int xage,int xsalary,char *xtel); void disp();解:#include <iostream.h>#include <string.h>Person:person(char *Xname,int Xage,int Xsalary,char *Xtel) strcpy ( name, xname);age=xage;salary=xsalary;strcpy (tel,xtel);void Person:disp() cout<<“ 姓名:”<<name<<endl;cout<<“ 年齡”:<<age<<endl;cout<<“ 工資”:<<salary<<endl:cout<<“ 電話”:<<tel<<endl;void main() Person obj (“張三”,25,850,“45678912”); obj.disp()實(shí)驗(yàn)四 類和對(duì)象(二)一、實(shí)驗(yàn)?zāi)康?、進(jìn)一步加深對(duì)類和對(duì)象的理解。2、掌握對(duì)類的對(duì)象數(shù)組、對(duì)象的指針及其使用方法。3、掌握友元的概念和使用。4、了解類模板的使用方法。二、實(shí)驗(yàn)要求1、分析并比較下列程序運(yùn)行的結(jié)果。程序一:#include<iostream.h>#include<iostream.h>class smallonepublic:smallone(int sma) cout<<"sm constr:"<<sma<<"n"void fn(int n) smallone sm(n);cout<<"in function fn with n="<<n<<endl;int main() fn(10); fn(20); return 0;/sm constr: 10in function fn with n=10sm constr: 20in function fn with n=20程序二:#include<iostream.h>#include<iostream.h>class smallonepublic:smallone(int sma) cout<<"sm constr:"<<sma<<"n"void fn(int n) static smallone sm(n);cout<<"in function fn with n="<<n<<endl; int main() fn(10); fn(20); return 0;/sm constr:10in function fn with n=10in function fn with n=202、建立一個(gè)對(duì)象數(shù)組,內(nèi)放5個(gè)學(xué)生的數(shù)據(jù)(學(xué)號(hào)、成績),設(shè)立一個(gè)函數(shù)max,用指向?qū)ο蟮闹羔樧骱瘮?shù)參數(shù),在max函數(shù)中找出5個(gè)學(xué)生中成績最高者,并輸出其學(xué)號(hào)。#include <iostream>using namespace std;class Student public: Student(int n,float s):num(n),score(s) int num; float score; ;void main()Student stud5= Student(101,78.5),Student(102,85.5),Student(103,98.5), Student(104,100.0),Student(105,95.5); void max(Student* ); Student *p=&stud0; max(p); reyurn 0; void max(Student *arr)float max_score=arr0.score; int k=0; for(int i=1;i<5;i+) if(arri.score>max_score) max_score=arri.score;k=i; cout<<arrk.num<<" "<<max_score<<endl; 3、聲明一個(gè)類模板,利用它分別實(shí)現(xiàn)兩個(gè)整數(shù)、浮點(diǎn)數(shù)和字符的比較,求出大數(shù)和小數(shù)。#include <iostream>using namespace std;template<class numtype>class Compare public: Compare(numtype a,numtype b) x=a;y=b; numtype max() return (x>y)?x:y; numtype min() return (x<y)?x:y; private: numtype x,y; ;int main()Compare<int> cmp1(3,7); cout<<cmp1.max()<<" is the Maximum of two inteder numbers."<<endl; cout<<cmp1.min()<<" is the Minimum of two inteder numbers."<<endl<<endl; Compare<float> cmp2(45.78,93.6); cout<<cmp2.max()<<" is the Maximum of two float numbers."<<endl; cout<<cmp2.min()<<" is the Minimum of two float numbers."<<endl<<endl; Compare<char> cmp3(a,A); cout<<cmp3.max()<<" is the Maximum of two characters."<<endl; cout<<cmp3.min()<<" is the Minimum of two characters."<<endl; return 0;實(shí)驗(yàn)五 運(yùn)算符重載一、實(shí)驗(yàn)?zāi)康?、進(jìn)一步了解運(yùn)算符重載的概念和使用方法。2、掌握幾種常用的運(yùn)算符重載的方法。二、實(shí)驗(yàn)要求1、定義一個(gè)復(fù)數(shù)類Complex,重載運(yùn)算法“+”,使之能用于復(fù)數(shù)的加法運(yùn)算。將運(yùn)算符重載為普通函數(shù)(非成員、非友元)、成員函數(shù)、友元函數(shù)。根據(jù)要求修改通過函數(shù)來實(shí)現(xiàn)復(fù)數(shù)相加的示例,分別編寫程序,求兩個(gè)復(fù)數(shù)之和。#include <iostream>using namespace std;class Complex /定義Complex類public: Complex(float x=0,float y=0)real=x;imag=y; /構(gòu)造函數(shù) Complex complex_add(Complex &c2); /聲明復(fù)數(shù)相加函數(shù) void display() cout<<real<<+<<imag<<i<<endl; ; private: float real; /實(shí)部 float imag; /虛部;Complex Complex:complex_add(Complex &c2) Complex c;c.real = real +c2.real;c.imag=imag+c2.imag;return c;int main() Complex complex1(3.34f, 4.8f), complex2(12.8f, 5.2f);Complex complex; /定義3個(gè)復(fù)數(shù)對(duì)象complex=complex1.complex_add(complex2); / 進(jìn)行兩個(gè)復(fù)數(shù)的加運(yùn)算complex.display( ); return 0;/16.14+10i/普通函數(shù)(非成員、非友元)#include <iostream>using namespace std;class Complex public: Complex()real=0;imag=0; Complex(double r,double i)real=r;imag=i; double get_real(); double get_imag(); void display(); private: double real; double imag; ; double Complex:get_real()return real;double Complex:get_imag()return imag;void Complex:display()cout<<"("<<real<<","<<imag<<"i)"<<endl;Complex operator + (Complex &c1,Complex &c2) return Complex(c1.get_real()+c2.get_real(),c1.get_imag()+c2.get_imag();int main()Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; cout<<"c3=" c3.display(); return 0; /運(yùn)算符重載為成員函數(shù)#include <iostream>using namespace std;class Complex public: Complex()real=0;imag=0; Complex(double r,double i)real=r;imag=i; Complex operator + (Complex &c2); void display(); private: double real; double imag; ;Complex Complex:operator + (Complex &c2)Complex c; c.real=real+c2.real; c.imag=imag+c2.imag;return c;void Complex:display()cout<<"("<<real<<","<<imag<<"i)"<<endl;int main()Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; cout<<"c1="c1.display(); cout<<"c2="c2.display(); cout<<"c1+c2="c3.display(); return 0;/將運(yùn)算符重載為友元函數(shù)#include <iostream>using namespace std;class Complex public: Complex()real=0;imag=0; Complex(double r)real=r;imag=0; Complex(double r,double i)real=r;imag=i; friend Complex operator+ (Complex &c1,Complex &c2); void display(); private: double real; double imag; ;Complex operator+ (Complex &c1,Complex &c2) return Complex(c1.real+c2.real, c1.imag+c2.imag);void Complex:display()cout<<"("<<real<<","<<imag<<"i)"<<endl;int main()Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; cout<<"c1=" c1.display(); cout<<"c2=" c2.display(); cout<<"c1+c2=" c3.display(); return 0;實(shí)驗(yàn)六 繼承和派生一、實(shí)驗(yàn)?zāi)康?、了解繼承在面向?qū)ο蟪绦蛟O(shè)計(jì)中的重要作用。2、進(jìn)一步理解繼承與派生的概念。3、掌握通過繼承派生出一個(gè)新的類的方法。4、了解虛基類的作用和用法。二、實(shí)驗(yàn)要求1、運(yùn)行程序,分析構(gòu)造函數(shù)與析構(gòu)函數(shù)的調(diào)用順序。程序一:#include <iostream.h>class A public: A()cout<<"A:Constructor"<<endl;A()cout<<"A:Destructor" <<endl;class B:public A public: B()cout<<"B:Constructor" <<endl; B()cout<<"B:Destructor"<<endl;void main() B b;/A:ConstructorB:ConstructorB:DestructorA:Destructor程序二:#include <iostream.h>class A int a;public :A(int aa=0) a=aa; A() cout<<”Destructor A!”<<a<<endl; ;class B: public A int b;public: B(int aa=0, int bb=0) : A(aa) b=bb; B() cout<<”Destructor B!”<<b<<endl; ;void main() B x(5),y(6,7);/Destructor B!7Destructor A!6Destructor B!0Destructor A!5調(diào)用順序:構(gòu)造x.A a=5 構(gòu)造x.B a=5 b=0 構(gòu)造y.A / 不匹配,不調(diào)用A() 構(gòu)造y.B a=6 b=7 析構(gòu)y.B B!7 析構(gòu)y.A A!6 析構(gòu)x.B B!0 析構(gòu)x.A A!52、分別聲明Teacher(教師)類和Cadre(干部)類,采用多重繼承方式由這兩個(gè)類派生出新類Teacher_Cader類。要求:在兩個(gè)基類種豆包含姓名、年齡、性別、地址、電話等數(shù)據(jù)成員。在Teacher類中還包含數(shù)據(jù)成員title(職稱),在Cader 類中還包含數(shù)據(jù)成員post(職務(wù))。在Teacher_Cader類中還包含數(shù)據(jù)成員wages(工資)。在對(duì)兩個(gè)基類中的姓名、年齡、性別、地址、電話等數(shù)據(jù)成員用相同的名字,在引用這些數(shù)據(jù)成員時(shí),指定作用域。在類體中聲明成員函數(shù),在類外定義數(shù)據(jù)成員。在派生類Teacher_Cader的成員函數(shù)show中調(diào)用Teacher類中的display函數(shù),輸出姓名、年齡、性別、職稱、地址、電話,然后再調(diào)用cout語句輸出職務(wù)和工資。#include<string>#include <iostream>using namespace std;class Teacher public: Teacher(string nam,int a,char s,string tit,string ad,string t); void display(); protected: string name; int age; char sex; string title; string addr; string tel;Teacher:Teacher(string nam,int a,char s,string tit,string ad,string t): name(nam),age(a),sex(s),title(tit),addr(ad),tel(t) void Teacher:display() cout<<"name:"<<name<<endl; cout<<"age"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"title:"<<title<<endl; cout<<"address:"<<addr<<endl; cout<<"tel:"<<tel<<endl; class Cadre public: Cadre(string nam,int a,char s,string p,string ad,string t); void display(); protected: string name; int age; char sex; string post; string addr; string tel; ; Cadre:Cadre(string nam,int a,char s,string p,string ad,string t): name(nam),age(a),sex(s),post(p),addr(ad),tel(t) void Cadre:display() cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"post:"<<post<<endl; cout<<"address:"<<addr<<endl; cout<<"tel:"<<tel<<endl; class Teacher_Cadre:public Teacher,public Cadre public: Teacher_Cadre(string nam,int a,char s,string tit,string p,string ad,string t,float w); void show( ); private: float wage; ; Teacher_Cadre:Teacher_Cadre(string nam,int a,char s,string t,string p,string ad,string tel,float w): Teacher(nam,a,s,t,ad,tel),Cadre(nam,a,s,p,ad,tel),wage(w) void Teacher_Cadre:show( ) Teacher:display(); cout<<"post:"<<Cadre:post<<endl; cout<<"wages:"<<wage<<endl; int main( ) Teacher_Cadre te_ca("Wang-li",50,f,"prof.","president","135 Beijing Road,Shanghai","(021)61234567",1534.5); te_ca.show( ); return 0;實(shí)驗(yàn)七 多態(tài)性和虛函數(shù)一、實(shí)驗(yàn)?zāi)康?、了解多態(tài)性的概念。2、了解虛函數(shù)的作用及其使用方法。3、了解靜態(tài)關(guān)聯(lián)和動(dòng)態(tài)關(guān)聯(lián)的概念和用法。4、了解純虛函數(shù)和抽象類的概念和用法。二、實(shí)驗(yàn)要求1、分析程序運(yùn)行結(jié)果,掌握虛函數(shù)的使用。程序一:#include <iostream.h>class ONE public: virtual void f()cout<<"l"<<endl;class TWO:public ONE public: TWO()cout<<"2"<<endl;class THREE:public TWO public: virtual void f()TWO:f(); cout<<"3"void main() ONE aa, *p; TWO bb; THREE cc; p = &cc; p->f();/2213程序二:#include<iostream.h>class Base public:virtual void fn() cout <<"In Base Classn"class SubClass :public Base public: virtual void fn() cout <<"In Sub Classn" ;void main() Base bc,*p;SubClass sc;p=&bc; p->fn();p=&sc; p->fn();/In Base ClassIn Sub Class2、實(shí)現(xiàn)一個(gè)類A,在A中有兩個(gè)私有的整型變量a和b,定義構(gòu)造函數(shù)對(duì)a和b進(jìn)行初始化,并實(shí)現(xiàn)成員函數(shù)geta()取得a的值和getb()取b的值。實(shí)現(xiàn)類B從A繼承,覆蓋geta(),使其返回a的2倍。主函數(shù)中聲明類B對(duì)象,調(diào)用類B中的geta()并將結(jié)果輸出。#include "iostream"using namespace std;class A private: int a; int b; public: A(int m,int n) a=m;b=n; int geta() return a; int getb() return b;class B :public A public: B(int m,int n):A(m,n) int geta() return A:geta()*2;void main() B b(2,2); cout << b.geta() << endl; return 0;3、聲明抽象基類Shape,由它派生出3個(gè)派生類:Cirle(圓形)、Rectangle(矩形)、Triangle(三角形),用一個(gè)函數(shù)printArea分別輸出以上三者的面積,3個(gè)圖形的數(shù)據(jù)在定義對(duì)象是給定。#include <iostream>using namespace std;/定義抽象基類Shapeclass Shapepublic: virtual double area() const =0; /純虛函數(shù);/定義Circle類class Circle:public Shapepublic:Circle(double r):radius(r) /結(jié)構(gòu)函數(shù) virtual double area() const return 3.14159*radius*radius; /定義虛函數(shù) protected: double radius; /半徑;/定義Rectangle類class Rectangle:public Shapepublic: Rectangle(double w,double h):width(w),height(h) /結(jié)構(gòu)函數(shù) virtual double area() const return width*height; /定義虛函數(shù) protected: double width,height; /寬與高;class Triangle:public Shapepublic: Triangle(double w,double h):width(w),height(h) /結(jié)構(gòu)函數(shù) virtual double area() const return 0.5*width*height; /定義虛函數(shù) protected: double width,height; /寬與高;/輸出面積的函數(shù)void printArea(const Shape &s)cout<<s.area()<<endl; /輸出s的面積int main() Circle circle(12.6); /建立Circle類對(duì)象circle cout<<"area of circle =" printArea(circle); /輸出circle的面積 Rectangle rectangle(4.5,8.4); /建立Rectangle類對(duì)象rectangle cout<<"area of rectangle =" printArea(rectangle); /輸出rectangle的面積 Triangle triangle(4.5,8.4); /建立Triangle類對(duì)象 cout<<"area of triangle =" printArea(triangle); /輸出triangle的面積 return 0;實(shí)驗(yàn)八 輸入輸出流和C+工具一、實(shí)驗(yàn)?zāi)康?、深入理解C+的輸入輸出的含義與其實(shí)現(xiàn)方法,2、掌握標(biāo)準(zhǔn)輸入輸出流的應(yīng)用,包括格式輸入輸出。3、學(xué)會(huì)使用C+的異常處理機(jī)制進(jìn)行程序的調(diào)試。二、實(shí)驗(yàn)要求1、輸入三角形的三邊a,b,c,計(jì)算三角形的面積的公式是area=s=構(gòu)成三角形的條件是:a+b>c, b+c>a, c+a>b編寫程序,輸入a,b,c,檢查a,b,c是否滿足以上條件,如不滿足,由cerr輸出有關(guān)出錯(cuò)信息。#include <iostream>#include <cmath>using namespace std;int main()double a,b,c,s,area; cout<<"please input a,b,c:" cin>>a>>b>>c; if (a+b<=c) cerr<<"a+b<=c,error!"<<endl; else if(b+c<=a) cerr<<"b+c<=a,error!"<<endl; else if (c+a<=b) cerr<<"c+a<=b,error!"<<endl; else s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c); cout<<"area="<<area<<endl; return 0;2、編程序,在顯示屏上顯示一個(gè)由字母B組成的三角形。#include <iostream>#include <iomanip>using namespace std;int main() for(int n=1;n<8;n+) cout<<setw(20-n)<<setfill( )<<" " <<setw(2*n-1)<<setfill(B)<<"B"<<endl; return 0;3、求一元二次方程式ax2+bx+c=0的實(shí)根,如果方程沒有實(shí)根,則輸出有關(guān)警告信息。#include <iostream>#include <math.h>using namespace std;int main()float a,b,c,disc; cout<<"please input a,b,c:" cin>>a>>b>>c; if (a=0) cerr<<"a is equal to zero,error!"<<endl; else if (disc=b*b-4*a*c)<0) cerr<<"disc=b*b-4*a*c<0"<<endl; else cout<<"x1="<<(-b+sqrt(disc)/(2*a)<<endl; cout<<"x2="<<(-b-sqrt(disc)/(2*a)<<endl; return 0;

注意事項(xiàng)

本文(《面向?qū)ο蟪绦蛟O(shè)計(jì)》答案.doc)為本站會(huì)員(wux****ua)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請(qǐng)重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!