Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
table.h
00001 #ifndef _TABLE_ 00002 #define _TABLE_ 00003 00004 #include "mbed.h" 00005 class table{ 00006 public: 00007 table(int times); 00008 ~table(); 00009 void SIN_table(void); 00010 void COS_table(void); 00011 void make_table(double (*fnc)(int)); 00012 double show(int num); 00013 double deg(double degree); 00014 double rad(double radian); 00015 private: 00016 int number; 00017 double *ans; 00018 double M_PI; 00019 private: 00020 }; 00021 #endif 00022 /* 00023 byDONAV___2017/03/19 00024 main関数だけ抜粋 00025 基本的にはcで書かれたほうのライブラリと使い方は同じだが、ユーザの手数をクラスを用いることによって減らしたバージョンがこれである。 00026 00027 コンストラクタとデスコントラクタ 00028 コンストラクタの引数はテーブルのサイズまたは、三角関数の精度となる。 00029 デスコントラクタは動的確保した配列の消去を行う。 00030 00031 メンバ関数の説明 00032 SIN_table 00033 正弦の値を動的確保した配列に代入する。 00034 00035 COS_table 00036 余弦の値を動的確保した配列に代入する。 00037 00038 make_table 00039 ユーザが定義した関数のポインタを引数として、動的確保した配列に代入する。 00040 00041 show 00042 基本的にはmake_tableを用いて配列に代入したときに用いる。 00043 引数の番号の配列の値を返す。 00044 00045 deg,rad 00046 基本的にはSIN_tableやCOS_tableを用いて配列に代入したときに用いる。 00047 引数は、degreeとradianの角度で、角度に対応した配列を返す。 00048 00049 プログラム例を下に記す。 00050 #include <stdlib.h> 00051 #include <stdio.h> 00052 #include <math.h> 00053 #include <class_table.h> 00054 double squad(int n){ 00055 return n*n; 00056 } 00057 int main(){ 00058 table sin_ta(1200); 00059 table cos_ta(1200); 00060 table sqa_ta(1200); 00061 sin_ta.SIN_table(); 00062 cos_ta.COS_table(); 00063 sqa_ta.make_table(squad); 00064 printf("%f",sin_ta.deg(30)); 00065 printf("%f",cos_ta.deg(60)); 00066 for(int i=0;i<1201;i++){ 00067 printf("%f\n",sqa_ta.show(i)); 00068 } 00069 } 00070 00071 00072 /////////////////////////////////////////////////////////////////////////////// 00073 実行結果 00074 0.50000 00075 0.50000 00076 */
Generated on Fri Aug 5 2022 06:59:11 by
