C++函数工具源码

支持一次函数和二次函数的求解和求坐标

//函数工具0.1.2beta 
//Creat by LMC
//版权所有,仿冒必究

#include<iostream>
#include<cmath>
#include<stdlib.h>

using namespace std;
//定义坐标的类,没啥用,装x的
class zb {
public:
	double num1, num2;
	double num3, num4;
};
//主程序
int main()
{
	int type;
	cout << "函数工具0.1.2" << endl;
	cout << "Creat by LMC" << endl;
	system("pause");
	system("cls");
	A:
	cout << "请选择模式" << endl;
	cout << "求解析式请输入1,求坐标请输入2" << endl;
	cin >> type;
	if (type == 1) {
		back:
		int ty;
		system("cls");
		cout << "您选择的是求解析式" << endl;
		cout << "请输入函数类型,正比例函数请输入1,一次函数输入2" << endl;
		cin >> ty;
		//正比例函数求解析式
		if (ty == 1) {
			cout << "正比例函数" << endl;
			float x, y;
			float k;
			cout << "正比例函数解析式(公式:y=k*x)" << endl;
			cout << "请分别输入经过点的x坐标和y坐标(纯数字)" << endl;
			cin >> x >> y;
			if (x == 0)
			{
				cout << "该正比例函数与y轴重合" << endl;
				return 0;
			}
			else if (y == 0)
			{
				cout << "该正比例函数与x轴重合" << endl;
				return 0;
			}
			k = y / x;
			cout << "该正比例函数解析式为:y=" << k << "*x" << endl;
			system("pause");
			return 0;
		}
		//一次函数求解析式
		else if (ty == 2) {
			cout << "一次函数" << endl;
			float x, y, x1, y1;
			float a, b, e;
			float c, d, f, g;
			cout << "求一次函数解析式(公式:y=m*x+b)" << endl;
			cout << "请分别输入该直线经过的点1的坐标(纯数字)" << endl;
			cin >> x >> y;
			cout << "请分别输入该直线经过的点2的坐标(纯数字)" << endl;
			cin >> x1 >> y1;

			e = y1 - y;
			f = x1 - x;
			a = e / f;
			g = a * x;
			b = y - g;
			if (a == 0)
			{
				cout << "该直线与x轴平行(或重合),解析式为:y=" << b << endl;
				return 0;
			}
			else if (x == x1)
			{
				if (x == 0)
				{
					cout << "该直线与y轴重合" << endl;
					return 0;
				}
				else
				{
					cout << "该直线与y轴平行,解析式为:x=" << a << endl;
					return 0;
				}
			}
			cout << "该直线解析式为:y=" << a << "x+" << b << endl;
			system("pause");
			return 0;
		}
		//输入其他数字时报错
		else {
			system("pause");
			cout << "请输入正确的数字!" << endl;
			goto back;
		}
	}
	//求坐标
	else if (type == 2) {
		B:
		int zyc;
		cout << "求坐标" << endl;
		cout << "选择类型,正比例函数输入1,一次函数输入2" << endl;
		cin >> zyc;
		if (zyc == 1)//正比例函数求坐标
		{
			double a;
			double X;
			double Y;
			double beg, end;
			double step;
			cout << "正比例函数求坐标" << endl;
			cout << "公式y=ax" << endl;
			cout << "请输入a的值" << endl;
			cin >> a;
			cout << "请输入x的最小值" << endl;
			cin >> beg;
			cout << "请输入x的最大值" << endl;
			cin >> end;
			cout << "请输入间隔值" << endl;
			cin >> step;
			for (X = beg; X < end; X = X + step) {
				Y = a * X;
				cout << "坐标为:" << "x=" << X << "y=" << Y << endl;
			}
			system("pause");
			return 0;
		}
		else if (zyc == 2)//一次函数求坐标
		{
			double x, y;
			double k, b;
			double step;
			double beg, end;
			cout << "一次函数求坐标" << endl;
			cout << "公式y=kx+b" << endl;
			cout << "输入k的值" << endl;
			cin >> k;
			cout << "输入b的值" << endl;
			cin >> b;
			cout << "输入x的最小值" << endl;
			cin >> beg;
			cout << "输入x的最大值" << endl;
			cin >> end;
			cout << "输入间隔值" << endl;
			cin >> step;
			for (x = beg; x < end; x = x + step)
			{
				y = k * x + b;
				cout << "坐标为" << "x=" << x << "y=" << y << endl;
			}
			system("pause");
			return 0;
		}
		//输入其他数字时报错
		else
		{
			system("cls");
			cout << "请输入正确的数字" << endl;
			goto B;
		}
	}
	//输入其他数字报错
	else {
		system("cls");
		cout << "请输入正确的数字!" << endl;
		goto A;
	}
	return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值