C/C++の宿題片付けます 129代目at TECH
C/C++の宿題片付けます 129代目 - 暇つぶし2ch211: ◆/91kCCQXBo
09/07/19 03:14:40
>>167 C++ で提出すれば君はヒーローだ。(星形の座標列を生成する)
#include <fstream>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
#define PI 3.1415926535897932384
void draw_star(ofstream &fout, float x1, int y1) {
  int i, dot;

  dot = abs(y1) + 4;
  for( i = 0; i <= dot; i++ ) {
    fout<<setw(6)<< cos(2*PI/dot*i)/2+x1 <<','<<setw(7)<< sin(2*PI/dot*i)/2+y1 <<endl;
    if( i < dot )
    fout<<setw(6)<< cos(2*PI/dot*(i+0.5))/4+x1 <<','<<setw(7)<< sin(2*PI/dot*(i+0.5))/4+y1 <<endl;
  }
  fout<<endl;
}
int main() {
  float x, xstep; int y;
  ofstream fout("polygon_29.csv");

  if(!fout) return 1;
  fout<<fixed<<setprecision(3);
  for( y = -10; y <= 10; y++ ) {
    xstep = 2.0 + 0.3 * abs(y);
    for( x=0.0; x<40.0; x += xstep ) {
      draw_star(fout, x, y);
    }
  }
  fout.close();
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch