c++
ZXkm020829
社会底层的码农正在努力往上爬
展开
-
自制简单计算器
//写一个计算器 //注释的部分为不是自定义输入数据时的计算器 #include<iostream> using namespace std; #include<string> class calculator { public: void printin(); /*void printout();*/ friend void test01(); float getrusult(string oper); private:float a; float b; float s原创 2021-04-24 19:50:02 · 93 阅读 · 0 评论 -
n的全排列
//n的全排列 #include<iostream> using namespace std; const int s = 10;//全排列的收纳盒 int n; int arr[s]; int hashtable[s] = { false };//整型数组 与布尔数组相互转化 void GE(int index) { //跳出循环的条件 //递归求全排列 for (int x = 1; x <= n; x++) { if (hashtable[x] == false)//第一个原创 2021-04-24 16:47:49 · 122 阅读 · 0 评论 -
重载+号运算符 使其矩阵相加
//重载+号运算符 使其两个矩阵相加 //矩阵的输入输出都需要使用for循环 行和列的循环 #include<iostream> using namespace std; class mix { public: friend mix operator+(mix&, mix&); void printin(); void printout(); private: int arr[2][3]; }; //输入数据 void mix::printin() { cout <原创 2021-04-24 13:25:35 · 409 阅读 · 0 评论 -
2021-04-22
重载加号运算符求两个矩阵相加 ```cpp ```cpp #include<iostream> using namespace std; //定义一个矩阵类 class Mix { public: void printin(); void printout(); friend Mix operator+(Mix& , Mix&); Mix(); private: int arr[2][3]; }; //构造函数 Mix::Mix() { for (int i = 0原创 2021-04-22 23:09:08 · 48 阅读 · 0 评论 -
2021-04-22
求平方 #include<iostream> using namespace std; int main() { //a代表我输入的数 int a; cin >> a; //i表示循环 i且代表数的指数 通过这个我能求某个数的某个次方 for (int i = 1; i < 20; i++) { //static为静态变量 初值为1,第一次之后变成2,不会释放 static long sum = 1; // static long sum=2;第二原创 2021-04-22 23:05:20 · 59 阅读 · 0 评论 -
c++课后习题
商店的售价 #include<iostream> using namespace std; class shop { public: shop(char n, int q, int p) :num(n), quantity(q), price(p) {}; friend float sum(shop& s); private: char num; int quantity; int price; }; float sum(shop& s) { int sum = 0;原创 2021-04-22 22:31:12 · 107 阅读 · 0 评论 -
运算符重载
自增运算符的重载 #include<iostream> using namespace std; class integer { public: friend ostream& operator<<(ostream& cout, integer myint); //重载自增运算符++a integer& operator++()//为什么返回的是引用 引用的好处形成链接 为了一直对一个数据进行递增 { m_a++; return *this;原创 2021-04-15 23:36:22 · 38 阅读 · 0 评论