#include<iostream> using namespace std; class Calc { private://声明私有成员,外部类不能访问 int sum; int diff; int pro; int que; public://声明公有方法,所有类都可以调用 void add(int num1, int num2) { sum =num1 + num2; printf("%d=%d+ %d\n", sum, num1, num2); } void sub(int num1, int num2) { diff = num1 - num2; printf("%d=%d-%d\n", diff, num1, num2); } void mul(int num1, int num2) { pro = num1 - num2; printf("%d=%d-%d\n", pro, num1, num2); } void div(int num1, int num2) { que = num1 / num2; printf("%d=%d/%d\n", que, num1, num2); } }; int main(void) { Calc test; test.add(12, 13); test.sub(8,9); test.mul(5,6); test.div(24, 4); getchar(); return 0; }
时间: 2024-10-05 07:32:00