Giter Club home page Giter Club logo

calculator_qt's Introduction

Calculator_Qt

This is a calculator program based on Qt visualization. The main functions are as follows: addition, subtraction, multiplication, division, trigonometric functions, square root, square, remainder, logarithmic calculation, reciprocal calculation, factorial calculation, inverse number calculation, pi and natural base e, all clear operation, backspace operation, clear digital register operation, etc.

Enviroment

  1. Operation System: Win7
  2. Development Platform: Qt-5.15.1

Class

The part of this system that involves the internal computing function of the calculator defines the following categories: Calculator, Operator, Factory, Node and Stack.

  • Calculator
class Calculator{ 
private:
	Stack<double> m_num; // 数字栈 
	Stack<shared_ptr<Operator>> m_opr; // 运算符栈 
	...
}
  • Operator
class Operator { 
public:
	Operator(string c, int numOprd, int pre) :m_symbol(c), m_numOprand(numOprd), m_precedence(pre) {} 
	string symbol() const { return m_symbol; } 
	int numOprand() const { return m_numOprand; } 
	int precedence() const { return m_precedence; } 
	virtual double get(double a, double b) const = 0; 
	virtual ~Operator() {} 
protected:
	const string m_symbol; // 运算符符号 
	const int m_numOprand; // 运算符目数 
	const int m_precedence; };
  • Factory
#define REGISTRAR(T, Key)	Factory::RegisterClass<T> reg_##T(Key);
class Factory {
public:
	template<typename T>
	struct RegisterClass {
		RegisterClass(string opr) {
				Factory::ms_operator.emplace(opr, [] {return make_shared<T>(); });
		} 
	};
	static shared_ptr<Operator> create(string opr); 
	static map<string, function<shared_ptr<Operator>()>> ms_operator;
};
  • Node
template<typename T> 
class Node { 
	friend class Stack<T>; 
	T m_value; 
	Node* m_next = nullptr; 
public:
	Node() = default; // 默认构造函数 
	Node(const Node& rhs) = delete; // 禁用拷贝构造函数 
	Node& operator =(const Node& rhs) = delete; 
	Node(const T& val) :m_value(val) {} // 含参构造函数 
	Node(T&& val) :m_value(std::move(val)) { } // 含参移动构造函数 
	const T& value() const { return m_value; } 
	Node* next() { return m_next; }
};
  • Stack
template<typename T> 
class Stack { 
	Node<T>* m_top = nullptr; 
public:
	Stack() = default; 
	Stack(const Stack&) = delete; 
	Stack& operator=(const Stack&) = delete; 
	~Stack(); void clear(); 
	void push(const T& val); 
	void push(T&& val); \
	void pop(); 
	bool empty()const ; 
	const T& top() ;
};

Results

More

If you want to know more about this code, you can click the detailed explanation of this code or contact me via the link above.😊

calculator_qt's People

Contributors

qitianyu-0403 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.