
作業社區
探索學習新天地,共享知識資源!
幕布斯3194744 的學生作業:
#include using namespace std; class Stu{ private: static Stu *stu; //靜態成員變量 Stu(); //構造函數私有化 public: static Stu *create_obj(void); //靜態成員函數 }; Stu *Stu::stu = NULL; //靜態成員變量初始化 Stu::Stu(){ } Stu* Stu::create_obj(void) { if(NULL == stu){ stu = new Stu(); } return stu; } int main(int argc, const char *argv[]) { Stu *stu1 = Stu::create_obj(); cout





幕布斯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




