11、12我实在是没精力做了,我这边也有一大堆活要忙,你再问问别人吧
或者你要是有耐心就等上10天左右,没准我会有空
第8题有问题,sort函数如果作成员函数,那么参数应该是个数组,而这里根本就没有指定数组长度的参数。除非把sort函数声明为静态的,并同时声明一个static的student*数组,这样才能跟踪student类的每个对象,并对所有对象进行排序。这道题你先别做了,找老师让他把题改了再说
另外能不能再加点分?写了这么多才50分。。。。。。。。
============================================================================
全部程序已通过VC 6.0测试
============================================================================
1.
#include
#include
class shape{ public: virtual float area()=0; };
class circle:public shape{ int x,y; float r;
public: circle(int xx,int yy,float rr)
{ x=xx;y=yy;r=rr; }
float area(){
return float(3.14*r*r); }};
class rectangle:public shape{
int x1,y1,x2,y2;
public:
rectangle(int xx1,int yy1,int xx2,int yy2)
{x1=xx1;y1=yy1;x2=xx2;y2=yy2; }
float area(){
return float(abs(x1-x2)*abs(y1-y2)); }};
void main(){
circle *pc=new circle(1,2,2);
rectangle* pr=new rectangle(1,2,3,4);
shape* pS[2]; pS[0]=pc; pS[1]=pr;
for(int i=0;i<2;i++)
{ cout<
============================================================================
2.
#include
class COil
{
private:
double m_UnLead;
double m_Lead;
double m_Total;
public:
COil()
{
m_UnLead = 0;
m_Lead = 0;
}
COil(double m_UnLead, double m_Lead)
{
this->m_Lead = m_Lead;
this->m_UnLead = m_UnLead;
}
double GetTotal()
{
m_Total = 17.0 * m_UnLead + 16.0 * m_Lead;
return m_Total;
}
};
void main()
{
double UnLead,Lead;
cout << "输入无铅油的数量:" << endl;
cin >> UnLead;
cout << "输入有铅油的数量:" << endl;
cin >> Lead;
COil oil(UnLead,Lead);
cout << "总的收入为:" << oil.GetTotal() << endl;
}
============================================================================
3.
#include
class RectAngle
{ private:
float ledge,sedge;
public:
RectAngle( ){ }
RectAngle(float l,float s)
{ ledge=l;sedge=s; }
float area( )
{ return ledge*sedge; }
friend void addarea(RectAngle &r1, RectAngle &r2);
};
void addarea(RectAngle &r1, RectAngle &r2)
{ cout<<"总面积:"<
}
void main( )
{ RectAngle Rectl(3,2),Rect2(4,3);
addarea(Rectl,Rect2);
}
============================================================================
4.
#include
#include
class Complex
{
public:
Complex() : _real(0), _imag(0) {}
explicit Complex( double r) : _real(r), _imag(0) {}
Complex(double r, double i) : _real(r), _imag(i) {}
Complex& operator+=(const double& d)
{
_real += d;
return *this;
}
Complex& operator+=(const Complex& c)
{
_real += c._real;
_imag += c._imag;
return *this;
}
Complex& operator-=(const double &d)
{
_real -= d;
return *this;
}
Complex& operator-=(const Complex& c)
{
_real -= c._real;
_imag -= c._imag;
return *this;
}
Complex& operator*=(const double& d)
{
_real *= d;
_imag *= d;
return *this;
}
Complex& operator*=(const Complex& c)
{
double re = _real;
double im = _imag;
_real = re * c._real - im * c._imag;
_imag = re * c._imag + im * c._real;
return *this;
}
Complex& operator/=(const double& d)
{
_real /= d;
_imag /= d;
return *this;
}
Complex& operator/=(const Complex& c)
{
double re = _real;
double im = _imag;
double d = c._real * c._real + c._imag * c._imag;
_real = (re * c._real + im * c._imag) / d;
_imag = (im * c._real - re * c._imag) / d;
return *this;
}
Complex Conj() const
{
return Complex(_real, -_imag);
}
double Real() const { return _real; }
double Imag() const { return _imag; }
void Real(const double& re) { _real = re ; }
void Imag(const double& im) { _imag = im ; }
void Set(const double& re, const double& im){ _real = re; _imag = im ; }
double Modsq() const { return _real*_real + _imag * _imag ; }
double Mod() const { return sqrt(_real*_real + _imag * _imag); }
private:
double _real;
double _imag;
};
inline Complex operator+(const Complex& c)
{
return Complex(c.Real(), c.Imag());
}
inline Complex operator-(const Complex& c)
{
return Complex(-c.Real(), -c.Imag());
}
inline Complex operator+(const Complex& c, const double& d)
{
return Complex(c.Real() + d, c.Imag());
}
inline Complex operator+(const double& d, const Complex& c)
{
return Complex(d + c.Real(), c.Imag());
}
inline Complex operator+(const Complex& c1, const Complex& c2)
{
return Complex(c1.Real() + c2.Real(), c1.Imag() + c2.Imag());
}
inline Complex operator-(const Complex& c, const double& d)
{
return Complex(c.Real() - d, c.Imag());
}
inline Complex operator-(const double& d, const Complex& c)
{
return Complex(d - c.Real(), -c.Imag());
}
inline Complex operator-(const Complex& c1, const Complex& c2)
{
return Complex(c1.Real() - c2.Real(), c1.Imag() - c2.Imag());
}
inline Complex operator*(const Complex& c, const double& d)
{
return Complex(c.Real() * d, c.Imag() * d);
}
inline Complex operator*(const double& d, const Complex& c)
{
return Complex(c.Real() * d, c.Imag() * d);
}
inline Complex operator*(const Complex& c1, const Complex& c2)
{
double real = c1.Real() * c2.Real() - c1.Imag() * c2.Imag();
double imag = c1.Real() * c2.Imag() + c1.Imag() * c2.Real();
return Complex(real, imag);
}
inline Complex operator/(const Complex& c, const double& d)
{
return Complex(c.Real() / d, c.Imag() / d);
}
inline Complex operator/(const double& d, const Complex& c)
{
double dd = c.Real() * c.Real() + c.Imag() * c.Imag();
return Complex((d * c.Real())/dd, (-d * c.Imag())/dd);
}
inline Complex operator/(const Complex& c1, const Complex& c2)
{
double d = c2.Real() * c2.Real() + c2.Imag() * c2.Imag();
double real = (c1.Real() * c2.Real() + c1.Imag() * c2.Imag()) / d;
double imag = (c1.Imag() * c2.Real() - c1.Real() * c2.Imag()) / d;
return Complex(real, imag);
}
inline double real(const Complex &c)
{
return c.Real();
}
inline double imag(const Complex &c)
{
return c.Imag();
}
inline double abs(const Complex &c)
{
return sqrt(c.Real() * c.Real() + c.Imag() * c.Imag());
}
inline double norm(const Complex &c)
{
return c.Real() * c.Real() + c.Imag() * c.Imag();
}
inline Complex conj(const Complex &c)
{
return Complex(c.Real(), -c.Imag());
}
ostream &operator<<(ostream &os, const Complex &c)
{
os<
}
int main()
{
Complex a(1, 2), b, c;
c = a+b;
cout<
cout<
}
============================================================================
5.
#include
#include
class tpoint
{
private:
int x,y;
public:
void setpoint(int m,int n);
void move(int xoffset,int yoffset);
tpoint(int m,int n);
int getx();
int gety();
friend double distance( tpoint a,tpoint b);
};
int tpoint::getx()
{
return x;
}
int tpoint::gety()
{
return y;
}
tpoint::tpoint(int m,int n)
{
x=m;
y=n;
}
void tpoint::setpoint (int m,int n)
{
x=m;
y=n;
}
void tpoint::move(int xoffset ,int yoffset)
{
x+=xoffset;
y+=yoffset;
}
double distance(tpoint a,tpoint b)
{
int k,l;
k=a.x-b.x;
l=a.y-b.y;
return sqrt(k*k+l*l);
}
void main()
{
tpoint a(3,4),b(6,8);
tpoint p(5,6);
p.move(5,4);
int m,n;
m=p.getx();
n=p.gety();
double d=distance(a,b);
cout<<"distance is "<< d;
cout<<"\nthe p's xcordinance is: "<
============================================================================
6.
#include
class watermelon{
private:
float weight;
static float totalw;
static int totaln;
public:
watermelon(float w)
{weight=w;
totalw+=weight;
totaln++;
}
~watermelon()
{totalw-=weight;
totaln--;
}
void display();
static void totaldisp();
};
float watermelon::totalw=0;
int watermelon::totaln=0;
void watermelon::display()
{cout<<"The watermelon weight is:";
cout<
void watermelon::totaldisp()
{cout<<"Total weight is:";
cout<
cout<
void main(){
watermelon w1(3.5);
w1.display();
watermelon::totaldisp();
watermelon w2(6);
w2.display();
watermelon::totaldisp();
watermelon w3(6);
w3.display();
watermelon::totaldisp();
w2.watermelon::~watermelon();
watermelon::totaldisp();
}
============================================================================
7.
#include
const float PI=(float)3.1415926;
void main()
{
int iType;
float radius,a,b,area;
cout<<"图形的类型为?(1-圆形 2-长方形 3-正方形):";
cin>>iType;
switch(iType)
{
case 1:
cout<<"圆的半径为:";
cin>>radius;
area=PI*radius*radius;
cout<<"面积为:"< break;
case 2:
cout<<"矩形的长为:";
cin>>a;
cout<<"矩形的宽为:";
cin>>b;
cout<<"面积为:"< break;
case 3:
cout<<"正方形边长为:";
cin>>a;
area=a*a;
cout<<"面积为:"< break;
default:
cout<<"不是合法的输入值!"<
}
============================================================================
8.
有问题
============================================================================
9.#include
class STACK
{
private:int base[10];
public:int size;
STACK();
void push(int a)
{
base[size++]=a;
}
int p()
{
return base[--size];
}
};
STACK:: STACK(){size=0;};
int main()
{
STACK s;
cout<<"出栈"<
s.push(2);
s.push(6);
s.push(7);
s.push(3);
cout<
}
============================================================================
10.
#include
#include
class person
{
int no;
char name[10];
public:void input()
{
cout<<" 编号:";cin>>no;
cout<<" 姓名:";cin>>name;
}
void disp()
{
cout<<" 编号:"<
};
class student:public person
{
private:char depart[6];
public:void input()
{
person::input();
cout<<" 班号:"; cin>>depart;
}
void disp()
{
person::disp();
cout<<" 班号:"<
};
class teacher:public person
{
private:char depart[10];
public:void input()
{
person::input();
cout<<" 部门:"; cin>> depart ;
}
void disp()
{
person::disp();
cout<<" 部门:"<< depart <
};
void main()
{
student s1;
teacher t1;
cout<<"输入一个学生数据:\n"; s1.input();
cout<<"输入一个教师数据:\n"; t1.input();
cout<<"显示一个学生数据:\n"; s1.disp();
cout<<"显示一个教师数据:\n"; t1.disp();
}
============================================================================
11.
============================================================================
12.
来找劳动力啊。。。。。。
为啥要跪解啊, 我还是比较习惯坐着回答问题。。
.................................
自己做就行啦。。