急求高手帮我编两道C++题目

2024-11-03 00:23:33
推荐回答(1个)
回答1:

#include
#include
using namespace std;
class Str{
private:
char str[120];

int length;
public:
Str &operator+(Str &s2);
void print()
{
cout<}
Str(const char *words)
{
int i;
for(i=0;words[i];i++)
str[i]=words[i];
str[i]='\0';
length=i;
}
};

int main()
{
int t;

char gh[50],gg[50];
cout<<"输入两句话\n";
cin>>gh>>gg;
Str ss1(gh),ss2(gg);
ss1+ss2;
ss1.print();
}

Str &Str::operator+(Str &s2)
{
int f;
for(f=0;f<=s2.length;f++)
{

str[length]=s2.str[f];
length+=1;
}
return *this;
}

#include
#include
using namespace std;
class Rectangle
{
int length,width;
public:
void input();
int S()
{
return length *width;
}
};
class Rectangular: public Rectangle
{
int height;
public:
void input()
{
Rectangle::input();
cout<<"输入高\n";
cin>>height;
}
int V()
{
return S()*height;
}
};
int main()
{
int t;
Rectangular R;
R.input();
cout<<"面积"<cout<<"体积"<}
void Rectangle::input()
{
cout<<"输入长\n";
cin>>length;
cout<<"输入宽\n";
cin>>width;
}
第一全
尘封梦想 20:09:13
#include
#include
using namespace std;
class Point
{
int x,y;
public:
Point(int a,int b):x(a),y(b)
{};
Point(const Point &s)
{
x=s.x;y=s.y;
}
float norm()
{
return sqrt(x *x+y*y);
}
void print()
{
cout<<"x为"<}
};
int main()
{
Point p(23,15),ss(p);
cout<<"原点距离"<ss.print();
}

尘封梦想 20:09:18
第三个
尘封梦想 20:10:26
第二个 #include
#include
using namespace std;
class Str{
private:
char str[120];
int length;
public:
Str &operator+(Str &s2);
void print()
{
cout<}
Str(const char *words)
{
int i;
for(i=0;words[i];i++)
str[i]=words[i];
str[i]='\0';
length=i;
}
};