• 大小: 17KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-23
  • 语言: C/C++
  • 标签: vc  6.0  C/C++程序  

资源简介

帮别人写的一个C/C++程序,输入两个字符串表达式,输入要合法,解析字符串,计算,例如 x + y, x -y,计算,,前一久写的程序,测了一下可以用,没有深入测试了,放在机子上也是放着,今天上传一下,弄点积分,谢谢大家!!!!!

资源截图

代码片段和文件信息

// MyPrograms.cpp : Defines the entry point for the console application.
//

#include “stdafx.h“
#include “stdio.h“
#include 
#include 
#include 
#include 
#include 

typedef struct _TVariable  
{
char Variable;   //字母变量
int VariableDegree;//字母变量的次数
int nMutiplied;                     //这个系数是否已经乘过   0: no  1: yes
struct _TVariable *pNextVariable;
}TVariable *PVariable;

typedef struct _TItem
{
int nCoefficient;    //多项式的系数
PVariable pVariable;       //  指向字母链表
struct _TItem *pNextItem; //
}TItem *PItem;
/*
typedef enum CURRENT_POSITION
{
BEFORE_LETTER  = 0   //字母前面是系数
    AFTER_LETTER   = 1   //字母后面为次数
};
CURRENT_POSITION g_CurrPosition = BEFORE_LETTER;
*/
PItem g_FirstDataHead = NULL;
PItem g_SecondDataHead = NULL;
PItem g_MutiResultHead = NULL;
char* g_InputData = NULL;

//单个联表内存的释放
void FreeSpace(PItem g_pItems)
{
while (g_pItems) //释放多项式链表
{
PItem pItemTemp = g_pItems->pNextItem;
PVariable pVar = g_pItems->pVariable;
while(pVar)//释放字母变量的联表
{
PVariable pVarTemp = pVar->pNextVariable;
free(pVar);
pVar = pVarTemp;
}
free(g_pItems);
g_pItems = pItemTemp;
}
}

//释放内存
void FreeMallocSpace()
{
FreeSpace(g_FirstDataHead);
FreeSpace(g_SecondDataHead);
FreeSpace(g_MutiResultHead);
}

int Find_0_9()//读出紧挨着的连续的数字
{
char StoreValue[100] = {0};
int i = 0;
while(*g_InputData <= ‘9‘ && *g_InputData >= ‘0‘)
{
StoreValue[i] = *g_InputData;
i++;
g_InputData++;
}
return atoi(StoreValue);
}


//刚进来,  *g_InputData一定是字母
void DisposeLetter(PItem pData)//解析字母以及   字母之间的数字(字母的系数系数不能为负数)
{
/* PVariable pLast = pData->pVariable;
PVariable pVarble = NULL;
while(!(*g_InputData == ‘+‘ || *g_InputData == ‘-‘ || *g_InputData == ‘\0‘))
{
if(*g_InputData <= ‘9‘ && *g_InputData >= ‘0‘)
{
pVarble->VariableDegree *= Find_0_9();
}
else if((*g_InputData <= ‘Z‘ && *g_InputData >= ‘A‘) || (*g_InputData <= ‘z‘ && *g_InputData >= ‘a‘))
{
pVarble = (PVariable)malloc(sizeof(struct _TVariable));
memset(pVarble 0 sizeof(struct _TVariable));

pVarble->Variable = *g_InputData;
pVarble->VariableDegree = 1;
pLast->pNextVariable = pVarble;

pLast = pVarble;
g_InputData++;
}
}
*/
//建立字母链表
if((*g_InputData <= ‘Z‘ && *g_InputData >= ‘A‘) || (*g_InputData <= ‘z‘ && *g_InputData >= ‘a‘))
{
PVariable pLast = NULL;
PVariable pVarble = (PVariable)malloc(sizeof(struct _TVariable));
memset(pVarble 0 sizeof(struct _TVariable));
pData->pVariable = pVarble ;   //字母
pLast = pVarble;


pVarble->Variable = *g_InputData;
pVarble->VariableDegree = 1;   //字母次数为1
g_InputData++;
while(!(*g_InputData == ‘+‘ || *g_InputData == ‘-‘ || *g_InputData == ‘\0‘))
{
if(*g_InputData <= ‘9‘ && *g_InputData >= ‘0‘)
{
pVarble->VariableDegree *= Find_0_9(); //字母之后的数字一定是,字母的次数,
}
else if((*g_InputData <= ‘Z‘ && *g_InputData >= 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      14267  2009-06-20 15:03  MyPrograms\MyPrograms.cpp

     文件       4582  2009-06-20 00:00  MyPrograms\MyPrograms.dsp

     文件        543  2009-06-17 19:03  MyPrograms\MyPrograms.dsw

     文件      66560  2009-06-20 15:03  MyPrograms\MyPrograms.ncb

     文件      54784  2009-06-20 15:03  MyPrograms\MyPrograms.opt

     文件       1092  2009-06-20 15:03  MyPrograms\MyPrograms.plg

     文件       1232  2009-06-17 19:03  MyPrograms\ReadMe.txt

     文件        297  2009-06-17 19:03  MyPrograms\StdAfx.cpp

     文件        667  2009-06-17 19:03  MyPrograms\StdAfx.h

     目录          0  2009-06-27 22:56  MyPrograms

----------- ---------  ---------- -----  ----

               144024                    10


评论

共有 条评论

相关资源