
作业社区
探索学习新天地,共享知识资源!
慕运维8597106 的学生作业:
#include using namespace std; class Test{ public: Test(int size){ this->data = new int[size]; this->size = size; this->index = 0; //需要给索引赋初始值,不然可能是随机数赋值 } ~Test(){ delete [] data; //申请的是多个地址,释放应该加[] } void insert(int data){ if(this->index >= this->size) //判断空间是否已满 { return; } this->data[this->index++] = data; //需要this } void show(void){ for(int i= 0;i < index;i ++){ cout data[i] insert(i + 1); } t->show(); delete t; return 0; }





慕运维8597106 的学生作业:
1 #include using namespace std; int my_swap(int &a,int &b) { a = a ^ b; b = a ^ b; a = a ^ b; } int my_swap(float &a,float &b) { float t = a; a = b; b = t; } int my_swap(string &a,string &b) { string t = a; a = b; b = t; } int main() { int i1 = 10,i2 = 20; my_swap(i1,i2); cout





慕运维8597106 的学生作业:
任务1: #include using namespace std; void swap_point(int *a,int *b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; return; } void swap_reference(int &a,int &b) { a = a ^ b; b = a ^ b; a = a ^ b; } int main() { int a = 10,b = 20; swap_point(&a,&b); swap_reference(a,b); cout





慕后端3277080 的学生作业:
head.h #ifndef __HEAD_H__ #define __HEAD_H__ #include extern int add(int,int); extern int sub(int,int); extern int mul(int,int); extern int div(int,int); extern int x; extern int y; #endif calc.c int add(const int x,const int y) { return x + y; } int sub(const int x,const int y) { return x - y; } int mul(const int x,const int y) { return x * y; } int div(const int x,const int y) { return x / y; } main.c #include "head.h" int main() { int x; int y; printf("please intput two data : "); scanf("%d%d",&x,&y); printf("x + y = %d\n",add(x,y)); printf("x - y = %d\n",sub(x,y)); printf("x * y = %d\n",mul(x,y)); printf("x / y = %d\n",div(x,y)); return 0; }





慕运维8597106 的学生作业:
space.h #ifndef __SPACE_H__ #define __SPACE_H__ namespace A_Space { extern int calc(int a,int b); } namespace B_Space { extern int calc(int a,int b); } #endif space_a.cpp namespace A_Space { int calc(int a,int b) { return a + b; } } space_b.cpp namespace B_Space { int calc(int a,int b) { return a - b; } } main.cpp #include "space.h" #include using namespace A_Space; using namespace B_Space; using namespace std; namespace A = A_Space; namespace B = B_Space; int main() { int a = 10,b = 5; int result = A::calc(a,b); cout





Linkus 的学生作业:
内容不匹配,上传对应练习: /* 探测用户是否已经输入,如果用户在3秒内没有输入则提示超时一次,如果超时三次程序自动结束。*/ #include #include #include #include #include #include #include #include #include int cnt = 3; void alarm_handler(int sig) { if(sig == SIGALRM) { if(cnt) { printf(" No input within 3s. cnt < %d >\n",cnt--); alarm(3); } else { printf("Exit < User no input >\n"); exit(0); } } } int main(void) { char buffer[100]; if (signal(SIGALRM,alarm_handler) == SIG_ERR){ perror("[ERROR] signal(): "); exit(EXIT_FAILURE); } alarm(3); while(1) { printf("Please enter: \n"); if(fgets(buffer,sizeof(buffer),stdin) != NULL) { cnt = 3; printf("Received : %s ",buffer); } } return 0; }