问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。完成函数fun(char*str,char*s)空出部分。函数fun(char*str,char*s)的功能是:将在字符串str中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串S中,S中字符按原字符串中字符的顺序排列。(注意0为偶数)
例如:当sttr中的字符串为:"abcdef"时,s中的字符串应为:"aaccee"。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
#include
void fun(char*str,char*s)
{
}
void main()
{
char str[100],s[100];
cout<<"P1ease enter string
string:"<
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数operator=,以实现深层复制。 要求: 补充编制的内容写在“//**********333**********”与“//**********666**********”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。 //CDeepCopy.h #include<iostream> #include<string> using namespace std; class CDeepCopy { public: int n; //动态数组的元素个数 int *p; //动态数组首地址 CDeepCopy(int); ~CDeepCopy(); CDeepCopy& operator = (constCDeepCopy&r);//赋值运算符函数};void writeToFile(char*);//main.cpp.#include”CDeepCopy.h”CDeepCopy::~CDeepCopy(){delete[]P;)CDeepCopy::CDeepCopy(int k){n=k;P=new int[n];}//构造函数实现CDeepCopy& CDeepCopy:: operator =(const CDeepCopy&r)//赋值运算符函数实现{//********333********//********666********}int main(){ CDeepCopy a(2),d(3); a.P[o]=1;d.P[0]=666;//对象a,d数组元素的赋值 { CDeepCopy b(3); a.P[0]=88;b=a;//调用赋值运算符函数 cout<<b.P[0];//显示内层局部对象的数组元素 } cout<<d.P[0];//显示d数组元素a.P[0]的值cout<<”d fade away;\n”;cout<<a.P[0];//显示a数组元素a.P[0]的值 writeToFile(“”); return 0;}
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中定义的Matrix是一个用于表示矩阵的类。成员函数max_value的功能是求出所有矩阵元素中的最大值。例如,若有3×3矩阵则调用max_value函数,返回值为3。请编写成员函数max_value。要求:补充编制的内容写在“//********333********”与“//********666********”之间,不得修改程序的其他部分。注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//Matrix.h#include<iostream>#include<iomanip>usingnamespacestd;constintM=18;constintN=18;classMatrixintarray[M][N];public:Matrix()intgetElement(inti,intj)constreturnarray[i][j];voidsetElement(inti,intj,intvalue)array[i][j]=value;intmaxvalue()const;voidshow(constchar*s)constcout<<endl<<s;for(inti=0;i<M;i++)cout<<endl;for(intj=0;j<N;j++)cout<<setw(4)<<array[i][j];;voidreadFromFile(constchar*,MatrixvoidwriteToFile(char*,constMatrix//main.cpp#include"Matrix.h"#include<fstream>voidreadFromFile(constchar*f,Matrixif(infile.fail())cerr<<"打开输入文件失败!";return;intk;for(inti=0;i<M;i++)for(intj=0;j<N;j++)infile>>k;m.setElement(i,j,k);intMatrix::maxvalue()const//********333********//********666********intmain()Matrixm;readFromFile("",m);m.show("Matrix:");cout<<endl<<"最大元素:"<<m.maxvalue()<<endl;writeToFile("",m);return0;
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程proj3,其中包含了类Polyno-mial(“多项式”)的定义。形如5x4+3.4x2-7x+2代数式称为多项式,其中的5为4次项系数,3.4为2次项系数,-7为1次项系数,2为0次项(常数项)系数。此例缺3次项,意味着3次项系数为0,即省略了0x3。在Polynomial中,多项式的各个系数存储在一个名为coef的数组中。例如对于上面的多项式,保存在coef[0]、coef[1]、…、coef[4]中的系数依次为:2.0、-7.0、3.4、0.0、5.0,也即对于i次项,其系数就保存在coef[i]中。作为成员函数重载的运算符“+”用于计算两个多项式的和,并返回作为计算结果的那个多项式。请补充完成文件Polynomial.cpp中重载运算符函数operator+的定义。此程序的正确输出结果应为:
p1+p2的结果:7.3X^4+20.6X^3-41.2X^2-2.4X+5
p2+p3的结果:-2.3X^5+14.6X^4+12.8X^3+2.8X^2+0.2X+1
注意:只需要在operator+的//********333********和//********666********之间填入若干语句,不要改动程序中的其他内容。
//源程序 //主函数#include"Polynomial.h"int
main(){ double p1[]={5.0,3.5,-41.2,7.8},
p2[]={0.0,-5.9,0.0,12.8,7.3},
p3[]={1.0,6.1,2.8,0.0,7.3,-2.3}; Polynomial poly1(p1,
sizeof(p1)/sizeof(double)), poly2(p2, sizeof(p2)
/sizeof(double)), poly3(p3, sizeof(p3)
/sizeof(double));
cout<<"p1+p2的结果:"<<(polyl+poly2).tostring()<<endl;
cout<<"p2+p3的结果:"<<(poly2+poly3).tostring()<<endl; //
writeToFile("K://b10//61000102/"); return
0:}//Polynomial.cpp函数#include"Polynomial.h"#include
<strstream>#include <cmath>const char*Polynomial::tostring()
const{//将多项式转换成用于输出的字符串 static char s[1000];
s[0]=0; strstream buf(s,1000); for(int
i=num_of_terms-1;i>=0;i--){ if(coef[i]==0.0) continue,
//0系数项不输出 if(coef[i]<0.0) buf<<"-";
//负系数先输出"-" else if(strlen(s)==0) buf<<" ";
else buf<<"+": buf<<fabs(coef[i]);
if(i>0){ buf<<"X":
if(i>1)buf<<"^"<<i; } }
buf<<ends: return buf.str();}Polynomial Polynomial::
operator+(const Polynomial &x) const} double
c[100]={0.0};//存放结果系数的数组,所有元素初始化为零。假定项数不会超过100
//下面的n为两个操作数中项数的较大者 int n=(num_of_terms>=x.num_of_terms?
num_of_terms:x.num_of_terms);
//将两个多项式的对应系数之和存放到数组c的对应单元中 //********333********
//********333********
while(n>1&&c[n-1]==0.0)n--;//去除无效的(系数为0的)最高次项 return
Polynomial(c,n);}
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:
1
1
2
1
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构, 错误的语句在
∥********error********的下面。
#include
class TestClass
{
∥********error********
∥********error********
const int j ;
public:
TestCiass()
{
∥********error********
static int i=0;
cout<<++i<
问答题简单应用
请使用"答题"菜单或使用VC6打开考生文件夹proj2下的工程proj2。此工程包含一个程序文件main.cpp,其中有日期类Date、人员类Person以及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为:
按姓名排序
排序前:
张三 男 出生日期:1978年4月20日
王五 女 出生日期:1965年8月3日
杨六 女 出生日期:1965年9月5日
李四 男 出生日期:1973年5月30日
排序后:
李四 男 出生日期:1973年5月30日
王五 女 出生日期:1965年8月3日
杨六 女 出生日期:1965年9月5日
张三 男 出生日期:1978年4月20日
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容, 也不能删除或移动"//**********found**********"。
问答题请使用VC6或使用[答题] 菜单打开
proj3下的工程文件proj3。本题创建一个小型字符串类,字符串长度不超过100。程序文件包括proj3. h、proj3. cpp、writeToFile. obj。补充完成重载赋值运算符函数,完成深复制功能。
屏幕上输出的正确结果应该是:
Hello!
Happy new year!
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”两行之间。不得修改程序的其他部分。
注意:
程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out. dat中。输出函数writeToFile已经编译为obj文件。
//proj3. h
#include<iostream>
#include<iomanip>
using namespace std;
class MiniString
{
public:
friend ostream return output; }
friend istream //用于输入的临时数组
temp[0]="/0";//初始为空字符串
input>> setw(100)>>temp;
int inLen=strlen(temp);//输入字符串长度
if(inLen !=0)
{
s. length=inLen;//赋长度
if(s. sPtr!=0)delete[]s. sPtr;//避免内存泄漏
s. sPtr=new char[s. length+1];
strcpy(s. sPtr, temp);//如果S不是空指针,则复制内容
}
else s. sPtr[0]="/0";//如果s是空指针,则为空字符串
return input;
}
void modString(const char*string2)//更改字符串内容
{
if(string2 !=0)//如果string2不是空指针,则复制内容
{
if(strlen(string2)!=length)
{
length=strlen(string2);
delete[]sPtr;
sPtr=new char[1ength+1];//分配内存
}
strcpy(sPtr, string2);
}
else sPtr[0]="/0";//如果string2是空指针,则为空字符串
}
MiniString
MiniString(const char*S=""): length((s !=0) ? strlen(s): 0)//构造函数
{
sPtr=0;
if(length!=0)
setString(s);
}
~MiniString()//析构函数
{delete[]sPtr;}
private:
int length;//字符串长度
char*sPtr;//指向字符串起始位置
void setString(const char*string2)//辅助函数
{
sPtr=new char[strlen(string2)+1];//分配内存
if(string2!=0) strcpy(sPtr, string2);//如果string2不是空指针,则复制内容
else sPtr[0]="/0";//如果string2是空指针,则为空字符串
}
};
//proj3. cpp
#include<iostream>
#include<iomanip>
using namespace std;
#include"proj3. h"
MiniString
void writeToFile(const char*);
str2=strl;//使用重载的赋值运算符
str2. modString("Happy new year!");
cout<<strl<<"/n";
cout<<str2<<"/n";
writeToFile(" ");
return 0;
}
问答题使用VC6打开
下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:
(1)定义类CPoint的带有两个参数的构造函数,两个变量为x、y都为int型,且缺省值为0。请在注释//********1********后添加适当的语句。
(2)完成类CRectangle的构造函数,给point1和point2进行赋值。请在注释//********2********后添加适当的语句。
(3)完成类CRectangle的函数GetArea(),用来计算矩形面积。请在注释//********3********后添加适当的语句。
(4)定义CRectangle类,拥有两个私有对象point1和point2,类型为Point,请在注释//********4********料后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include<iostream.h>
#include <cmath>
class CPoint
{
public:
//********1********
{
x=i;
y=j;
}
int GetX()
{
return x;
}
int GetY()
{
return y;
}
private:
int x,y;
};
class CRectangle
{
public:
//********2********
{
}
int GetArea()
{
//********3********
in theight=point1.GetY()
-point2.GetY();
return (width*height)?
width*height: -width*height;
}
int GetGirth()
{
int width=abs(point1.GetX-point2.GetX());
int height=abs(point1.GetY()-point2.GetY());
return (2*(width+height));
}
private:
//********4********
CPoint point2;
};
int main()
{
CRectangle rect(5,2,13,18);
cout
rect.GetArea()
endl;
cout
rect.GetGirth()
endl;
return 0;
}
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj1。程序中位于每个//ERROR************found************下的语句行有错,请加以改正。改正后程序的输出应该是: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。 //源程序 #include<iostream> using namespace std; class StudentInfo protected: //ERROR************found************ char Name[]; int Age; int ID; int CourseNum; float Record: public: //ERROR************found************ void StudentInfo(char*name, int age, int ID, int courseNum,float record); //ERROR************found************ void~StudentInfo()delete[]Name; float AverageRecord() return Record/CourseNum: void show() consL; ; StudentInfo::StudentInfo(char*name, int age, int ID, int courseNum, float record) Name=strdup(name); Age=age; this->ID=ID: CourseNum=courseNum: Record=record: void StudentInfo::show()const cout<<"Name:"<<Name<<"Age:"<< <<"CourseNum:"<<CourseNum<<" Record:"<<Record<<endl; int main() StudentInfo st("Smith",21,99999,12,970); st.show(); return 0:
问答题请使用VC6或使用【答题】菜单打开
proj2下的工程proj2,其中定义了Employee类和Manager类。Employee用于表示某公司的雇员,其属性包括姓名(name)和工作部分(dept)。Manager是Employee的公有派生类,用于表示雇员中的经理。除了姓名和工作部分之外,Manager的属性还包括级别(level)。Employee类的成员函数print用于输出雇员的信息;Manager类的成员函数print负责输出经理的信息。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
Name:Sally Smith
Dept:Sales
Level:2
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“// ****found****”。
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee (string name, string dept):
// **********found**********
______
{}
virtual void print() const;
string dept() const //返回部门名称
{
// **********found**********
______
}
virtual ~Employee() {}
private:
string name_;
string dept_;
};
class Manager: public Employee {
public:
Manager (string name, string dept, int level):
// **********found**********
______
{}
virtual void print() const;
private:
int level;
};
void Employee::print() const
{
cout << "Name:" << name_ << endl;
cout << "Dept:" << dept_ << endl;
}
void Manager::print() const
{
// **********found**********
cout << "Level:" << level_ << endl;
}
int main()
{
Employee * emp = new Manager("Sally Smith", "Sales", 2);
emp -> print();
delete emp;
return 0;
}
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 车牌号:冀ABCl234 品牌:ForLand类别:卡车 当前档位:0最大载重量:12 车牌号:冀ABCl234 品牌:ForLand类别:卡车 当前档位:2最大载重量:12 车牌号:沪XYZ5678品牌:QQ类别:小轿车 当前档位:0座位数:5 车牌号:沪XYZ5678品牌:QQ类别:小轿车 当前档位:一1座位数:5注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include<iostream>#include<iomanip>#include<cmath>using namespace std;class AutoMobile{ //“汽车”类 char*brand; //汽车品牌 char*number; //车牌号 int speed; //档位:1、2、3、4、5,空档:0,倒档:一1 public: AutoMobile(const char*the brand,const char*the_number):speed(0){ brand=new char[strlen(the brand)+1 ];//**********found********** _________;//**********found********** _________; strcpy(number,the number); } ~AutoMobile(){delete[]brand;delete[]number;) const char*theBrand()const{return brand;} //返回品牌名称 const char*theNumber()const{return number;) //返回车牌号 int currentSpeed()const{ returnspeed;} //返回当前档位 void changeGearTo(int the_speed){ //换到指定档位 if(speed>=一1&&speed<=5) speed=the_speed; } virtual const char*category()const=0, //类别:卡车、小轿车等 virtual void show()const{ cout<<”车牌号:”<<theNumber()//********** found********** <<”品牌:”<<________ <<”类别:”<<category() <<”当前档位:”<<currentSpeed(); }},class Car:public AutoMobile{int seats;//座位数public: Car(const char*the_brand,constchar*the_number,int the_seats):AutoMobile(the brand,the number),seats(the seats){) int numberOfSeat()const{return seats;}//返回座位数 const char*category()const{return”小轿车”;) //返回汽车类别 void show()const{ AutoMobile::show(); cout<<”座位数:tt<<numberOfSeat()<<endl ; }}, class Truck:public AutoMobile{// “卡车”类 int max load;//最大载重量public: Truck(const char*the brand,const char*the number,int the maxload):AutoMobi le(the brand,thenumber),max load(the max load){) int maxLoad()const{return maxload;}//返回最大载重量//**********found**********const char*category()________//返回汽车类别 void show()const{ AutoMobile::show(.); cout<<”最大载重量:”<<maxLoad()<<endl; }};int main(){ Truck truck(”ForLand”,”冀ABC1234”,12); truck.show(); truck.changeGearTo(2); truck.show(); Car car(”QQ”,”沪xYz5678”,5); car.show(); car.changeGearTo(一1); car.show(); cout<<end1; return 0;}
问答题改错题
使用VC6打开考生文件夹下的工程kt13_1,此工程包含一个源程序文件kt13_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:
5
5
源程序文件kt13_1.cpp清单如下:
#include
classA{
public:
/*****************found*****************/
staticintn=1;
A(){n++;};
~A(){n--;}; };
/*****************found*****************/
intn=0;
intmain(){
Aa;
Ab[3];
A*c=newA;
c=
/*****************found*****************/
cout<
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能: (1)利用define定义常量TRUE为1,定义常量FALSE为0,请在注释//********1********后添加适当的语句。 (2)在类A2前增加A1的声明,请在注释//********2********后添加适当的语句。 (3)在类C1中声明友元函数bool fune(A2&a,A1&b),请在注释//********3********后添加适当的语句。 (4)实现函数bool func(A2&obj1,Al&obj2)功能,检查两个类的值都为TRUE,则返回TRUE,请在注释//********4********后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。#include<iostream.h>//********1********#define FALSE 0//********2********Class A2 { private: bool m_A2; friend bool func(A2&obj1,A1&obj2);public: A2() { m_A2=FALSE; }public: void setA2(bool n) { m_A2=n; } }; class A1 { private: bool m A1; //********3********public: A1() { m_A1=TRUE; }public: void setA1(bool n) { m_A1=n; } }; bool func(A2&obj1,A1&obj2) { //********4******** return } int main() { A2 obj0; A1 obj1; cout<<func(obj0,obj1)<<end1; obj0.setA2(TRUE); obj1.setA1(TRUE); cout<<func(obj0,obj1)<<end1;’ return 0; }
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并使程序输出的结果为: Max is 7 提示:max()函数实现找出两个数中的最大值,并作为函数值返回。 注意:错误的语句在//********error********的下面,修改该语句即可。#include<iostream>using namespace std;//********error********int max(int a,int b){ if(a<b) { int t=a; a=b; b=t; } return b;}int main(){ int m=-3; int n=7; //********error******** max(-3,n); cout<<"Max is"<<m<<endl; return 0;}
问答题请使用VC6或使用【答题】菜单打开考生文件夹pmj3下的工程pmj3,其中包含主程序文件main.cpp和用户定义的头文件Array.h,整个程序包含有类Array的定义和主函数main的定义。请把主程序文件中的Array类的成员函数Contrary()的定义补充完整,经补充后运行程序,得到的输出结果应该是:585,4,3,2,10,0,8.4,5.6,4.5,3.4,2.3,1.2注意:只允许在“//**********333**********”和“//**********666**********”之间填写内容,不允许修改其他任何地方的内容。//Array.h#include<iostream>usingnamespacestd;template<classType,intm>classArray{//数组类public:Array(Typeb[],intmm){//构造函数for(inti=0;i<m;i++)if(i<mm)a[i]=b[i];elsea[i]=0;}voidContrary();//交换数组a中前后位置对称的元素的值intLength()const{returnm;}//返回数组长度Typeoperator[](inti)const{//下标运算符重载为成员函数if(i<0||i>=m){cout<<"下标越界!"<<end1;exit(1);}returna[i];}private:Typea[m];};voidwriteToFile(constchar*);//不用考虑此语句的作用//main.cpp#include"Array.h"//交换数组a中前后位置对称的元素的值template<classType,intm>voidArray<Type,m>::Contrary(){//补充函数体//********333********//********666********}intmain(){ints1[5]={1,2,3,4,5};doubles2[6]={1.2,2.3,3.4,4.5,5.6,8.4};Array<int,5>dl(s1,5);Array<double,8>d2(s2,6);inti;d1.Contrary();d2.Contrary();cout<<d1.Length()<<¨<<d2.Length()<<end1;for(i=0;i<4;i++)cout<<d1[i]<<",";cout<<d1[4]<<end1;for(i=0;i<7;i++.)cout<<d2[i]<<”,”;cout<<d2[7]<<end1;writeToFile(””);//不用考虑此语句的作用return0;}
问答题使用VC++6.0打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(int n)的功能是在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个,并作为参数返回。 注意:不能修改程序的其他部分,只能修改fun函数。 试题程序: #include<iostream.h> #define N 100 int a[N][N]; int fun(int n) void main() int n; cout<<"please input N:"<<end1; cin>>n; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cout<<"please input a Number:"<<end1; cin>>a[i][j]; cout<<"The min of max numbers is"<<fun(n)<<end1;
问答题写出下列程序的运行结果。
#include <iostream>
using namespace std;
class Base
{
public:
Base(int x,int y) {a=x; b=y;}
void Show() {cout<<" Base: "<<a<<","<<b<<endl;}
private:
int a.b:
};
class Derived: public Base
{
public:
Derived(int x,int y,int z):Base(x,y),c(z){}
void Show() {cout<<"Derived:"<<c<<endl;}
private:
int c:
};
int main()
{
Base b(50,50),*pb;
Derived d(10,20,30);
pb=
pb->Show();
pb=
pb->Show();
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,请修改程序中的错误,使程序能得出正确的结果:num:0num:1num:10注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//******eror******的下面。#include<iostream.h>int i=10;class TestClasS{public:TestClasS(int i){cout<<"num:"<<i<<endl;//********error********i=i+1;}void Print()const(cout<<"num:"<<i<<endl;}private:int i;};void main(){//********error*******TestClass print;int i(0);print.Print();//********error********cout<<"num:"<<i<<endl;return;}
问答题使用VC6打开考生文件夹下的源程序文件modi.cpp。请完成函数fun(char*s1,char*s2),此函数的功能是计算s1中出现s2的个数,当不出现时,则返回0。如: s1为"1112223333aaaaeeffd" s2为"11"则返回1 s2为"aa"则返回2 注意:请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。{}include<iostream.h>//注意只能使用int类型,不能类型转换int fun(char*s1,char*s2){}void main(){ char s1[1024]; char s2[256]; cout<<"please input a string:"<<end1; cin.getline(s1,1 024); cout<<”please input otherstring:"<<end1; cin.getline(s2,256); cout<<fun(s1,s2); cout<<end1; return; }
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=实现的,三角形面积的计算是按公式f=实现的,其中s=。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:side1:9.43398Side2:5Side3:8area:20注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include<iostream>#include<cmath>usingnamespacestd;classPoint{//坐标点类public:constdoublex,y;Point(doublex=0.0,doubley=0.0):x(x),y(y){}//**********found*********doubledistanceTo(_______)const{//到指定点的距离returnsqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));}};classLine{//线段类public:constPointp1,p2;//线段的两个端点//**********found**********Line(Pointp1,Pointp2):______________{}doublelength()const{returnp1.distanceTo(p2);}//线段的长度};classTriangle{//=角形类public:constPointp1,p2,p3;//三角形的三个顶点//**********found**********Triangle(______________):p1(p1),p2(p2),p3(p3){}doublelength1()const{//边p1,p2的长度returnLine(p1,p2).length();}doublelength2()const{//边p2,p3的长度returnLine(p2,p3).length();}doublelength3()const{//边p3,p1的长度returnLine(p3,p1).length();}doublearea()const{//三角形面积//**********found**********doubles=______________;returnsqrt(s*(s-lengthl())*(s-length2())*(s-length3()));}};intmain(){Triangler(Point(0.0,8.0),Point(5.0,0.0),Point(0.0,0.O));cout<<"Side1:"<<r.length1()<<endl;cout<<"Side2:"<<r.lngth2()<<endl;cout<<"Side3:"<<r.length3()<<endl;cout<<"area:"<<r.area()<<endl;return0;}
