![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
编程练习
16
这个作者很懒,什么都没留下…
展开
-
c++程序设计语言第三章练习
6.6.1int i = 0;while(i < max_length){ if(*input_line == '?') quset_count++;}6.6.2 (a = (((b + (c * d)) << 2) & 8)) (a & (077 != 3)) ((a == b) || ((a == c) && (c < 5))) (c = (x != 0)) ((0 <=原创 2021-07-04 17:59:59 · 156 阅读 · 1 评论 -
c++程序设计语言第二章练习
5.9.1#include <iostream>#include <string>using namespace std;int main(void){ char x = 'a'; char * ch = &x; int num[10]; for(int i = 0; i < 10; i++) { num[i] = i; } int (&n)[10] = num; stri原创 2021-07-01 18:10:42 · 127 阅读 · 0 评论 -
c++程序设计语言第一章练习
by:学完cpp primer plus之后对游戏辅助感兴趣去学了7章windows程序设计之后研究了下imgui,把imgui自带的绘图函数封装了个绘图类,平时写辅助够用了又回来继续cpp了4.11.1#include <iostream>int main(void){ std::cout << "Hello World!" << std::endl; return 0;}我理解的意思是声明改定义,定义改声明,写了没把全部写完4.11.2原创 2021-06-30 21:52:19 · 142 阅读 · 1 评论 -
C++ Primer Plus第十八章练习
18.12.1#include <iostream>#include <initializer_list>using namespace std;template <typename T>T average_list(initializer_list<T>);int main(void){ auto q = average_list({15.4, 10.7, 9.0}); cout << q << endl原创 2021-06-17 15:21:09 · 117 阅读 · 0 评论 -
C++ Primer Plus第十七章练习
看完16章之后觉得又行了 直接去看了2天windows程序设计 看晕了又回来继续cpp了17.8.1#include <iostream>using namespace std;int main(void){ int count = 0; cout << "请输入一串字符串:"; char temp[30]; cin.get(temp, 30, '$'); for(int i = 0; temp[i]; i++) co原创 2021-06-15 16:34:44 · 146 阅读 · 0 评论 -
C++ Primer Plus第十六章练习
不得不说16章的STL初学者噩梦 看到算法那直接省略跳过了16.10.1#include <iostream>#include <string>using namespace std;bool Petest(const string &);int main(void){ cout << "otto是否是回文: " << (Petest("otto") ? "是" : "不是") << endl; return原创 2021-06-10 00:03:41 · 161 阅读 · 0 评论 -
C++ Primer Plus第十五章练习
15.8.1很简单 只需要多添加2个方法和一个状态就行 不过令我不解的是为什么需要将remote前向声明tv.h#ifndef TV_H#define TV_H#include <iostream>using namespace std;class Remote;//????这是为何 书上说如果声明为友元类就不需要前向声明了 如果没有这个不通过编译class Tv{public: friend class Remote; enum { Off, On };原创 2021-06-03 21:28:03 · 103 阅读 · 0 评论 -
C++ Primer Plus第十四章练习
14.7.1Wine.h#ifndef WINE_H#define WINE_H#include <iostream>#include <valarray>#include <string>using namespace std;template <typename T1, typename T2>class Pair{private: T1 a; T2 b;public: Pair(void) {} i原创 2021-05-29 23:37:20 · 147 阅读 · 0 评论 -
C++ Primer Plus第十三章练习
13.11.1成员数据并无不需要动态内存分配所以不需要拷贝构造与赋值构造Cd.h#ifndef CD_H#define CD_H#include <iostream>#include <cstring>using namespace std;class Cd{private: char performers[50]; char label[20]; int selections; double playtime;public:原创 2021-05-24 16:31:13 · 143 阅读 · 0 评论 -
C++ Primer Plus第十二章练习
12.10.1Cow.cpp#include "Cow.h"Cow::Cow(void){ strcpy(name, "xswl"); hobby = new char[1]; hobby[0] = '\0'; weight = 0;}Cow::Cow(const char * nm, const char * ho, double wt) : weight(wt){ strcpy(name, nm); hobby = new char[strl原创 2021-05-21 14:51:24 · 123 阅读 · 0 评论 -
C++ Primer Plus第十一章练习
11.9.1类和类定义直接使用????上的 main添加个fstream头文件让他输出进文件里就行了vector.h#ifndef VECTOR_H_#define VECTOR_H_#include <iostream>#include <cstdlib>#include <ctime>#include <cmath>#include <fstream>using namespace std;namespace VECTOR原创 2021-05-18 14:40:39 · 122 阅读 · 0 评论 -
C++ Primer Plus第十章练习
10.10.1main.cpp#include "bank.h"int main(void){ bank a, b("伞兵", "111111", 999999); a.show(); b.show(); b.fetch(5631); b.show(); b.save(5631); b.show(); return 0;}bank.h#ifndef BANK_H#define BANK_H#include <iostr原创 2021-05-15 16:40:32 · 112 阅读 · 0 评论 -
C++ Primer Plus第九章练习
9.6.1main.cpp#include "golf.h"int main(void){ golf arr[2]; char temp1[30]; int temp2, i; for(i = 0; i < 2; i++) { cout << "请输入球手名字: "; cin.getline(temp1, 29); if(!temp1[0]) break;原创 2021-05-12 20:38:35 · 73 阅读 · 0 评论 -
C++ Primer Plus第八章练习
8.8.1#include <iostream>using namespace std;void show(const char *, int n = 0);int main(void){ show("xswl"); show("xswl", 1); return 0;}void show(const char * s1, int n){ if(n) cout << s1 << endl;}8.8.2原创 2021-05-10 15:26:12 · 107 阅读 · 0 评论 -
C++ Primer Plus第七章练习
7.13.1#include <iostream>using namespace std;int Calculate(int, int);int main(void){ int num1, num2; while(cin >> num1 >> num2 && num1 > 0 && num2 > 0) cout << num1 << "与" << nu原创 2021-05-07 16:01:39 · 139 阅读 · 0 评论 -
C++ Primer Plus第六章练习
6.11.1#include <iostream>#include <cctype>using namespace std;int main(void){ char ch; while(cin >> ch && ch != '@') { if(isupper(ch)) ch = tolower(ch); else if(islower(ch))原创 2021-05-05 15:45:07 · 74 阅读 · 0 评论 -
C++ Primer Plus第五章练习
5.9.1#include <iostream>using namespace std;int main(void){ int sum = 0; int one, two; cout << "请指定第一个数: "; cin >> one; cout << "请指定第二个数: "; cin >> two; for(int i = one; i <= two; i++)原创 2021-05-04 15:18:13 · 96 阅读 · 0 评论 -
C++ Primer Plus第四章练习
4.13.1#include <iostream>using namespace std;int main(void){ cout << "What is your first name? "; char fname[20]; cin.getline(fname, 19); cout << "What is your last name? "; char lname[20]; cin.getline(lname, 1原创 2021-05-02 19:16:26 · 81 阅读 · 0 评论 -
C++ Primer Plus第三章练习
3.7.1#include <iostream>using namespace std;int main(void){ const float Feet = 0.0833; cout << "请输入您的身高:______\b\b\b\b\b\b"; int inch; cin >> inch; cout << "转换为英尺后:" << Feet * inch << endl; re原创 2021-04-29 17:54:48 · 73 阅读 · 0 评论 -
C++ Primer Plus第二章练习
2.7.1#include <iostream>using namespace std;int main(void){ cout << "姓名:XXX" << endl; cout << "地址:XXX" << endl; return 0;}2.7.2#include <iostream>using namespace std;int main(void){ cout <&l原创 2021-04-28 21:57:02 · 126 阅读 · 0 评论 -
C和指针第十八章编程练习
18.8.1使用codeblocks的汇编调试发现代码如下 push %ebp mov %esp,%ebp mov 0x8(%ebp),%edx mov 0xc(%ebp),%eax add %eax,%edx mov 0x10(%ebp),%eax add %edx,%eax pop %ebp ret然后发现codeblocks并不能写汇编vc++????✍内联汇编应该是_asm{原创 2021-03-31 12:09:21 · 149 阅读 · 0 评论 -
C和指针第十七章编程练习
17.10.1void resize_stack(size_t size){ assert(stack != NULL); stack_size = size; realloc(stack, sizeof(STACK_TYPE) * size); assert(stack != NULL);}17.10.2接口#include <stdio.h>#include <stdlib.h>#include <assert.h>原创 2021-03-30 18:07:39 · 164 阅读 · 1 评论 -
C和指针第十六章编程练习
16.13.1#include <stdio.h>#include <stdlib.h>int main(int argc, char * argv[]){ if(argc < 2) { perror("argc"); exit(1); } int i; long num = strtol(argv[1], NULL, 10); for(i = 2; i < 37 &&原创 2021-03-27 16:49:46 · 648 阅读 · 0 评论 -
C和指针第十五章编程练习
15.22.1#include <stdio.h>int main(void){ int ch; while((ch = getchar()) != EOF) putchar(ch); return 0;}15.22.2#include <stdio.h>int main(void){ char temp[81]; while(fgets(temp, 80, stdin)) fputs(temp原创 2021-03-24 16:21:13 · 267 阅读 · 0 评论 -
C和指针第十四章编程练习
14.10.1void print_ledger(int a){ #if OPTION_LONG print_ledger_long(); #elif OPTION_DETAILED print_ledger_detailed(); #else print_ledger_default(); #endif}14.10.2cpu_type.h#ifndef CPU_TYPE_H_INCLUDED#define CPU_TYPE_H_原创 2021-03-20 20:34:39 · 100 阅读 · 0 评论 -
C和指针第十三章编程练习
13.10.1#include <stdio.h>#include <ctype.h>int control(char ch);int space(char ch);int num(char ch);int low(char ch);int up(char ch);int pun(char ch);int noprint(char ch);int main(void){ int (*pt[7])(char) = {control, space, num, lo原创 2021-03-20 13:21:10 · 235 阅读 · 0 评论 -
C和指针第十二章编程练习
12.8.1必须知道链表类型 修改改函数可用于遍历链表typedef struct list{ int i; struct list * n;}List;int listcount(List * d){ int count = 0; while(d->n) { count++; d = d->n; } return count;}12.8.2无序有序都可以用这个List * find原创 2021-03-18 22:55:32 · 301 阅读 · 0 评论 -
C和指针第十一章编程练习
11.11.1void * my_calloc(size_t n, size_t m){ void * temp = malloc(n * m); if(!temp) return NULL; return temp;}11.11.2int * read(void){ int count = 1; int * temp = (int *)malloc(sizeof(int)), value; puts("请输入一列整数:");原创 2021-03-17 12:21:30 · 152 阅读 · 0 评论 -
C和指针第十章编程练习
10.11.1typedef struct{ int area; int swboard; int standnum;}phone;typedef struct{ int year; int month; int day;}data;typedef struct{ data dat; float time; phone your; phone his; phone pay;}longcall;10.11.2typedef struct{ char name[原创 2021-03-16 16:03:02 · 202 阅读 · 0 评论 -
C和指针第九章编程练习
9.14.1#include <stdio.h>#include <ctype.h>int main(void){ char str[50]; if(gets(str) && str[0]) { int i; int char_num[7] = {0}; for(i = 0; str[i]; i++) { if(iscntrl(str[i])) char_num[0]++; else if(isspace(str[i]原创 2021-03-15 22:47:08 · 492 阅读 · 0 评论 -
C和指针第八章编程练习
8.8.1#include <stdio.h>int main(void){ static char char_value[3][6][4][5] = { { { {}, {}, {}, {} }, { {}, {}, {}, {} }, { {}, {}, {}, {} }, { {}, {}, {}, {}原创 2021-03-14 15:52:00 · 397 阅读 · 0 评论 -
C和指针第七章编程练习
7.11.1int hermite(int n, int x){ if(n <= 0) return 1; else if(n == 1) return 2 * x; else return 2 * x * hermite(n - 1, x) - 2 * (n - 1) * hermite(n - 2, x);}7.11.2循环写法int gcd(int m, int n){ if(m < 0 ||原创 2021-03-13 12:13:30 · 179 阅读 · 0 评论 -
C和指针第六章编程练习
6.18.1char * find_char(const char * source, const char * chars){ if(source == NULL || chars == NULL || *source == '\0' || *chars == '\0')//检测 return NULL; const char * temp = chars;//用个临时指针保存chars的起始地址 while(*source) { whi原创 2021-03-12 14:39:10 · 342 阅读 · 0 评论 -
C和指针第五章编程练习
5.9.1#include <stdio.h>#include <ctype.h>int main(void){ char ch; while((ch = getchar()) != '\n') { if('A' <= ch && ch <= 'Z') ch = tolower(ch); putchar(ch); } return 0;}5.9.2原创 2021-03-10 17:02:21 · 198 阅读 · 0 评论 -
C和指针第四章编程练习
4.14.1#include <stdio.h>int main(void){ double n = 1, n1 = -1;//用于计算的2个数,n1可不初始化但不严谨这里用≠n的值都可以 double n2;//用户输入的数 puts("输入一个值计算平方根:"); scanf("%lf", &n2); if(n2 > 0) { while(n != n1) { n1 =原创 2021-03-09 19:12:56 · 114 阅读 · 0 评论 -
C和指针第二章编程练习
2.8.1main.c#include <stdio.h>int increment(int);int negata(int);int main(void){ printf("increment(10):%d\n", increment(10)); printf("increment(0):%d\n", increment(0)); printf("increment(-10):%d\n", increment(-10)); printf("negat原创 2021-03-07 15:31:00 · 198 阅读 · 0 评论 -
C和指针第一章编程练习
C和指针第一章编程练习1.8.1#include <stdio.h>int main(void){ printf("Hello World\n"); return 0;}1.8.2#include <stdio.h>int main(void){ int i = 1; char str[500]; while(gets(str))//与gets(str) != NULL意思相同 { printf("%原创 2021-03-06 19:51:34 · 268 阅读 · 0 评论