Dialog Box-based calculator (addition, subtraction, multiplication, division)

Source: Internet
Author: User
/** Requirements: 1. create a simple calculator to implement simple addition, subtraction, multiplication, division operations. continuous operation */# include <iostream> # include <cstdlib> using namespace STD; Class number {public: Number (double AA = 0 ); void input (double a1 = 0); void calculate (); void main (); Number operator + (number & A1); Number operator-(number & A1 ); number operator * (number & A1); Number operator/(number & A1); friend istream & operator> (istream & input, number & N ); friend ostream & operator <(ostream & output, number & N); Private: Double A ;}; number: Number (double aa) {A = AA;} void Number:: input (double A1) {A = A1;} Number: Operator + (number & A1) {number M; M. A = a + a1.a; return m;} Number: Operator-(number & A1) {number M; M. A = a-a1.a; return m;} Number: Operator * (number & A1) {number M; M. A = A * a1.a; return m;} Number: Operator/(number & A1) {number M; M. A = A/a1.a; return m;} istream & operator> (istream & input, number & N) {input> N. a; return input;} ostream & operator <(ostream & output, number & N) {output <n. a; return output;} void number: Calculate () {number A, B, C; char F; CIN >>> F >> B; if (F = '+') {c = a + B; cout <C;} If (F = '-') {c = A-B; cout <C;} If (F = '*') {c = a * B; cout <C;} If (F = '/') {c = A/B; cout <C;} Main ();} void number: Main () {cout <Endl; cout <"select the operation type: 1. addition, subtraction, multiplication, division, and calculation; 0. exit simple calculator "<Endl; int C; CIN> C; Switch (c) {Case 0: exit (0); Case 1: Calculate (); break; default: cout <"Your selection is incorrect"; break ;}} int main () {number N; N. main ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.