⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read.cpp

📁 This is my assignment for my tutor s Class. and many problems exist,so you should comprhend it and i
💻 CPP
字号:
// Read.cpp: implementation of the CRead class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FilmDesign.h"
#include "Read.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRead::CRead()
{

}

CRead::~CRead()
{

}

bool CRead::Read()
{
  CFilmDesignApp * app=(CFilmDesignApp*)AfxGetApp();
  CString strName="";
  char szFilter[]="Text Files (*.txt)|*.txt||";
  CFileDialog fileDialog(true, "txt","First",OFN_OVERWRITEPROMPT,szFilter);//OFN_READONLY|
  int response=fileDialog.DoModal();
  if(response==IDOK)
	  strName=fileDialog.GetPathName();//Get fileName to open
  else if(response==IDCANCEL)
       AfxMessageBox("取消打开操作!",MB_OK);

  
  CStdioFile file(strName,CFile::modeRead);//Open  the file to read
  
  CString str;
  
  
  
  
  int count=0;
  for(int i=0;i<MAX;i++)
  {   
	    

	  file.ReadString(str); 
	  
      TRACE0(str);
	  if(str.GetLength()>300||file.GetLength()>5000)  //Evaluating file is too long or not
	  {
		  AfxMessageBox("文件格式不对,或文件太大",MB_OK);
		  break;
	  }
      
	  if(this->ReadWord(str)==1)     // emit usefulnessless line data
	
	  {
	    app->m_Data[count].SetName(this->GetName());
	    app->m_Data[count].SetN(this->GetN());
	    app->m_Data[count].SetK(this->GetK());
	    app->m_Data[count].SetM(this->GetThickness());
	    app->m_Data[count].SetUse(true);
	    count+=1;
	  } 	  
	   
 
  }   

      return true;

}

int CRead::ReadWord(CString &str)
{
    

	CString m_str[4];
	for(int p=0;p<4;p++)
		m_str[p]="";

    if(str.GetLength()==0)		return 0;  //str is null?
	int m=0,n=0;
	
	int k=str.GetLength()-1;//note endal space blank of string using '*'
	if((str.GetAt(k)>='0'&&str.GetAt(k)<='9')) ;
	else if(str.GetAt(k)==' '||str.GetAt(k)=='\n'||str.GetAt(k)=='\r'||str.GetAt(k)=='\t')
			str.SetAt(k,'*');
	
	for(int i=0;i<str.GetLength();i++)     //analyze char of string
	{   
		if(str.GetAt(i)=='*') break;
	//	if(str.GetAt(i)=='\r'||str.GetAt(i)=='\n') break;
		if(str.GetAt(i)==' '||str.GetAt(i)=='\t'||str.GetAt(i)=='\r'||str.GetAt(i)=='\n')  //decide wheather one word is end or not
			                                       //and clear ' ' to null
		{   
			while(str.GetAt(i)==' '||str.GetAt(i)=='\t'||str.GetAt(i)=='\n'||str.GetAt(i)=='\r')
				 i++;
			if(m_str[m].GetLength()!=0)
			{     if(m>=3) break;
		        	else 
					{
				           m++;
				           n=0; 
					}
				  
			}
			
		}
        if(m>3)  break;       
		
        if(str.GetAt(i)!=' '&&str.GetAt(i)!='\t'&&str.GetAt(i)!='\r'&&str.GetAt(i)!='\n')
		     m_str[m].Insert(n++,str.GetAt(i));//input data
                
		
	    
        
		 
	

	}
   
	if(atofd(m_str[1])==0)
		return 0;

	this->SetName(m_str[0]);
	this->SetN(this->atofd(m_str[1]));
    this->SetK(this->atofd(m_str[2]));
	this->SetThickness(this->atofd(m_str[3]));

	return 1;
	
    
}
double CRead::atofd(CString str)
{

	char mstr[100];
	for(int i=0;i<str.GetLength();i++)
	{
		mstr[i]=str.GetAt(i);
	}

	mstr[i]='\0';

	double data=atof(mstr);
	return data;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -