本人学疏才浅恳请吧友、雷氏力学大师指正。
#include<iostream>
using namespace std;
class Lei
{
public:
Lei();
Lei(int d1, int d2);
Lei division() const;
void display() const;
friend Lei operator/(Lei & l1, Lei & l2);
friend ostream & operator <<(ostream & output, Lei & l);
void differential();
void mechanics();
void ana();
private:
mutable int quotient;
int divident;
int divisor;
};
Lei::Lei()
{
divident = 0;
divisor = 0;
quotient = 0;
}
Lei::Lei(int d1, int d2):divident(d1), divisor(d2)
{
quotient = 0;
}
Lei Lei::division()
const
{
if (divident == 1 && divisor == 0)
quotient = 1;
else
quotient = divident / divisor;
return *this;
}
void Lei::display()
const
{
cout << "被除数=" << divident << endl;
cout << "除数=" << divisor << endl;
if (quotient != 0 || divident == 0)
cout << "商=" << quotient << endl;
cout << endl;
}
Lei operator/(Lei & l1, Lei & l2)
{
Lei l;
l.divident = l1.divident;
l.divisor = l1.divisor;
l.quotient = l1.divident / l1.divisor * l2.divisor;
return l;
}
ostream & operator<<(ostream & output, Lei & l)
{
if (l.divisor == 0)
output << l.divident << '/' << l.divisor << '=' << l.quotient << endl;
else if (l.divisor == 1)
output << l.divident << '/' << l.divisor << '/' << l.quotient /
l.divident << '=' << l.quotient << endl;
output << endl;
return output;
}
void Lei::differential()
{
cout << "雷氏微分:" << endl;
cout << "F=m*dv/dt" << endl;
cout << "约去d" << endl;
cout << "F=MV/t" << endl;
cout << endl;
}
void Lei::mechanics()
{
cout << "雷氏力学定律:" << endl;
cout << "L=kmv" << endl;
cout << "k是常数" << endl;
cout << endl;
}
void Lei::ana()
{
cout << "雷氏语录:" << endl;
cout << "两种人" << endl;
cout << "太差太差" << endl;
cout << "无知无德" << endl;
cout << "肉原子" << endl;
cout << endl;
}
int main()
{
Lei const l(1, 0);
Lei lt;
// l.display();
lt = l.division();
// lt.display();
cout << "雷氏除法1:" << endl;
cout << lt;
Lei l1(10, 1), l10(1, 10);
Lei lt1;
lt1 = l1 / l10;
// lt1.display();
cout << "雷氏除法2:" << endl;
cout << lt1;
lt1.differential();
lt1.mechanics();
lt1.ana();
return 0;
#include<iostream>
using namespace std;
class Lei
{
public:
Lei();
Lei(int d1, int d2);
Lei division() const;
void display() const;
friend Lei operator/(Lei & l1, Lei & l2);
friend ostream & operator <<(ostream & output, Lei & l);
void differential();
void mechanics();
void ana();
private:
mutable int quotient;
int divident;
int divisor;
};
Lei::Lei()
{
divident = 0;
divisor = 0;
quotient = 0;
}
Lei::Lei(int d1, int d2):divident(d1), divisor(d2)
{
quotient = 0;
}
Lei Lei::division()
const
{
if (divident == 1 && divisor == 0)
quotient = 1;
else
quotient = divident / divisor;
return *this;
}
void Lei::display()
const
{
cout << "被除数=" << divident << endl;
cout << "除数=" << divisor << endl;
if (quotient != 0 || divident == 0)
cout << "商=" << quotient << endl;
cout << endl;
}
Lei operator/(Lei & l1, Lei & l2)
{
Lei l;
l.divident = l1.divident;
l.divisor = l1.divisor;
l.quotient = l1.divident / l1.divisor * l2.divisor;
return l;
}
ostream & operator<<(ostream & output, Lei & l)
{
if (l.divisor == 0)
output << l.divident << '/' << l.divisor << '=' << l.quotient << endl;
else if (l.divisor == 1)
output << l.divident << '/' << l.divisor << '/' << l.quotient /
l.divident << '=' << l.quotient << endl;
output << endl;
return output;
}
void Lei::differential()
{
cout << "雷氏微分:" << endl;
cout << "F=m*dv/dt" << endl;
cout << "约去d" << endl;
cout << "F=MV/t" << endl;
cout << endl;
}
void Lei::mechanics()
{
cout << "雷氏力学定律:" << endl;
cout << "L=kmv" << endl;
cout << "k是常数" << endl;
cout << endl;
}
void Lei::ana()
{
cout << "雷氏语录:" << endl;
cout << "两种人" << endl;
cout << "太差太差" << endl;
cout << "无知无德" << endl;
cout << "肉原子" << endl;
cout << endl;
}
int main()
{
Lei const l(1, 0);
Lei lt;
// l.display();
lt = l.division();
// lt.display();
cout << "雷氏除法1:" << endl;
cout << lt;
Lei l1(10, 1), l10(1, 10);
Lei lt1;
lt1 = l1 / l10;
// lt1.display();
cout << "雷氏除法2:" << endl;
cout << lt1;
lt1.differential();
lt1.mechanics();
lt1.ana();
return 0;