欢迎来到天天文库
浏览记录
ID:22471144
大小:38.42 KB
页数:13页
时间:2018-10-29
《c++课后习题解答》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++课后习题程序3-14.用递归的方法编写程序求N阶勒让德多项式的值,在主程序中实现输入输出。递归公式为1(n=0)Pn(x)=x(n=1)[(2n-1)x*Pn-1(x)-(n-1)Pn-2(x)]/n(n>1)#includeusingnamespacestd;longp(intx,inty)//Legendrepolynomials函数定义{if(y==0)return1;elseif(y==1)returnx;elsereturn(((2*y-1)*x*p(x,y-1)
2、-(y-1)*p(x,y-2))/y);}voidmain(){inta;//legendrepolynomials函数中x的值intn;//级数ncout<<"请输入legendrepolynomials函数中x的值:";cin>>a;cout<<"请输入所要求的多项式级数:";cin>>n;p(a,n);cout<<"n阶勒让德多项式的值为(当x="<3、,以及对这些属性操作的方法。实现并测试这个类。(第一个程序待调试)???#includeclassDog{public:Dog(intinitialAge=0,intinitialWeight=5);~Dog();intGetAge(){returnitsAge;}//inline!voidSetAge(intage){itsAge=age;}//inline!intGetWeight(){returnitsWeight;}//inline!voidSetWeight(int4、weight){itsAge=weight;}//inline!private:intitsAge,itsWeight;};Dog::Dog(intinitialAge,intinitialWeight){itsAge=initialAge;itsWeight=initialWeight;}Dog::~Dog()//destructor,takesnoaction{}intmain(){DogJack(2,10);cout<<"JackisaDogwhois";cout<5、<<"yearsoldand";cout<#includeusingnamespacestd;c6、lassdog{private:intm_age;intm_weight;public:dog():m_age(5),m_weight(10){}voidsetAge(inti){m_age=i;}voidsetWeight(inti){m_weight=i;}intage(){returnm_age;}intweight(){returnm_weight;}};intmain(){dogd;cout<7、个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。#includeclassRectangle{public:Rectangle(inttop,intleft,intbottom,intright);~Rectangle(){}intGetTop()const{returnitsTop;}intGetLeft()const{returnitsLeft;}intGetBottom()const{returnitsBottom;}int8、GetRight()const{returnitsRight;}voidSetTop(inttop){itsTop=top;}voidSetLeft(intleft){itsLeft=left;}voidSetBottom(intbottom){itsBottom=bottom;}voidSetRight(intright){itsRight=right;}intGetArea()const;private:intitsTop;intitsLeft;intitsBot
3、,以及对这些属性操作的方法。实现并测试这个类。(第一个程序待调试)???#includeclassDog{public:Dog(intinitialAge=0,intinitialWeight=5);~Dog();intGetAge(){returnitsAge;}//inline!voidSetAge(intage){itsAge=age;}//inline!intGetWeight(){returnitsWeight;}//inline!voidSetWeight(int
4、weight){itsAge=weight;}//inline!private:intitsAge,itsWeight;};Dog::Dog(intinitialAge,intinitialWeight){itsAge=initialAge;itsWeight=initialWeight;}Dog::~Dog()//destructor,takesnoaction{}intmain(){DogJack(2,10);cout<<"JackisaDogwhois";cout<5、<<"yearsoldand";cout<#includeusingnamespacestd;c6、lassdog{private:intm_age;intm_weight;public:dog():m_age(5),m_weight(10){}voidsetAge(inti){m_age=i;}voidsetWeight(inti){m_weight=i;}intage(){returnm_age;}intweight(){returnm_weight;}};intmain(){dogd;cout<7、个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。#includeclassRectangle{public:Rectangle(inttop,intleft,intbottom,intright);~Rectangle(){}intGetTop()const{returnitsTop;}intGetLeft()const{returnitsLeft;}intGetBottom()const{returnitsBottom;}int8、GetRight()const{returnitsRight;}voidSetTop(inttop){itsTop=top;}voidSetLeft(intleft){itsLeft=left;}voidSetBottom(intbottom){itsBottom=bottom;}voidSetRight(intright){itsRight=right;}intGetArea()const;private:intitsTop;intitsLeft;intitsBot
5、<<"yearsoldand";cout<#includeusingnamespacestd;c
6、lassdog{private:intm_age;intm_weight;public:dog():m_age(5),m_weight(10){}voidsetAge(inti){m_age=i;}voidsetWeight(inti){m_weight=i;}intage(){returnm_age;}intweight(){returnm_weight;}};intmain(){dogd;cout<7、个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。#includeclassRectangle{public:Rectangle(inttop,intleft,intbottom,intright);~Rectangle(){}intGetTop()const{returnitsTop;}intGetLeft()const{returnitsLeft;}intGetBottom()const{returnitsBottom;}int8、GetRight()const{returnitsRight;}voidSetTop(inttop){itsTop=top;}voidSetLeft(intleft){itsLeft=left;}voidSetBottom(intbottom){itsBottom=bottom;}voidSetRight(intright){itsRight=right;}intGetArea()const;private:intitsTop;intitsLeft;intitsBot
7、个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。#includeclassRectangle{public:Rectangle(inttop,intleft,intbottom,intright);~Rectangle(){}intGetTop()const{returnitsTop;}intGetLeft()const{returnitsLeft;}intGetBottom()const{returnitsBottom;}int
8、GetRight()const{returnitsRight;}voidSetTop(inttop){itsTop=top;}voidSetLeft(intleft){itsLeft=left;}voidSetBottom(intbottom){itsBottom=bottom;}voidSetRight(intright){itsRight=right;}intGetArea()const;private:intitsTop;intitsLeft;intitsBot
此文档下载收益归作者所有