⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsample.cpp

📁 实现了分数之间的四则运算
💻 CPP
字号:
#include "fraction.cpp"

int main()
{
   fraction a(3,2),b(4,3);
   fraction sum,difference,product,quotient;
   
   cout<<"fraction a is "<<a<<";";
   cout<<"fraction b is "<<b<<";"<<endl;
   //to test the six comparing operators
   cout<<"\nThe results of comparing a and b(1 is true, 0 is false):"
       <<"\na == b is " << ( a == b )
       <<"\na != b is " << ( a != b )
       <<"\na >= b is " << ( a >= b ) 
       <<"\na <= b is " << ( a <= b )
       <<"\na >  b is " << ( a >  b )
       <<"\na <  b is " << ( a <  b )
       <<"\n*************************************************************"<<endl;
   //to test the four arithmetic operators
   sum = a + b;
   cout<<"The sum of a and b is : "<<sum<<endl;
   
   difference = a - b;
   cout<<"a minus b is : "<<difference<<endl;
   
   product = a * b;
   cout<<"The product of a and b is : "<<product<<endl;
   
   quotient = a / b;
   cout<<"a divide b is : "<<quotient<<endl;
   
   cout<<"*************************************************************"<<endl;
   //to test the member funtion:simplify and reciprocal 
   fraction c(6,9);
   cout<<"Fraction c is "<<c<<endl;
   c.simplify();
   cout<<"Fraction c after simplify is "<<c<<endl;
   c.reciprocal();
   cout<<"The reciprocal of c is "<<c<<endl;
   
   //to test the class Integer 
   cout<<"*************************************************************"<<endl;
   Integer d(2);
   cout<<"Integer d is "<<d<<endl;
   cout<<"The sum of a and d is "<<a+d<<endl;
   cout<<"d minus a is "<<d-a<<endl;
   cout<<"The product of a and d is "<<a*d<<endl;
   cout<<"a divide d is "<<a/d<<endl;
   
   cout<<"*************************************************************"<<endl;   
   Integer e(3),f;
   d.set_fraction(2,1);
   cout<<"Integer d is "<<d<<endl;
   cout<<"Integer e is "<<e<<endl;
   f = d + e;
   
   cout<<"The sum of two integers d and e is "<<f<<endl;
   
   f = d - e;
   cout<<"d minus e is "<<f<<endl;
   
   f = d * e;
   cout<<"The product of d and e is "<<f<<endl;
   
   f = e / d;
   cout<<"e divide d is "<<f<<endl;
   
   cout<<"*************************************************************"<<endl;
   cout<<"\nThe results of comparing d and e(1 is true, 0 is false):"
       <<"\nd == e is " << ( a == b )
       <<"\nd != e is " << ( a != b )
       <<"\nd >= e is " << ( a >= b ) 
       <<"\nd <= e is " << ( a <= b )
       <<"\nd >  e is " << ( a >  b )
       <<"\nd <  e is " << ( a <  b )<<endl;
   
   system("pause");
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -