
作业社区
探索学习新天地,共享知识资源!
daishuuuu 的学生作业:
namespace A_Space { int calc(int a, int b) { int c; c = a + b; return c; } } namespace B_Space { int calc(int a, int b) { int c; c = a - b; return c; } } namespace A_Space { extern int calc(int a, int b); } namespace B_Space { extern int calc(int a, int b); } #include #include "space.h" int main(){ int a = 10; int b = 5; int c = 0; int d = 0; c = A_Space::calc(a, b); d = B_Space::calc(a, b); std::cout





阿大月 的学生作业:
#include #include #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 (str != NULL){ this->str = (char*)malloc((strlen(str) + 1)); int i = 0; for (i=0;istr[i] = str[i]; } this->str[i] = '\0'; } } void String::show(void){ cout str str[i], this->str[i]); } free(this->str); } int main(void){ String s("Hello World!"); s.show(); }





浪潮君 的学生作业:
#include #include // 引入ctype.h头文件,里面有isupper()函数 // 设计一个函数,统计字符串中大写字母的个数 int count_uppercase_character(const char str[]) { int count = 0; // 用来记录大写字母的数量 for (int i = 0; str[i] != ‘\0’; i++) { // 遍历字符串,直到遇到结束符’\0’ if (isupper((unsigned char)str[i])) { // 如果当前字符是大写字母 count++; // 计数器加1 } } return count; // 返回大写字母的总数 } int main() { char buf[] = “I Love China”; // 定义一个字符串 int uppercase_count = count_uppercase_character(buf); // 调用函数统计大写字母数量 printf("Number of uppercase characters: %d\n", uppercase_count); // 输出结果 return 0; // 程序正常结束 }





浪潮君 的学生作业:
#include int a[5]; // 全局数组 // 1. 输入数组 void input_array() { printf(“请输入5个整数:\n”); for (int i = 0; i < 5; i++) { scanf("%d", &a[i]); } } // 2. 输出数组 void output_array() { printf(“数组内容是:\n”); for (int i = 0; i < 5; i++) { printf("%d “, a[i]); } printf(”\n"); } // 3. 查找最大值 int find_max() { int max = a[0]; for (int i = 1; i < 5; i++) { if (a[i] > max) { max = a[i]; } } return max; } int main() { input_array(); // 输入数组 output_array(); // 输出数组 int max_value = find_max(); // 查找最大值 printf("数组中的最大值是:%d\n", max_value); return 0; }





慕运维8597106 的学生作业:
没用互斥锁的情况 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 185480 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 191622 linux@linux:~/learn/chapter12/thread$ linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 200000 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 200000 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 200000 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 200000 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 200000 linux@linux:~/learn/chapter12/thread$ ./a.out 100000 global = 198353 使用了互斥锁,再大也不会有问题 linux@linux:~/learn/chapter12/thread$ gcc job1-2--new.c -lpthread linux@linux:~/learn/chapter12/thread$ ./a.out 10000000 global = 20000000 linux@linux:~/learn/chapter12/thread$





浪潮君 的学生作业:
#include // 函数:计算两个整数中的较大值,使用值传递 int calc_data(int a, int b) { return (a > b) ? a : b; // 使用三目运算符,简洁返回较大值 } int main() { int a, b; // 定义输入的两个整数 int max_value; // 保存最大值 int sum; // 保存两个数的和 printf("请输入两个整数(以空格分隔):"); scanf("%d %d", &a, &b); // 读取用户输入的两个整数 // 调用函数计算最大值 max_value = calc_data(a, b); // 直接计算两个数的和 sum = a + b; // 输出最大值 printf("两个数中较大的数是: %d\n", max_value); // 输出总和 printf("两个数的和是: %d\n", sum); return 0; // 程序正常结束 }




