C++ 为什么我的程序的轴关闭了 //============================================================================ //姓名:Assignment.cpp //作者:Tim Bialecki //版本: //============================================================================ #包括 #包括 使用名称空间std; 空心圆(整数x,整数y,整数半径); 虚线(内部a、内部b、内部c、内部d); 布尔缓冲区[26][81]; 字符提取空间[26][81]; int main(){ INTA=75; int b=5; int c=4; int d=26; /*cout>x; cout>y; cout>半径*/ 圆圈(a、b、c); 对于(int col=80;col>=0;col--){ 对于(int行=25;行>=0;行--){ cout=26 | | y-半径
在我看来还行:C++ 为什么我的程序的轴关闭了 //============================================================================ //姓名:Assignment.cpp //作者:Tim Bialecki //版本: //============================================================================ #包括 #包括 使用名称空间std; 空心圆(整数x,整数y,整数半径); 虚线(内部a、内部b、内部c、内部d); 布尔缓冲区[26][81]; 字符提取空间[26][81]; int main(){ INTA=75; int b=5; int c=4; int d=26; /*cout>x; cout>y; cout>半径*/ 圆圈(a、b、c); 对于(int col=80;col>=0;col--){ 对于(int行=25;行>=0;行--){ cout=26 | | y-半径,c++,C++,在我看来还行: //============================================================================ // Name : Assignment.cpp // Author : Tim Bialecki // Version : //============================================================================
//============================================================================
// Name : Assignment.cpp
// Author : Tim Bialecki
// Version :
//============================================================================
#include <iostream>
#include <math.h>
using namespace std;
void circle(int x, int y, int radius);
void line(int a, int b, int c, int d);
bool buffer[26][81];
char drawSpace[26][81];
int main() {
int a = 75;
int b = 5;
int c = 4;
int d = 26;
/*cout << "please enter an x coordinate for the center of the circle";
cin >> x;
cout << "please enter a y coordinate for the center of the circle";
cin >> y;
cout << "please enter a value for the radius of the circle";
cin >> radius;*/
circle(a, b, c);
for (int col = 80; col >= 0; col--) {
for (int row = 25; row >= 0; row--) {
cout << drawSpace[row][col];
}
cout << "\n";
}
return 0;
}
void circle(int x, int y, int radius){
/*if (x + radius >= 81 || y + radius >= 26 || y - radius <= 26){
cout << "the coordinates provided for the circle will not fit on the screen" << endl;
return;
}*/
for (int i = 0; i < 26; i++) {
for(int j = 0; j < 81; j++) {
int a = abs (x - j);
int b = abs (y - i);
int distance = pow(a, 2) + pow(b, 2);
int realDistance = pow(radius, 2);
if (abs(realDistance - distance) <= 3){
buffer[i][j] = true;
}
}
}
for (int m = 0; m < 26; m++){
for(int n = 0; n < 81; n++){
if (buffer[m][n]){
drawSpace[m][n] = 42;
}
else
drawSpace[m][n] = 32;
}
}
}
void line(int a, int b, int c, int d){
int intercept = 0;
double rise = d - b;
double run = c - a;
double slope = rise/run;
intercept = b - (slope*a);
for (int i = 0; i < 26; i++) {
for(int j = 0; j < 81; j++) {
int newIntercept = i - (slope*j);
int test = abs (intercept - newIntercept);
if (test <= 0)
buffer[i][j] = true;
else
buffer[i][j] = false;
}
}
for (int m = 0; m < 26; m++){
for(int n = 0; n < 81; n++){
if (buffer[m][n])
drawSpace[m][n] = 42;
else
drawSpace[m][n] = 32;
}
}
}
它不是完美的圆形,因为角色的高度比宽度高
编辑:这只是我输出的前几行。根据注释和代码的第二次查看,我认为行和列混淆了
***
** **
* *
* *
* *
* *
* *
** **
***
for(int col=80;col>=0;col--){
对于(int行=25;行>=0;行--){
对于C++来说,看到这种赋值是很奇怪的。语言比这些更值得一提。IMO。对于我来说,Y轴是以X轴为轴打印的,图的顶部是Y轴。你知道,这个终端的左上角是0,0,这个系统中的行向下,列向右。
for (int col = 80; col >= 0; col--) {
for (int row = 25; row >= 0; row--) {
cout << drawSpace[row][col];
}
cout << "\n";
}