写一个c++程序构造一个X坐标为222,Y坐标为66,半径为5的圆形,5秒后删除
时间: 2023-06-03 09:04:21 浏览: 45
以下是符合要求的C语言代码:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
int x = 222, y = 66, radius = 5;
circle(x, y, radius);
delay(5000);
cleardevice();
getch();
closegraph();
return 0;
}
相关问题
写一个c++程序构造一个X坐标为222,Y坐标为66,半径为5的圆形和一个坐标为(100,200)长为100,宽为50的矩形,5秒后删除圆形
好的,以下是这个问题的C语言代码:
#include <graphics.h>
#include <stdlib.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// 绘制圆形
int x = 222;
int y = 66;
int r = 5;
circle(x, y, r);
// 绘制矩形
int x0 = 100;
int y0 = 200;
int x1 = x0 + 100;
int y1 = y0 + 50;
rectangle(x0, y0, x1, y1);
// 等待5秒钟
delay(5000);
// 删除圆形
setcolor(BLACK);
circle(x, y, r);
getch();
closegraph();
return 0;
}
用C++写一个软件,生成椭圆坐标点,点数为360,保存到txt文件
以下是用C++编写生成椭圆坐标点并保存到txt文件的示例代码:
```c++
#include <iostream>
#include <fstream>
#include <cmath>
const double PI = 3.14159265358979323846;
int main() {
// 椭圆的长轴半径和短轴半径
double a = 20.0;
double b = 10.0;
// 生成360个点
int num_points = 360;
// 打开文件
std::ofstream outfile("ellipse_points.txt");
if (!outfile.is_open()) {
std::cerr << "Failed to open file!" << std::endl;
return 1;
}
// 生成椭圆上的点并保存到文件
for (int i = 0; i < num_points; ++i) {
double angle = i * 2.0 * PI / num_points;
double x = a * std::cos(angle);
double y = b * std::sin(angle);
outfile << x << " " << y << std::endl;
}
// 关闭文件
outfile.close();
std::cout << "Points saved to file: ellipse_points.txt" << std::endl;
return 0;
}
```
首先定义了椭圆的长轴半径a和短轴半径b,以及要生成的点数num_points。然后打开文件"ellipse_points.txt",如果打开失败则输出错误信息并返回1。接着使用for循环生成椭圆上的点,算法是将360个点均匀地分布在椭圆周上,计算每个点的坐标,并将其保存到文件中。最后关闭文件并输出成功信息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)