关于一个程序运行时间测试的程序
//一个头文件utility
#include<string>
#include<iostream>
#include<limits>
#include<cmath>
#include<fstream>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<iomanip>
#include<cstdarg>
#include<cassert>
using namespace std;
//定时器类timer
class timer
{
private:
clock_t starttime;
public:
timer();
~timer(void){};
double elapsedtime();
void reset();
};
timer::timer()
{
starttime=clock();
}
double timer::elapsedtime()
{
clock_t endtime=clock();
return(double)(endtime-starttime)/(double)CLK_TCK;
}
void timer::reset()
{
starttime=clock();
}
//通用异常类
#define MAX_ERROR_MESSAGE_LEN 100
class error
{
private:
char message[MAX_ERROR_MESSAGE_LEN];
public:
error(char mes[]="一般性异常");
~error(void){};
void show()const;
};
error::error(char*mes)
{
strcpy(message,mes);
}
void error::show() const
{
cout<<message<<endl;
}
//随机函数
void setrandseed()
{
srand((unsigned)time(NULL));
}
int getrand(int n)
{
return rand()%(n);
}
int getrand()
{
return rand();
}
//交互函数
bool usersaysyes()
{
char ch;
bool initialresponse=true;
do
{
if(initialresponse)
{
cout<<"(y,n)?";
}
else
{
cout<<"用y 或n回答:";
}
ch=getchar();
initialresponse=false;
} while(ch!='y'&&ch!='Y'&&ch!='n'&&ch!='N');
while (getchar()!='\n');
if(ch=='y'||ch=='Y')return true;
else return false;
}
//主函数
#include"utility.h"
#define NUM 280
int main(void)
{
try
{
if(NUM>280) throw error("num值太大了!");
int a[NUM+1][NUM+1],b[NUM+1][NUM+1],c[NUM+1][NUM+1];
bool iscontinue=true;
timer objtimer;
while(iscontinue)
{
int i,j,k;
setrandseed();
objtimer.reset();
for(i=1;1<=NUM;i++)
for(j=1;j<=NUM;j++)
{
a[i][j]=getrand();
b[i][j]=getrand();
}
for(i=1;1<=NUM;i++)
for(j=1;j<=NUM;j++)
{
c[i][j]=0;
for(k=1;k<=NUM;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
cout<<"用时:"<<objtimer.elapsedtime()<<"秒"<<endl;
cout<<"是否继续";
iscontinue=usersaysyes();
}
}
catch (error err)
{
err.show ();
}
system("pause");
return 0;
}
运行后 什么也显示不出来 请各位 高手指教 解决后马上结贴