| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 693 人关注过本帖
标题:c++ class调用和数组问题
只看楼主 加入收藏
yilisb24
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-3-25
结帖率:0
收藏
已结贴  问题点数:0 回复次数:2 
c++ class调用和数组问题
问题是这样的,4个cpp,main.cpp开始调用,然后计算显示等,但是失败。
这是main.cpp
#include <cstdlib>
#include "CAS.h"
using namespace std;
FlightParams fltparams[200];

int main(void) {
    CASHistory cashistory;
    cashistory.doIt();

    system("pause");
    return 0;
    }  
这是CASHistory.cpp

#include "CAS.h"

CASHistory::CASHistory(void)
{

}

CASHistory::~CASHistory(void)
{
   }  
void CASHistory::doIt()
{
    bool reRun;
    string buf;
    do {
        system("cls");
              string filename;  
        cout << "Plz enter the file name:" << endl;
        getline(cin,filename);
        fin.clear();
        fin.open(filename.c_str());
        if (!fin.fail()){
            cout << "\nCAS History Plot(seconds,knots)\n\n";}
        else {
            cout << "\nPlz check your input file name!\n\n";}
        CASCalculator casCalculator;
        casCalculator.doThis();
        fin.close();
        CASDisplay casDisplay;
        casDisplay.doThat();
        reRun = false;
        cout << "Re-run (Y/N):" << endl;
        char tmp;
        while (cin >> tmp && tmp != 'Y' && tmp != 'y' && tmp != 'N' && tmp != 'n');
        if (tmp == 'Y' || tmp == 'y') reRun = true;
        getline(cin, buf);
    } while (reRun);
    cout << "End of program execution!" << endl;
}
这是CASDisplay.cpp
#include "CAS.h"
CASDisplay::CASDisplay()
{
   
}
CASDisplay::~CASDisplay()
{
}

void CASDisplay::doThat()
{
   
    double j=0;
    double   max;
    max=fltparams[0].speed;
    for (int o = 0;o<LINES;o++)

    {
        if(max < fltparams[o].speed)
        {
            max   =   fltparams[o].speed;        
        }
    }
      maxvalue=max;

     for (int z=0;z<LINES;z++)
        {
            double sf;
            sf=fltparams[z].speed/(maxvalue/barlength);
            cout << right;
            cout.fill('*');
            cout<<setw(sf);
            cout<<fltparams[z].time<<","<<fltparams[z].speed<<endl;
        }
}
这是CASCalculator.cpp
#include "CAS.h"
#include <iostream>
using std::cout;
using std::endl;
#include <fstream>
#include <cmath>
#include <iomanip>
#include <string>



CASCalculator::CASCalculator()
{
}

CASCalculator::~CASCalculator()
{
}

void CASCalculator::doThis()
{
     
      ifstream infile;   
      char filename;
      infile.open(filename/*,ios::in*/);      
      LINES=CountLines(filename);
    for(int i=0;i<LINES;i++)
        {
            infile>>fltparams[i].time;
            infile>>fltparams[i].pressure;
        }
}

double CASCalculator::calcSpeed(double l)
{
        double sp;
        sp=a0*sqrt(5*(pow((l/1000)/P0+1,2.0/7)-1));
        return sp;
}
int CASCalculator::CountLines(char na)
{
    ifstream ReadFile;
int n=0;
string temp;
ReadFile.open(name,ios::in);   
if(ReadFile.fail())              {
   return 0;
}
else{

   while(getline(ReadFile,temp))
   {
    n++;
   }
   return n;
}
ReadFile.close();
}
最后是头文件CAS.h
#ifndef _CAS_H
#define _CAS_H

#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
using std::string;


    const double P0 = 1013.25;
    const double a0 =  661.48;
    const int barlength = 80;
    int LINES = -1;
    double maxvalue;



    class CASCalculator
{
public:
    double calcSpeed(double l);
    int CountLines(char na);
    void doThis();
    CASCalculator();
    virtual ~CASCalculator();
};
    class CASDisplay
{
public:
    void doThat();
    CASDisplay();
    virtual ~CASDisplay();
};

    class CASHistory
{
public:
    void doIt();
    CASHistory(void);
    virtual ~CASHistory(void);
private:
};

    struct FlightParams   
{
int time;           
double pressure;     // value read from data file
double speed;        // calculated from pressure
};
#endif


编译之后各种错误,唉,小弟才疏学浅,感觉有些地方有点乱来
希望高手帮忙解决,十分紧急


搜索更多相关主题的帖子: return system 
2011-03-25 23:44
loveminttea
Rank: 3Rank: 3
来 自:河南科技学院
等 级:论坛游侠
帖 子:95
专家分:146
注 册:2010-10-14
收藏
得分:10 
不懂~
2011-03-26 00:25
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:10 
程序是什么功能?
2011-03-26 12:30
快速回复:c++ class调用和数组问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031443 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved