CMakeLists.txt
Project (AAA) Add_library (AAA SHARED Aaa.cpp) add_executable (BBB bbb.cpp) target_link_libraries (BBB AAA)
Aaa.h
#pragma once#ifndef aaa_aaa_h#define aaa_aaa_h#endifclass father{ Private:public: int *fabonacci (int n); Double *wma (doubleint int int wmalen);};
Aaa.cpp
#include"aaa.h"#include<iostream>using namespacestd;int*father::fabonacci (intN) { if( ->= n >0) { int*array =New int[n]; Switch(n) { Case 1: {array[0] =1; cout<< array[0] <<Endl; Break; } Case 2: {array[0] =1; array[1] =1; cout<< array[0] <<Endl; cout<< array[1] <<Endl; Break; } default: {array[0] =1; array[1] =1; cout<< array[0] <<Endl; cout<< array[1] <<Endl; for(inti =2; I < n; i++) {Array[i]= Array[i-1] + array[i-2]; cout<< Array[i] <<Endl; } } } returnArray; } Else{cout<<"error!\n"<<Endl; returnNULL; }}Double*father::wma (Double*array,int*fabonacci,intArraylen,intWmalen) { intn =Wmalen; Double*wma =New Double[Arraylen]; if(Arraylen >= Wmalen >0) { int*PF =Father::fabonacci (Arraylen); while(Arraylen >=Wmalen) { Doublesum =0; for(inti = wmalen-n; i < Wmalen; i++) {sum= SUM + array[i] * (* (PF +i)); } Wma[wmalen-1] = SUM/Pf[arraylen]; cout<<"wma["<< Wmalen-1<<"] = "<< Wma[wmalen-1] <<Endl; Wmalen++; } Delete(PF); returnWMA; } Else{cout<<"error!\n"<<Endl; returnNULL; }}
Bbb.cpp
#include"aaa.h"#include<iostream>using namespacestd;template<typename t>intGetarraylen (T &Array) { return sizeof(array)/sizeof(array[0]);}intMain () {DoubleArray[] = {1,2,3,4,5,6,7,8,Ten,9, One, A}; Father Child; intLen =Getarraylen (array); int*PF =Child.fabonacci (len); Double*pwma = child.wma (Array, PF, Len,3); Delete(PF); Delete(PWMA); return 0;}
C + + WMA algorithm