如何将这些代码分解为.h,.cpp和main.cpp文件,并获得相同的结果 [英] how can i break theses codes into .h, .cpp and main.cpp files and achieve the same results

查看:108
本文介绍了如何将这些代码分解为.h,.cpp和main.cpp文件,并获得相同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <stdio.h>
#include <ctime>
#define NUMBER 10000

using namespace std;

double diffclock(clock_t clock1,clock_t clock2)
{
 double diffticks=clock1-clock2;
 double diffms=(diffticks*10)/CLOCKS_PER_SEC;
 return diffms;
}


void getTranspose(int C[4][4], int T[4][4])
{
    for (int i=0;i<4;i++)
        for (int j=0;j<4;j++)
        T[i][j]=C[j][i];
}

void MatrixMultiply_CX(int C[4][4], int X[4][4],int R[4][4])
{
    cout << endl;
    for (int i=0;i<4;i++)
        for (int j=0;j<4;j++) R[i][j]=0;
    for (int i=0;i<4;i++)
        for (int j=0;j<4;j++)
        for (int k=0;k<4;k++)
        R[i][j] +=C[i][k]*X[k][j];// Product formula

}
void MatrixMultiply_RT(int R[4][4], int T[4][4],int D[4][4])
{
    cout << endl;
    for (int i=0;i<4;i++)
        for (int j=0;j<4;j++) D[i][j]=0;
    for (int i=0;i<4;i++)
        for (int j=0;j<4;j++)
        for (int k=0;k<4;k++)
        D[i][j] +=R[i][k]*T[k][j];

}

int main()
{
    int C[4][4] ={1,1,1,1,2,1,-1,-2,1,-1,-1,1,1,-2,2,-1};
    int X[4][4] ={4,8,6,9,7,6,3,11,1,9,8,3,15,5,15,6};
    int R[4][4];
    int T[4][4];
    int D[4][4];

clock_t begin=clock();
    getTranspose(C, T);
    for (int i=0;i<4;i++) {
        for (int j=0;j<4;j++)cout << T[i][j] << " ";
            cout << endl;
    }

    MatrixMultiply_CX(C, X, R);

    for(int i = 0; i<4; i++){
        for(int j = 0; j<4; j++)cout << R[i][j] << " ";
            cout << endl;
    }

    MatrixMultiply_RT(R, T, D);

        for(int i = 0; i<4; i++){
            for(int j = 0; j<4; j++) cout << D[i][j] << " ";
            cout << endl;
    }

 clock_t end=clock();
 cout<<"Execution time: "<<diffclock(end,begin)<<" ms."<<endl;

    system ("PAUSE");
    return EXIT_SUCCESS;
}

推荐答案

一个拆分示例:)

"Is-State":
A splitting example :)

The "Is-State" :
// main.cpp
#include "any.h"
 

int takeFive()
{
  return 5;
}

int main()
{
  return takeFive();
}



可能/应该的状态":



The "Could/Should-State" :

// Five.h
#pragma once
// declaration:
int takeFive();

// Five.cpp
#include "Five.h"
// implementation: 
int takeFive()
{
  return 5;
}

// Main.cpp
#include "any.h"
#include "Five.h"
 

int main()
{
  return takeFive();
}


现在您的项目必须包含
这两个文件:Five.cpp Main.cpp-
正确链接:)


Now your project must contain
the both files: Five.cpp and Main.cpp -
to be compiled and linked correctly :)


检查高分辨率性能计数器是否具有功能
Check if the high-resolution performance counter functions
QueryPerformanceFrequency()

QueryPerformanceCounter()

帮助.

http://msdn.microsoft.com/en-us/library/ms644904(VS .85).aspx [ ^ ]

helps.

http://msdn.microsoft.com/en-us/library/ms644904(VS.85).aspx[^]


这篇关于如何将这些代码分解为.h,.cpp和main.cpp文件,并获得相同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆