写日志:

class LogFile
{
public:
static LogFile &instance();
operator FILE *() const { return m_file; }
private
LogFile(const char *filename)
{
m_file = fopen(filename, "a+");
}
~LogFile()
{
fclose(m_file);
}
FILE *m_file;
}; LogFile &LogFile::instance()
{
static LogFile log("AppLog.txt");
return log;
} 用的时候可以这么写:
fwrite("abc", 1, 3, LogFile::instance());

读取文件信息:

c语言实现如下功能 输入全部文件名(绝对路径加文件名)得到,文件名,扩展名,文件长度

/* MAKEPATH.C */
#include<string.h>
#include <stdlib.h>
#include <stdio.h> #define LENGTH 200 struct FILEHEAD
{
char path_buffer[LENGTH];
char filename[LENGTH];
char ext[LENGTH];
unsigned int length; }; FILEHEAD file; void getFileInformation(FILEHEAD file)
{
memset(&file,0,sizeof(file)); //_makepath( path_buffer, "c", "\\sample\\crt\\", "makepath", "c" );
printf( "Path created with : \n\n");
scanf("%s",file.path_buffer);
_splitpath( file.path_buffer, NULL, NULL, file.filename, file.ext ); FILE *fp= NULL;
fp=fopen(file.path_buffer,"r");
if (NULL==fp)
{
printf("cannot open the %s \n",file.path_buffer);
exit(0);
} fseek(fp,0l,SEEK_END);
file.length=ftell(fp); fclose(fp);
fp = NULL; //需要指向空,否则会指向原打开文件地址 printf( "Path extracted with _splitpath:\n" );
//printf( " Drive: %s\n", drive );
//printf( " Dir: %s\n", dir );
printf( " Filename: %s\n", file.filename );
printf( " Ext: %s\n", file.ext );
printf( " length is btye: %ld btye\n", file.length );
} int main( void )
{ getFileInformation(file); system("pause"); return 0;
}

算法排序框架:

#include <stdio.h>
#include <stdlib.h>
#include <time.h> #define TRUE 1
#define FALSE 0
#define MAX 10000 typedef int KeyType;
typedef int OtherType; typedef struct
{
KeyType key;
OtherType other_data;
}RecordType; // All kinds of seek.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include "headfile.h"
#include "windows.h"
#include "conio.h " #include"WinBase.h"
#include "Psapi.h" #pragma once
#pragma message("Psapi.h --> Linking with Psapi.lib")
#pragma comment(lib,"Psapi.lib") int Data[MAX]={0}; void produceData(int a[],int length) //给数组生成数据,用于随即查找
{
time_t t;
srand(time(&t));
for (int i=0;i<length;i++)
{
a[i]=rand()%length;
} } void printData(int a[],int length) //打印数字,到控制台,每五个换一行
{
for (int i=0;i<length;i++)
{
printf("%8d",a[i]);
if (0==i%5)
{
printf("\n");
}
} } double showMemoryInfo()
{ double MemorySize; //单位MB
HANDLE handle=GetCurrentProcess(); PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo(handle,&pmc,sizeof(pmc));
MemorySize=pmc.WorkingSetSize/1024; printf("内存使用: %8lf \n",MemorySize); //WorkingSetSize The current working set size, in bytes. return MemorySize; } void writeRecordtime(unsigned rTime)//将程序结果运行时间写入文件
{
FILE *fpRecord=NULL; char *s="your programm running time is: ";
char *c="ms "; if((fpRecord=fopen("record.txt","wt+"))==NULL) { printf("Cannot open file strike any key exit!"); getchar(); exit(1); } fprintf( fpRecord, "%s", s);
fprintf( fpRecord, "%d", rTime);
fprintf( fpRecord, "%s", c); fprintf( fpRecord, "\n");
fprintf( fpRecord, "your programm use %fMB size of memory!!!", showMemoryInfo()); fclose(fpRecord); } int _tmain(int argc, _TCHAR* argv[])
{
produceData(Data,MAX);
printData(Data,MAX); getchar(); return 0;
}

快速求积分办法:

// Integral-romberg方法求积分.cpp : 定义控制台应用程序的入口点。
//
/*
romberg方法求积分
方法也称为逐次分半加速法。它是在梯形公式,simpson公式和newton-cotes公式之间的关系的基础上,
构造出一种加速计算积分的方法。作为一种外推算法,它在不增加计算量的前提下提高了误差的精度。
在等距基点的情况下,用计算机计算积分值通常都采用吧区间逐次分半的方法进行。
这样,前一次分割得到的函数值在分半以后仍然可以被利用,并且易于编程。 运行结果如下:
输入:
0
3.14159
输出:Romberg- -12.0703
增加迭代次数或提高精度时,程序运行
得到的结果几乎没有什么变化。可以看到,
和Simpson方法运行的结果基本一致,但
Romberg法速度更快、精度更高 */ #include "stdafx.h" #include<iostream>
#include<math.h>
#define epsilon 0.00001
#define COUNT 100
using namespace std; double fun(double x)
{
return x*x;
} double Romberg(double a,double b)
{
int m ,n;
double h,x,s,q,ep;
double p,*R =new double[COUNT]; h=b-a;
R[0]= h*(fun(a)+ fun(b))/2.0;
m=1;
n=1;
ep=epsilon+1.0;
while ((ep >= epsilon)&& (m <COUNT))
{
p = 0.0;
{
for(int i=0;i<n;i++)
{
x = a+ (i+0.5)*h ;
p= p + fun(x);
}
p= (R[0]+ h*p)/2.0;
s = 1.0;
for(int k=1;k<=m;k++)
{
s = 4.0*s;
q= (s*p-R[k-1])/(s-1.0);
R[k-1]= p;
p =q;
}
p=fabs(q -R[m-1]);
m =m + 1;
R[m-1]= q;
n = n + n;
h = h/2.0;
}
return (q);
}
} int _tmain(int argc, _TCHAR* argv[])
{
double a,b;
cout<<"Input a,b:a为下限,b为上限"<<endl;
cin>>a>>b;
cout<<"Romberg="<<Romberg(a,b)<<endl;
system("pause");
return 0;
}

最新文章

  1. 城管停车执法打印APP 移动云POS 现场打印告知单-执法平台+智能POS客户端系统
  2. LoadRunner使用之变量参数化
  3. Vim自动补全神器–YouCompleteMe
  4. Replication的犄角旮旯(九)-- sp_setsubscriptionxactseqno,赋予订阅活力的工具
  5. BZOJ2463: [中山市选2009]谁能赢呢?
  6. [原]Unity3D深入浅出 - 常用类的成员变量和成员函数(Tranform、Time、Random、Mathf、Input)
  7. Windows 8 键盘上推自定义处理
  8. html5权威指南:表格元素
  9. AdaBoost 算法原理及推导
  10. Dictionary使用(转)
  11. vue.js + ajax 数据加载(纯新手get)
  12. Add AI feature to Xamarin.Forms app
  13. Map 转换成byte[] 数组
  14. Event Loop
  15. Java Http协议处理类
  16. Java NIO-3
  17. DedeCMS实现自定义表单提交后发送指定QQ邮箱的方法
  18. K2P刷机教程转自恩山磨人的小妖精
  19. 03_ActiveMQ安全机制
  20. focal loss和ohem

热门文章

  1. Oracle with as 嵌套
  2. java线程共享受限资源 解决资源竞争 thinking in java4 21.3
  3. bzoj1193: [HNOI2006]马步距离(贪心+bfs)
  4. [BZOJ3670] [NOI2014] 动物园 解题报告 (KMP)
  5. PostgreSQL服务器存储参数的内部查看方法和实际表述之间的关系
  6. oracle(sql)基础篇系列(四)——数字字典、索引、序列、三范式
  7. codeforces 495D Sonya and Matrix
  8. 对OC中property的一点理解
  9. Python3基础笔记---re模块
  10. 01背包-第k优解