c和c++的一些训练题(8)(打印心形)

问题的提出:根据“心”形曲线的数学参数方程,绘制曲线并输出屏幕。在各坐标点处循环显示“LOVE”的各字母。

编程思路:“心”形曲线的数学参数方程为:


用xin[2*R+1][2*R+1]存储图形。

代码:

// test9_.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <math.h>

const int R = 16;//极坐标的半径
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	char xin[2*R+1][2*R+1];
	//初始化
	int x,y,t;
	double d;
	for (x=0; x<=2*R; x++)
	{
		for (y=0; y<=2*R; y++)
		{
			xin[x][y]=' ';
		}
	}
	for(t=0; t<=360; t+=5)
	{
		d=t*3.14159/180;//转换为弧度
		//i=(int)(R*sin(d/2)*sin(d));
		//j=(int)(R*sin(d/2)*cos(d));
		x=(int)(R*sin(d/2)*sin(d))+R;
		y=(int)(R*sin(d/2)*cos(d))+R;
		if(t%4==0)
			xin[x][y]='L';
		else if(t%4==1)
			xin[x][y]='O';
		else if(t%4==2)
			xin[x][y]='V';
		else if(t%4==3)
			xin[x][y]='E';
		else 
			xin[x][y]='*';
	}
		for (x=0; x<=2*R; x++)
		{
			for (y=0; y<=2*R; y++)
			{
				cout<<setw(2)<<xin[x][y];
			}
			cout<<endl;
		}

	system("pause");
	return 0;
}
结果:



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值