Having problems with OOP C++
Jan 4, 2014 at 1:13pm UTC
Hello guys! Happy New year! I am having some issues with the following code, I am just not able to see where I am wrong. Can you please help me? Thanks in advance!
This is the header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
//CAS.h
#ifndef _CAS_H
#define _CAS_H
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
const double P0 = 1013.25;
const double a0 = 661.48;
const int barlength = 80;
int LINES = -1;
double maxvalue;
class CASHistory
{
public :
double calcSpeed(double l);
int CountLines(char name);
void CasCalc();
void CasDisp();
void CasHis();
CASHistory();
virtual ~CASHistory();
};
struct FlightParams
{
int time;
double pressure; // value read from data file
double speed; // calculated from pressure
} fltparams;
#endif
This is the .cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
#include "CAS.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
using std:: cout;
using std:: getline;
CASHistory::CASHistory(void )
{
}
CASHistory::~CASHistory(void )
{
}
void CASHistory::CasHis()
{ ifstream fin;
bool reRun;
string buf;
do {
system("cls" );
string filename;
cout << "Please 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" ;}
void CASHistory::CasCalc()
{
ifstream infile;
char filename;
infile.open(filename,ios::in);
LINES=CountLines(filename);
for (int i=0;i<LINES;i++)
{
infile>>fltparams.time;
infile>>fltparams.pressure;
}
}
double CASHistory:: calcSpeed(double l);
{
double sp;
sp=a0*sqrt(5*(pow((l/1000)/P0+1,2.0/7)-1));
cout<<"speed=" <<sp<<endl;
return 0;
}
int CASHistory::CountLines(char name)
{
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();
}
fin.close();
void CASHistory::CasDisp()
{
double j=0;
double max;
max=fltparams.speed;
for (int o = 0;o<LINES;o++)
{
if (max < fltparams.speed)
{
max = fltparams.speed;
}
}
maxvalue=max;
for (int z=0;z<LINES;z++)
{
double sf;
sf=fltparams.speed/(maxvalue/barlength);
cout << right;
cout.fill('*' );
cout<<setw(sf);
cout<<fltparams.time<<"," <<fltparams.speed<<endl;
}
}
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;
}
And the main.cpp itself
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <cstdlib>
#include "CAS.h"
#include <string>
using namespace std;
int main(void ) {
CASHistory cashistory;
cashistory.CasHis();
system("pause" );
return 0;
}
Topic archived. No new replies allowed.