Demo entry 6335525

Fraction:main.cpp

   

Submitted by anonymous on Dec 06, 2016 at 12:14
Language: C++. Code size: 2.4 kB.

#include<iostream>
#include"class.h"
//already using namespace

void main(){
	fraction a(3, 4), b (2,3), tmp, d, e;
	int c = 1,tmpi;
	cout << "a = 3/4, b = 2/3, c = 1\n" << endl;


	

	cout << "下面是关于作业要求的展示\n*********************************************" << endl;
	cout << "请输入一个分数,3/4或者3,4的形式\nd = ";
	cin >> d;

	cout << "\n下面是关于 + 的重载的展示\n*********************************************" << endl;
	tmp = a + b;
	cout << "a + b = " << tmp << endl;
	tmp = d + c;
	cout << "d + c = " << tmp << endl;
	tmp = c + b;
	cout << "c + b = " << tmp << endl;

	cout << "\n下面是关于 - 的重载的展示\n*********************************************" << endl;
	tmp = a - b;
	cout << "a - b = " << tmp << endl;
	tmp = d - c;
	cout << "d - c = " << tmp << endl;
	tmp = c - b;
	cout << "c - b = " << tmp << endl;
	cout << "单目-" << endl;
	tmp = -a;
	cout << "-a = " << tmp << endl;

	cout << "\n下面是关于 * 的重载的展示\n*********************************************" << endl;
	tmp = a * b;
	cout << "a * b = " << tmp << endl;
	tmp = d * c;
	cout << "d * c = " << tmp << endl;
	tmp = c * b;
	cout << "c * b = " << tmp << endl;

	cout << "\n下面是关于 / 的重载的展示\n*********************************************" << endl;
	tmp = a / b;
	cout << "a / b = " << tmp << endl;
	tmp = d / c;
	cout << "d / c = " << tmp << endl;
	tmp = c / b;
	cout << "c / b = " << tmp << endl;

	cout << "\n下面是取倒数的展示\n*********************************************" << endl;
	e = d.Reciprocal();
	cout << "d的倒数是e = " << e << endl;

	cout << "\n下面是逻辑运算符的展示\n*********************************************" << endl;
	
	tmpi = (a == b);
	cout << "a == b 的结果是:  " << tmpi<< endl;
	tmpi = (a != b);
	cout << "a != b 的结果是:  " << tmpi << endl;
	tmpi = (a > b);
	cout << "a > b 的结果是:  " << tmpi << endl;
	tmpi = (a >= b);
	cout << "a >= b 的结果是:  " << tmpi << endl;
	tmpi = (a < b);
	cout << "a < b 的结果是:  " << tmpi << endl;
	tmpi = (a <= b);
	cout << "a <= b 的结果是:  " << tmpi << endl;


	cout << "*********************************************" << endl;
	tmpi = (a == 2);
	cout << "a == 2 的结果是:  " << tmpi << endl;
	tmpi = (a != 2);
	cout << "a != 2 的结果是:  " << tmpi << endl;
	tmpi = (a > 2);
	cout << "a > 2 的结果是:  " << tmpi << endl;
	tmpi = (a >= 2);
	cout << "a >= 2 的结果是:  " << tmpi << endl;
	tmpi = (a < 2);
	cout << "a < 2 的结果是:  " << tmpi << endl;
	tmpi = (a <= 2);
	cout << "a <= 2 的结果是:  " << tmpi << endl;


}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).