
作业社区
探索学习新天地,共享知识资源!
胡汉三66 的学生作业:
#include #include // c ==> c++ ==> 两个数据库都可以 using namespace std; class String { public: //共有成员 可以在对象外使用 String(const char *str = NULL);// 构造函数 String(const String &obj); // 拷贝构造函数 void show(void); // 输出字符串中的每个字符和对应的ASCII码 ~String(); // 析构函数 char &operator[](const int index); // 声明 类成员函数: "[]"运算符重载函数 int size(){ // 成员函数 return strlen(str); } private: //私有成员 只能类成员可以使用 char *str; }; String::String(const char *str) //构造函数 { cout 堆区分配内存 strcpy(this->str,str); // 复制 字符串 }else{ this->str = NULL; //如果传入的指针为空,则將成员变量 str 设置为 NULL } } String::String(const String &obj) // 拷贝构造函数 { cout 堆区分配内存 strcpy(this->str,obj.str); // 复制 字符串 }else{ this->str = obj.str; // 浅拷贝 ==>释放内存 会出现问题 } } String::~String() // 析构函数 { cout





学无止境呀呀呀 的学生作业:
void ouputc(char *s,int n) { int i = 0; for(i = 0;i < n;i++) { printf("%c ",s[i]); } printf("\n"); } void buddle_sortc(char *p,int n) { int i = 0,j = 0; for(i = 0;i < n - 1;i++) //轮数 { for(j = 0;j < n - 1 - i;j++) { if(p[j] == 0 || p[j+1] ==0 ) continue; if(p[j] > p[j + 1]) { p[j] = p[j] ^ p[j + 1]; p[j + 1] = p[j + 1] ^ p[j]; p[j] = p[j] ^ p[j + 1]; } } } return ; } int main() { unsigned char str[] = "decba "; int n = sizeof(str)/sizeof(str[0]); ouputc(str,n); buddle_sortc(str,n); ouputc(str,n); return 0; }





满足各态历经性的XC 的学生作业:
#include #include #include #include #include #include #include void ip_convert(const char *ip, const char *port) { struct in_addr net_addr; int ret; uint32_t net_port; uint32_t host_port; //1 ip ----> networks ret = inet_aton(ip, &net_addr); if(ret == 0) { fprintf(stderr, "Invalid IP address!\n"); return; } printf("net_addr: %#X\n", net_addr.s_addr); //2 networks ----> ip printf("net_addr: %s\n", inet_ntoa(net_addr)); //3 port ----> network net_port = htonl(atoi(port)); printf("net_port: %#X\n", net_port); //4 network ----> host host_port = ntohl(net_port); printf("host_port: %d\n", host_port); } int main(int argc, char *argv[]) { if (argc < 3) { fprintf(stderr, " Usage : %s ip !\n", argv[0]); return -1; } ip_convert(argv[1], argv[2]); return 1; }




