Here's a C++ program that creates a star with five explicit angles:

#include <iostream>
#include <cmath>

int main() {
    const double PI = std::acos(-1.0);
    const int NUM_POINTS = 10;
    const double ANGLE = 2 * PI / NUM_POINTS;
    const double ANGLE_OFFSET = PI / 2;
    
    double x[NUM_POINTS];
    double y[NUM_POINTS];
    
    // Calculate points of star
    for (int i = 0; i < NUM_POINTS; i++) {
        double angle = i * ANGLE + ANGLE_OFFSET;
        double radius = (i % 2 == 0) ? 1.0 : 0.5;
        x[i] = radius * std::cos(angle);
        y[i] = radius * std::sin(angle);
    }
    
    // Print coordinates of star
    for (int i = 0; i < NUM_POINTS; i++) {
        std::cout << '(' << x[i] << ', ' << y[i] << ')' << std::endl;
    }
    
    return 0;
}

This program utilizes a constant number of points (10) to construct a star with five distinct angles. It determines the star's points using trigonometric functions and outputs the x and y coordinates of each point. The resulting output should resemble this:

(0, 1)
(-0.951057, 0.309017)
(0.587785, 0.809017)
(-0.587785, -0.809017)
(0.951057, -0.309017)
(0, -0.5)
(-0.951057, -0.309017)
(0.587785, -0.809017)
(-0.587785, 0.809017)
(0.951057, 0.309017)

These coordinates can then be employed to draw the star using a graphics library or another technique.

C++ Program to Generate a Star with Five Explicit Angles

原文地址: https://www.cveoy.top/t/topic/l6IR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录