c++头文件:cdraw

目录

前文

头文件源码

函数逐个解析

1.drawCircle

2.drawdrawTriangle

3. drawRectangle

头文件使用方法

不那么温馨的温馨提示

后文


前文

  本期博客,我会分享一个我自制的c++头文件:#include ,有什么意见可以提出来。

头文件源码

#ifndef CDARW_H 
#define CDRAW_H
#include 
#include 
using namespace std;

void drawCircle(int radius,int a) {
		bool isFilled;
		if(a==1){
			isFilled=true;
		}else{
			isFilled=false;
		}
    for (int y = -radius; y <= radius; y++) {
    
        for (int x = -radius; x <= radius; x++) {
            double distance = sqrt(x * x + y * y);
            if (isFilled) {
                if (distance <= radius) cout << "*";
                else cout << " ";
            } else {
                if (distance >= radius - 0.5 && distance <= radius + 0.5) std::cout << "*";
                else cout << " ";
            }
        }
       cout << "\n";
    }
  }
  // 绘制三角形
 void drawTriangle(int x, int y, bool z) {
     // 验证输入参数
     if (x <= 0 || y <= 0) {
         cout << "错误:底和高必须为正整数" << endl;
         return;
     }
     
     // 确保底边长度为奇数,以保证三角形居中
     if (x % 2 == 0) {
         x++;
         cout << "提示:底边长度已调整为奇数:" << x << endl;
     }
     
     // 计算最大可能的高度
     int maxHeight = (x + 1) / 2;
     if (y > maxHeight) {
         y = maxHeight;
         cout << "提示:高度已调整为最大可能值:" << y << endl;
     }
     
     // 计算每行的星号数量
     int starsPerLine = 1;
     int step = (x - 1) / (y - 1);
     
     for (int i = 0; i < y; i++) {
         // 计算当前行的星号数量
         if (i > 0) {
             starsPerLine += step;
             // 确保不超过底边长度
             if (starsPerLine > x) {
                 starsPerLine = x;
             }
         }
         
         // 计算左侧空格数量
         int spaces = (x - starsPerLine) / 2;
         
         // 输出左侧空格
         for (int j = 0; j < spaces; j++) {
             cout << " ";
         }
         
         // 输出星号
         if (z || i == 0 || i == y - 1) {
             // 实心三角形或第一行/最后一行:输出全部星号
             for (int j = 0; j < starsPerLine; j++) {
                 cout << "*";
             }
         } else {
             // 空心三角形:只输出边缘的星号
             for (int j = 0; j < starsPerLine; j++) {
                 if (j == 0 || j == starsPerLine - 1) {
                     cout << "*";
                 } else {
                     cout << " ";
                 }
             }
         }
         
         // 换行
         cout << endl;
     }
 }


 void drawRectangle(int x,int y,int z){
 	int flag;
 	if(x<2||y<2){
	 	cout<<"你逗我玩呢?";
	 flag=1;
	 }
	 if(flag!=1){
 	 if(z==1){//实心
	  	for(int a=1;a<=x;a++){
 		 	for(int b=1;b<=y;b++){
 			 	cout<<"*";
 			 }
 			 cout<

函数逐个解析

1.drawCircle

它的作用是生成一个圆,用法是drawCircle(x,y)。其中x为圆的半径,如果y为1,那么绘制实心圆,否则绘制空心圆。

2.drawTriangle

  它的作用是生成三角形,用法是drawTriangle(x,y,z)。其中x为底,y为高,z与drawCircle(x,y)中的y相同。

3. drawRectangle

它的作用是生成方形,用法是 drawRectangle( x, y, z)。其中x为长,y为宽,z与drawCircle(x,y)中的y相同。

头文件使用方法

  把cdraw.h放在Dev-Cpp\MinGW64(或32)\include文件夹中(Dev-C++的默认安装目录是C:\Program Files (x86)\Dev-Cpp),然后在代码开头调用它,就像这样:

#include 

  点这里下载。

不那么温馨的温馨提示

《民法典》第1185条(知识产权侵权惩罚性赔偿)
  内容:

“故意侵害他人知识产权,情节严重的,被侵权人有权请求相应的惩罚性赔偿。”

  解读:

  首次在民法基本法中确立知识产权侵权的惩罚性赔偿制度,大幅提高恶意侵权成本。适用于著作权领域,打击盗版、抄袭等故意侵权行为。

后文

  本期博客就到这里,我们下期再见!

你可能感兴趣的:(C++,c++,开发语言,算法)