
作业社区
探索学习新天地,共享知识资源!
幕布斯3194744 的学生作业:
#include using namespace std; class Test{ public: Test(int size){ this->data = new int[size]; //成员变量名为data this指向 this->index = 0; //index初始化 //this->size = size; } ~Test(){ delete[] data; //data为指针 } void insert(int data){ #if 0 if(this->index>=this->size) //此处最好需要进行是否未满判断 { return; } #endif this->data[this->index ++] = data; } void show(void){ for(int i = 0;i < index;i ++){ cout data[i] insert(i + 1); } t->show(); delete t; //释放堆区分配的内存 return 0; } 【图片】





幕布斯3194744 的学生作业:
#include #include using namespace std; class String{ public: String(const char *str = NULL); //有参构造函数 void show(void);//输出字符串中的每个字符和对应的ASCII码 private: char *str; //私有成员变量 }; String::String(const char *str) { if(NULL != str){ //对传入的参数进行判断 this->str = new char[strlen(str)+1]; strcpy(this->str,str); }else{ str = NULL; } } void String::show(void) { for(int i = 0;str && *str;i++){ //第二个没理解 cout





幕布斯3194744 的学生作业:
#include using namespace std; class Time{ private: int hour; int min; int sec; public: void setHour(int _hour); void setMin(int _min); void setSec(int _sec); void output_time(); }; void Time::setHour(int _hour) { hour = _hour; } void Time::setMin(int _min) { min = _min; } void Time::setSec(int _sec) { sec = _sec; } void Time::output_time() { cout




