C + + WMA algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.