summaryrefslogtreecommitdiffstats
path: root/code/MyCodes.html
diff options
context:
space:
mode:
Diffstat (limited to 'code/MyCodes.html')
-rw-r--r--code/MyCodes.html237
1 files changed, 237 insertions, 0 deletions
diff --git a/code/MyCodes.html b/code/MyCodes.html
new file mode 100644
index 0000000..0fc370f
--- /dev/null
+++ b/code/MyCodes.html
@@ -0,0 +1,237 @@
1<!DOCTYPE html>
2<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
3
4<head>
5 <meta charset="utf-8" />
6 <meta name="generator" content="pandoc" />
7 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
8 <title>我的实用代码</title>
9 <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css">
10 <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script>
11</head>
12
13<body>
14 <div class="pandoc">
15 <div class="main">
16 <header id="title-block-header">
17 <p class="title">我的实用代码</p>
18 </header>
19 <p>这里是英(C)语(yǔ)科(yán)听力部分。该部分有第一、第二两节。</p>
20 <p>请注意,回答听力部分时,请先将答案写在试卷上,听力部分结束前,你将有两分钟的时间将试卷上的答案转移到答题卡上。</p>
21 <p>听力考试,现在开始!</p>
22 <h1 id="光标隐藏函数">光标隐藏函数</h1>
23 <pre><code class="language-c">void HideCursor(void)
24{
25 CONSOLE_CURSOR_INFO cursor_info = {1, 0};
26 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &amp;cursor_info);
27}</code></pre>
28 <h1 id="show_bytes">show_bytes</h1>
29 <pre><code class="language-cpp">#include &lt;bits/stdc++.h&gt;
30using namespace std;
31typedef unsigned char* bite_pointer;
32typedef int T;//数据类型为int,可更改
33void show_bites(bite_pointer p,size_t len)
34{
35 size_t i;
36 cout&lt;&lt;&quot;In machine order:&quot;;
37 for(i=0;i&lt;len;i++)
38 {
39 printf(&quot;%.2x &quot;,p[i]);
40 }
41 printf(&quot;\n&quot;);
42 cout&lt;&lt;&quot;In person order: &quot;;
43 for(i=len-1;i&gt;0;i--)
44 {
45 printf(&quot;%.2x &quot;,p[i]);
46 }
47 printf(&quot;%.2x &quot;,p[i]);
48 printf(&quot;\n&quot;);
49}
50int main()
51{
52 int a;
53 cout&lt;&lt;&quot;Please input the data in type \&quot;int\&quot;:&quot;;
54 cin&gt;&gt;a;
55 show_bites((bite_pointer)&amp;a,sizeof(T));
56 return 0;
57}</code></pre>
58 <h1 id="界面设计和上色">界面设计和上色</h1>
59 <p>注意:<strong>本内容请勿改动任何参数!</strong></p>
60 <pre><code class="language-c">#include &lt;windows.h&gt;
61#include &lt;conio.h&gt;
62#include &lt;time.h&gt;
63
64int wide=60,high=30;//宏常量定义,数据可变
65HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//写在主函数或调用函数内部,用于定义hout并进行初始化
66system(&quot;mode con cols=80 lines=40 &quot;);//运行框大小限制
67
68void gotoxy(HANDLE hout,int x,int y)
69{
70 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
71 COORD pos;
72 pos.X = x;
73 pos.Y = y;
74 SetConsoleCursorPosition(hout,pos);
75}
76int color(int c)//设置颜色
77{
78 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
79 return 0;
80}//颜色有若干种
81//两个调用函数</code></pre>
82 <p>设置某句子的位置用<code>gotoxy(hout,wide*k,high*m)</code>,就是在 wide 的 k 倍,high 的 m 倍的位置。
83 句子上色用<code>color(c)</code>,c 为指定颜色序号。
84 输出后的停顿用<code>void Sleep(int t)</code>函数,在<code>&lt;windows.h&gt;</code>中,t 代表暂停的毫秒数。 使用时每个句子前都要用 gotoxy
85 指定位置,用 color 上色。 合起来如下:</p>
86 <pre><code class="language-c"> gotoxy(hout,wide/5,high/6);
87 color(6);
88 printf(&quot;本计算器仅支持5个及以下的矩阵,分别名为A~E(大写)。&quot;);
89 Sleep(200);
90 gotoxy(hout,wide/5,high/6+1);
91 color(6);
92 printf(&quot;每个矩阵阶数不超过5*5。&quot;);
93 Sleep(200);</code></pre>
94 <h1 id="关于音乐效果">关于音乐效果</h1>
95 <pre><code class="language-c">#include&lt;windows.h&gt;
96#include&lt;mmsystem.h&gt;
97#pragma comment(lib.&quot;Winmm.lib&quot;) //头文件
98PlaySound(TEXT(&quot;音乐名.wav&quot;),NULL,SND_FILENAME | SND_ASYNC | SND_LOOP);//开始播放
99PlaySound(NULL,NULL,SND_FILENAME);//结束播放</code></pre>
100 <p>注意:音频必须使用<strong>wav</strong>格式,必须放在<strong>跟代码同一个文件夹</strong>,如果不然,音乐名处<strong>应当使用其绝对地址或相对地址</strong>。
101 </p>
102 <h1 id="震动心形设计">震动心形设计</h1>
103 <pre><code class="language-c">#define I 20
104#define R 340
105
106int wide=80,high=40;//宏常量定义,数据可变
107system(&quot;title xxx&quot;);//运行框名称修改,主函数第一句
108system(&quot;mode con cols=80 lines=40 &quot;);//运行框大小限制
109
110void draw_color()//整体颜色震动效果函数
111{
112 char cl[20];
113 srand((unsigned int)time(NULL));
114 int k = rand() % strlen(back_color);
115 strcpy(cl, Color);
116 cl[len] = back_color[k];
117 srand((unsigned int)time(NULL));
118 k = rand() % strlen(font_color);
119 cl[len + 1] = font_color[k];
120 cl[len + 2] = &#39;\0&#39;;
121 system(cl);
122}</code></pre>
123 <p>颜色震动使用方法实例:</p>
124 <pre><code class="language-c">for(i=0;i&lt;6;i++,lower+=3)
125{
126 puts(data[i+15]);
127 for(j=0;j&lt;wait;j++)
128 {
129 draw_color();
130 Sleep(200);
131 }
132 Sleep(200);
133}
134void draw_heart(int wait)//心形设计函数,传入参数为0即可
135{
136 int i,j,e,a;
137 for(i=1,a=I;i&lt;I/2;i++,a--)
138 {
139 for(j=(int) ( I-sqrt(I*I-(a-i)*(a-i)) );j&gt;0;j--)
140 {
141 printf(&quot; &quot;);
142 }
143 for(e=1;e&lt;=2*sqrt(I*I-(a-i)*(a-i));e++)
144 {
145 printf(&quot;\3&quot;);
146 }
147 for(j=(int)( 2*( I-sqrt(I*I-(a-i)*(a-i)) ) );j&gt;0;j--)
148 {
149 printf(&quot; &quot;);
150 }
151 for(e=1;e&lt;=2*sqrt(I*I-(a-i)*(a-i));e++)
152 {
153 printf(&quot;\3&quot;);
154 }
155 printf(&quot;\n&quot;);
156 if(wait&amp;&amp;i%2)
157 {
158 draw_color();
159 Sleep(80);
160 }
161 }
162 for(i=1;i&lt;80;i++)
163 {
164 if(i==20)
165 {
166 for(int j=0;j&lt;40;j++)
167 {
168 printf(&quot;\3&quot;);
169 }
170 i+=40;
171 }
172 printf(&quot;\3&quot;);
173 }
174 printf(&quot;\n&quot;);
175 for(i=1;i&lt;=R/2;i++)
176 {
177 if(i%2||i%3)
178 {
179 continue;
180 }
181 for(j=(int) ( R-sqrt(R*R-i*i) );j&gt;0;j--)
182 {
183 printf(&quot; &quot;);
184 }
185 for(e=1;e&lt;=2*( sqrt(R*R-i*i) - (R-2*I) );e++)
186 {
187 printf(&quot;\3&quot;);
188 }
189 printf(&quot;\n&quot;);
190 if(wait)
191 {
192 draw_color();
193 Sleep(80);
194 }
195 }
196}</code></pre>
197 <h1 id="给代码加行号的代码">给代码加行号的代码</h1>
198 <pre><code class="language-c">#include&lt;stdio.h&gt;
199
200int main(void)
201{
202 FILE *fpIn;
203 // 输入文件的指针
204 FILE *fpOut;
205 // 输出文件的指针
206 char str[1000];
207 // 用来存储从文件中读取出的”一行“字符串信息
208 int row = 1;
209 fpIn = fopen(&quot;文件名.cpp&quot;, &quot;r&quot;);
210 /* 以只读和文本格式打开需要的.cpp文件
211 *这里的文件名无所谓大小写
212 */
213 fpOut = fopen(&quot;文件名.txt&quot;, &quot;w&quot;);
214 // 以创建方式(也叫写方式)打开文件名.txt文件
215 fgets(str, 81, fpIn);
216 /* 从文件中读取一行信息,保存到str数组中。
217 *这里要注意的是这个81,
218 *一般情况下,编写文本格式文件的人,都习惯遇到行尾就敲回车,
219 *所以,一般情况下,文本文件一行最多80个字符。
220 *如果,一行不够80个字符,这个函数会自动只读到&#39;\n&#39;就结束了。
221 */
222 while(!feof(fpIn))
223 { // 判断上一次fgets()是否正常(即,没有遇到文件尾部)
224 fprintf(fpOut, &quot;%4d %s&quot;, row, str);
225 // 在读入的每一行信息前,加入0000到9999的行号(应该够用了吧),呵呵呵呵
226 row++; // 行号加一
227 fgets(str, 81, fpIn); // 读取下一行
228 }
229 fclose(fpIn); // 关闭文件
230 fclose(fpOut);
231}</code></pre>
232 <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script>
233 </div>
234 </div>
235</body>
236
237</html> \ No newline at end of file