类编程作业

#include <iostream>
using namespace std;
class Integer {
private:
	int _num;
public:
	//构造函数
	Integer(int num) {
		_num = num;
	}
	//计算当前Integer 和 b之间的最大公约数
	int gcd(Integer b) {
		int r=b._num;
		while (r != 0)
		{
			r = _num%b._num;
			_num = b._num;
			b._num = r;
		}
		return _num;
	}
};
int main(){
	int a, b;
	cin >> a >> b;
	Integer A(a);
	Integer B(b);
	cout << A.gcd(B) << endl;
	return 0;
}


/* students please write your program here */

#include <iostream>
using namespace std;

class Integer{
private:
	int _num;
	//getLength()函数获取_num长度
	int getLength(){
		int len=1;
		int n = _num;
		while (n / 10 != 0)
		{
			++len;
			n /= 10;
		}
		return len;
	}
public:
	//Integer类构造函数
	Integer(int num){
		_num = num;
	}
	//反转_num
	int inversed(){
		int len = getLength();
		int tmp = _num;
		int s = 0;
		for (int i = 0; i < len; i++)
		{
			s = s * 10 + tmp % 10;
			tmp /= 10;
		}
		return s;
	}
};

int main() {
	int n;
	cin >> n;
	Integer integer(n);
	cout << integer.inversed() << endl;
}



/* students please write your program here */

#include <iostream>
#include <cmath>
using namespace std;
class Equation{
private:
	int _a, _b, _c,_x;
public:
	Equation(int a, int b, int c){
		_a = a;
		_b = b;
		_c = c;
		_x = _b*_b - 4 * _a*_c;
	}
	void solve(){
		if (_x > 0 && _a != 0)
		{
			cout << 1 << endl;
			double x = -_b / 2.0 / (double)_a;
			double y = sqrt(_x) / 2.0 / (double)_a;
			printf("%.2f %.2f\n", x - y, x + y);
		}
		else if (_x == 0 && _a != 0)
		{
			cout << 2 << endl;
			double x = -_b / 2.0 / (double)_a;
			printf("%.2f\n", x);
		}
		else if (_x<0 && _a != 0)
		{
			cout << 3 << endl;
		}
		else if (_a == 0 && _b == 0 && _c != 0)
		{
			cout << 4 << endl;
		}
		else if (_a == 0 && _b == 0 && _c == 0)
		{
			cout << 5 << endl;
		}
		else if (_a == 0 && _b != 0)
		{
			cout << 6 << endl;
			double x = -_c / (double)_b;
			printf("%.2f\n", x);
		}
	}
};
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	Equation tmp(a, b, c);
	tmp.solve();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值