#include<iostream> #include<conio.h> #include<graphics.h> #include<time.h> #include<math.h> using namespace std; class Csin { double A, W, B, x_bg,x_end,b_bg, b_end; int step=1; public: Csin(double a, double w, double b, double x_b, double x_e,double b_b, double b_e) { A = a, W = w, B = b; x_bg = x_b,x_end=x_e; b_bg = b_b, b_end = b_e; } void cartoon() { double B1 = b_bg; while (B1 <= b_end) { for (double i = x_bg; i <= x_end; i++) { line(i, A * sin(W * i + B) + 150, i + step, A * sin(W * (i + step) + B) + 150); } B1++; Sleep(30); cleardevice(); } } }; int main() { double a,b,c,d,e; initgraph(800,800); srand(time(0)); a = rand() % 100; b = rand() % 100*0.01; c = rand() % 5; d = rand() % 200+100; do { e = rand() % 200+100;} while(e < d); Csin C1(a,b,c,200.0,400.0,d,e); _getch(); closegraph(); return 0; }有什么bug?
时间: 2024-04-10 11:28:13 浏览: 13
While循环的基本语法是:
```
while (条件) {
// 循环执行的代码
}
```
其中,条件是一个布尔表达式。只要条件为真,就会一直执行循环体中的代码,直到条件为假才会停止循环。
例如,下面的代码使用 while 循环输出 1 到 10 的整数:
```
int i = 1;
while (i <= 10) {
cout << i << " ";
i++;
}
```
输出结果为:1 2 3 4 5 6 7 8 9 10
在每次循环开始时,都会检查条件 i <= 10 是否满足。只要满足条件,就会执行 cout << i << " "; 和 i++; 的语句,然后再次检查条件。当 i 变成 11 时,不满足条件,循环停止。
相关问题
#include <string.h>#include <iomanip>
这是C++中引入头文件的方式,`#include <string.h>`用于字符串处理,`#include <iomanip>`则用于流输入输出流的格式控制。下面是两个头文件的简介:
1.`#include <string.h>`是C和C++的标准头文件之一,提供了字符串处理函数和一些有关内存操作的函数。
2.`#include <iomanip>`则提供了一组流操纵符和一些操纵符的操作函数,可以用于格式控制输出流的各种格式。
举个例子,下面的代码演示了如何使用`<iomanip>`头文件中的操作符`setw()`设置输出的字段宽度为10个字符:
```c++
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int x = 123456;
cout << "x = " << setw(10) << x << endl;
return 0;
}
```
运行结果为:
```
x = 123456
```
#include <iostream>和#include <stdio.h>区别
#include <iostream>和#include <stdio.h>都是C++和C语言中的头文件库,但是它们有一些区别。
1. iostream是C++的库,而stdio.h是标准C的库。
2. 在C++中,使用#include <iostream>的时候,需要在下边加上using namespace std;,而使用#include <stdio.h>则不需要。
3. 在C++中,iostream库中的cout和cin可以直接使用,而在C语言中,需要使用printf和scanf函数。
4. iostream库中的函数和类更加面向对象,而stdio.h库中的函数更加面向过程。
5. 在C++中,iostream库中的函数和类可以进行重载,而在stdio.h库中的函数则不行。