雷氏力学吧 关注:10,266贴子:205,768
  • 18回复贴,共1

雷氏数学、物理的c++初步实现

只看楼主收藏回复

本人学疏才浅恳请吧友、雷氏力学大师指正。
#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;


IP属地:上海来自Android客户端1楼2021-04-12 07:07回复
    诚征各种雷哏,以便完善雷氏力学方方面面。


    IP属地:上海来自Android客户端2楼2021-04-12 07:25
    回复
      void换成空虚之极,谢谢。


      IP属地:广东来自Android客户端4楼2021-04-12 08:20
      收起回复
        看不清楚,如果有运动就用L=kmv计算


        IP属地:山东来自iPhone客户端5楼2021-04-12 16:06
        收起回复
          太差太差,计算机是管科产物


          来自Android客户端6楼2021-04-12 17:28
          收起回复
            正确的,中出楼主


            IP属地:广西来自Android客户端7楼2021-04-12 17:35
            回复
              看不清楚。
              去动手做个电脑,把结果告诉大家


              IP属地:山西来自Android客户端9楼2021-04-12 17:55
              收起回复
                缩进!


                IP属地:重庆来自Android客户端10楼2021-04-12 19:41
                收起回复
                  看不清楚,如果有oop,就用1/0=1


                  IP属地:北京来自Android客户端12楼2021-04-12 20:15
                  收起回复
                    肉原子


                    IP属地:上海来自Android客户端13楼2021-04-12 20:35
                    回复