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