笔果题库
C++程序设计
免费题库
搜题找答案,就上笔果题库
利用LOCATION类,使用继承定义圆类CIRCLE,圆由圆心和半径构成。提供得到圆心坐标和半径的成员函数、以及计算圆的周长和面积的成员函数。在主程序中创建两个圆A和B,圆心坐标分别为(0,3)、(3,7),按如下格式输出两个圆的圆心坐标、周长和面积,并计算和输出两个圆的圆心之间的距离。A:(x1,y1,r1),Girth=g1,Area=a1B:(x2,y2,r2),Girth=g2.Area=a2A(x1,y1),B(x2,y2),Distance=d定义LOCATION类,该类没有“继承”等现象。注意二维坐标点之间的距离公式。classLOCATION{doublex,y;public:virtualdoublegetx()const{returnx;};virtualdoublegety()const{returny;};virtualdoubledist(LOCATION&s)const;LOCATION(doublex,doubley)::x(x),y(y){};};doubleLOCATION::dist(LOCATION&s)const{doublexd=s.x—==x,yd=s.y__y;returnsqrt(xd*xd+yd*yd);}
搜题找答案,就上笔果题库
设计一个Bank类,实现银行某账号的资金往来账目管理,包括建账号、存入、取出等。解:Bank类包括私有数据成员top(当前账指针),date(日期),money(金额),rest(余额)和sum(累计余额)。有三个成员函数bankin()(处理存入账),bankout()处理取出账)和disp()(输出明细账)请完成函数的实现。本题程序如下:#include#include#defineMax100classBank{inttop;chardate[Max][10];//日期intmoney[Max];//金额intrest[Max];//余额staticintsum;//累计余额public:Bank(){top=0;}voidbankin(chard[],intm){…}voidbankout(chard[],intm){…}voiddisp(){…};};
搜题找答案,就上笔果题库
声明复数类,Complex,该类中有两个私有变量real,image分别表示一个复数的实部和虚部。为Complex类添加适当的构造函数。并使用友元函数add实现复数加法。#includeusingnamespacestd;classComplexprivate:doublereal,image;public:voidsetRI(doublea,doubleb){real=a;image=b;}doublegetReal(){returmreal;}doublegetlmage(){returnimage;}voidprint(){if(image>0)cout
搜题找答案,就上笔果题库
在三角形类TRI实现两个函数,功能是输入三个顶点坐标判断是否构成三角形。#include#includeclasspoint{private:floatx,y;public:point(floata,floatb){x=a;y=b;}point(){x=0;y=0;},voidset(floata,floatb){x=a;y=b;}floatgetx(){returnx;}floatgety(){returny;}};classtri{pointx,y,z;floats1,s2,s3;public;...settri(…);//用于输入三个顶点坐标....test(…);//用于判断是否构成三角形};请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值类型)
搜题找答案,就上笔果题库
设计一个圆类circle和一个桌子类table。circle类包含私有数据成员radius和求圆面积的成员函数getare();table类包含私有数据成员height和返回高度的成员函数getheight()。roundtable类继承所有上述类的数据成员和成员函数,添加了私有数据成员color和相应的成员函数。其中,main函数已给出。请完成程序的其他部分。voidmain(){}roundtablert(0.8,1.2,"黑色");cout
搜题找答案,就上笔果题库
给出下面程序的输出结果。#includeusingnamespacestd;templateTmax(Tml,Tm2){return(m1>m2)?ml:m2:}voidmain(){cout
搜题找答案,就上笔果题库
给出下面程序的输出结果。include#includeusingnamespacestd;classBook{char*title;char*author;intnumsold;public:Book(){}Book(constchar*strl,constchar*str2,constintnum){intlen=strlen(strl);title=newchar[len+1];strcpy(title,str1);len=strlen(str2);author=newchar[len+1];strcpy(author,str2);numsold=num;}voidsetbook(constchar*str1,constchar*str2,constintnum){intlen=strlen(str1);title=newchar[len+1];strcpy(title,str1);len=strlen(str2);author=newchar[len+1];strcpy(author,str2);numsold=num;}~Book(){deletetitle;deleteauthor;}voidprint(ostream&output){output
搜题找答案,就上笔果题库
请写出myTextl.txt文本文件中的内容。#include#includeusingnamespacestd;#includevoidmain(){ofstreammyFile1;myFilel.open("myTextl.txt");cout
搜题找答案,就上笔果题库
给出下面程序的输出结果。#include"iostream.h"intmain(){inti=17;while(i>=10)if(--i%4==3)continue;elsecout
搜题找答案,就上笔果题库
给出下面程序的输出结果。#includeusingnamespacestd;voidmain(){intnum=300;int&ref=num;cout