freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c面向?qū)ο蟪绦蛟O(shè)計(jì)上機(jī)考試題庫(已修改)

2025-04-08 23:34 本頁面
 

【正文】 C++面向?qū)ο蟪绦蛟O(shè)計(jì)上機(jī)考試題庫一、第一類題目(20道,每題7分,在word中保留代碼并將輸出結(jié)果窗口保留)1.定義盒子Box類,要求具有以下成員:長(zhǎng)、寬、高分別為x,y,z,可設(shè)置盒子形狀;可計(jì)算盒子體積;可計(jì)算盒子的表面積。includeiostreamclass Box { private: int x,y,z。 int v,s。 public: void int(int x1=0,int y1=0,int z1=0) {x=x1。y=y1。z=z1。} void volue() {v=x*y*z。} void area() {s=2*(x*y+x*z+y*z)。} void show() {coutx= x y= y z=zendl。 couts= s v= vendl。 }}。void main(){ Box a。(2,3,4)。()。()。()。}2. 有兩個(gè)長(zhǎng)方柱,其長(zhǎng)、寬、高分別為:(1)30,20,10;(2)12,10,20。分別求他們的體積。編一個(gè)基于對(duì)象的程序,在類中用帶參數(shù)的構(gòu)造函數(shù)。 include iostream using namespace std。 class Box {public: Box(int,int,int)。//帶參數(shù)的構(gòu)造函數(shù) int volume()。 private: int length。 int width。 int height。 }。Box::Box(int len,int h,int w) {length=len。 height=h。 width=w。 }//Box::Box(int len,int w,int,h):length(len),height(h),width(w){}int Box::volume() {return(length*width*height)。 } int main() { Box box1(30,20,10)。 coutThe volume of box1 is ()endl。 Box box2(12,10,20)。 coutThe volume of box2 is ()endl。 return 0。 }3. 有兩個(gè)長(zhǎng)方柱,其長(zhǎng)、寬、高分別為:(1)12,20,25;(2)10,30,20。分別求他們的體積。編一個(gè)基于對(duì)象的程序,且定義兩個(gè)構(gòu)造函數(shù),其中一個(gè)有參數(shù),一個(gè)無參數(shù)。 include iostreamusing namespace std。class Box {public: Box()。 Box(int len,int w ,int h):length(len),width(w),height(h){} int volume()。 private: int length。 int width。 int height。 }。int Box::volume() {return(length*width*height)。 } int main() { Box box1(10,20,25)。 coutThe volume of box1 is ()endl。 Box box2(10,30,20)。 coutThe volume of box2 is ()endl。 return 0。 } 4. 聲明一個(gè)類模板,利用它分別實(shí)現(xiàn)兩個(gè)整數(shù)、浮點(diǎn)數(shù)和字符的比較,求出大數(shù)和小數(shù)。include iostreamusing namespace std。templateclass numtype//聲明一個(gè)類模板class Compare {public: Compare(numtype a,numtype b) {x=a。y=b。} numtype max() {return (xy)?x:y。} numtype min() {return (xy)?x:y。} private: numtype x,y。 }。int main(){Compareint cmp1(3,7)。 cout() is the Maximum of two inteder numbers.endl。 cout() is the Minimum of two inteder numbers.endlendl。 Comparefloat cmp2(,)。 cout() is the Maximum of two float numbers.endl。 cout() is the Minimum of two float numbers.endlendl。 Comparechar cmp3(39。a39。,39。A39。)。 cout() is the Maximum of two characters.endl。 cout() is the Minimum of two characters.endl。 return 0。} 5. 建立一個(gè)對(duì)象數(shù)組,內(nèi)放5個(gè)學(xué)生的數(shù)據(jù)(學(xué)號(hào)、成績(jī)),用指針指向數(shù)組首元素,輸出第1,3,5個(gè)學(xué)生的數(shù)據(jù)。初值自擬。include iostreamusing namespace std。class Student {public: Student(int n,double s):num(n),score(s){} void display()。 private: int num。 double score。 }。void Student::display() {coutnum scoreendl。} int main(){Student stud[5]={ Student(101,),Student(102,),Student(103,), Student(104,),Student(105,)}。 Student *p=stud。 for(int i=0。i=2。p=p+2,i++) pdisplay()。 return 0。 }6. 建立一個(gè)對(duì)象數(shù)組,內(nèi)放5個(gè)學(xué)生的數(shù)據(jù)(學(xué)號(hào)、成績(jī)),設(shè)立一個(gè)函數(shù)max,用指向?qū)ο蟮闹羔樧骱瘮?shù)參數(shù),在max函數(shù)中找出5個(gè)學(xué)生中成績(jī)最高者,并輸出其學(xué)號(hào)。初值自擬。include iostreamusing namespace std。class Student {public: Student(int n,float s):num(n),score(s){} int num。 float score。 }。void main(){Student stud[5]={ Student(101,),Student(102,),Student(103,), Student(104,),Student(105,)}。 void max(Student* )。 Student *p=amp。stud[0]。 max(p)。 } void max(Student *arr){float max_score=arr[0].score。 int k=0。 for(int i=1。i5。i++) if(arr[i].scoremax_score) {max_score=arr[i].score。k=i。} coutarr[k].num max_scoreendl。} 7. 用new建立一個(gè)動(dòng)態(tài)一維數(shù)組,并初始化int[10]={1,2,3,4,5,6,7,8,9,10},用指針輸出,最后銷毀數(shù)組所占空間。includeiostreamincludestringusing namespace std。void main(){ int *p。 p=new int[10]。 for(int i=1。i=10。i++){ *(p+i1)=i。 cout*(p+i1) 。 } coutendl。 delete []p。 return。}8. 定義一個(gè)復(fù)數(shù)類Complex,重載運(yùn)算符“+”,使之能用于復(fù)數(shù)的加法運(yùn)算。將運(yùn)算符函數(shù)重載為非成員、非友元的普通函數(shù)。編寫程序,求兩個(gè)復(fù)數(shù)之和。初值自擬。include iostreamusing 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,imagi)endl。}Complex operator + (Complex amp。c1,Complex amp。c2){ return Complex(()+(),()+())。}int main(){Complex c1(3,4),c2(5,10),c3。 c3=c1+c2。 coutc3=。 ()。 return 0。}9. 定義一個(gè)復(fù)數(shù)類Complex,重載運(yùn)算符“+”,“—”,使之能用于復(fù)數(shù)的加,減運(yùn)算,運(yùn)算符重載函數(shù)作為Complex類的成員函數(shù)。編程序,分別求出兩個(gè)復(fù)數(shù)之和,差。初值自擬。using namespace std。class Complex {public: Complex(){real=0。imag=0。} Complex(double r,double i){real=r。imag=i。} Complex operator+(Complex amp。c2)。 Complex operator(Complex amp。c2)。 void display()。 private: double real。 double imag。 }。 Complex Complex::operator+(Complex amp。c2){Complex c。 =real+。 =imag+。 return c。} Complex Complex::operator(Complex amp。c2){Complex c。 =。 =。 return c。}void Complex::display(){cout(real,imagi)endl。}int main(){Complex c1(3,4),c2(5,10),c3。 c3=c1+c2。 coutc1+c2=。 ()。 c3=c1c2。 coutc1c2=。 ()。 return 0。}10. 定義一個(gè)復(fù)數(shù)類Complex,重載運(yùn)算符 “*”,“/”,使之能用于復(fù)數(shù)的乘,除。運(yùn)算符重載函數(shù)作為Complex類的成員函數(shù)。編程序,分別求出兩個(gè)復(fù)數(shù)之積和商。初值自擬。提示:兩復(fù)數(shù)相乘的計(jì)算公式為:(a+bi)*(c+di)=(acbd)+(ad+bc)i。兩復(fù)數(shù)相除的計(jì)算公式為:(a+bi)/(c+di)=(ac+bd)/(c*c+d*d)+(bcad) /(c*c+d*d)i。include iostreamusing namespace std。class Complex {public: Complex(){real=0。imag=0。} Complex(double r,double i){real=r。imag=i。} Complex operator*(Complex amp。c2)。 Complex operator/(Complex amp。c2)。 void display()。 private: double real。 double imag。 }。Complex Complex::o
點(diǎn)擊復(fù)制文檔內(nèi)容
黨政相關(guān)相關(guān)推薦
文庫吧 www.dybbs8.com
公安備案圖鄂ICP備17016276號(hào)-1