Avatar billede jennemaan Nybegynder
08. maj 2001 - 10:27 Der er 4 kommentarer og
2 løsninger

fatal error C1010: unexpected end of file while looking for precompiled header directive

Hej folkens,

jeg er begyndt på et atl projekt med ms vc++ 6.

Til selve projektet har jeg tilføjet nogle klasser som tidligere er blevet brugt i en console applikation.

Nu får jeg følgende fejl:

fatal error C1010: unexpected end of file while looking for precompiled header directive ensourcefil.cpp

Da der er tale om 7 klasser jeg har tilføjet kan arbejdet med at ændre koden så det virker under win32 vel ikke så stort?

Hvad skal jeg kigge efter?

Her er et eksempel på een af klasserne der giver prob.:


/*  Data structures
File:      dayvaluelist.h
*/

#ifndef __DAYVALUELIST_H__
#define __DAYVALUELIST_H__

//! Class for holding a date and a stock quote
/*!
  The class CDayValue basicly contains a day (stored as a double) and the a
  value. The value is the value of a share on the given day. By storing the day
  as a double we would comply to the existing Microsoft standards
*/

class CDayValue {
  double dDay;  //!< The day
  double dValue;    //!< The value of the day   

public:
  //! The most basic constructor
  CDayValue(void);

  //! A constructor for setting up a CDayValue with day and value
  CDayValue(double, double);

  //! A destructor
  ~CDayValue(void);

  //! Set the values of a CDayValue
  void Set(double, double);

  //! Set the values of a CDayValue
  void Set(CDayValue *);

  //! Returns the day
  int  Day(void);

  //! Returns the value
  double Value(void);

  //! Prints the CDayValue in a nice way
  void PrettyPrint(void);
};

//! Class containing a list of dates and stockquotes
/*!
  The class CDayValueList is an array of CDayValue\'s. It represents a series
  of stock quotations.
*/
class CDayValueList {
  int iLen;          //!< Number of stock quotations.
  CDayValue *aList;  //!< Array of stock quotations and the associated days.

  double splint(double [], double [], double [], int, double);

  double splint_light(double, double, double, double, double, double, double);

public:
  //! A basic constructor generating an empty CDayValueList.
  CDayValueList(void);

  //! A reading constructor.
  CDayValueList(char *);

  //! A constructor building a CDayValueList using the length, array of days
  //! and an array of stock prices.
  CDayValueList(int, double [], double []);

  //! This constructor allocates a CDayValueList of a length equal to the
  //! first argument having the second argument as the first day.
  CDayValueList(int, int);

  //! A copy constructor. Makes an exact copy of the CDayValuelist given
  //! as argument.
  CDayValueList(CDayValueList *);

  //! A destuctor.
  ~CDayValueList(void);

  //! Returns the length of the list.
  int Length(void);

  //! Returns the last date in the list.
  int EndDay(void);

  //! Returns the first date in the list.
  int StartDay(void);

  //! Returns the day at the argument.
  int GetDayAbs(int); // abs pos

  //! Returns the CDayValue given at the argument as a day.
  CDayValue *GetPair(int); // day

  //! Returns the CDayValue given at the argument as an array position.
  CDayValue *GetPairAbs(int); // Abs. pos

  //! Returns the value at the given day. This function assumes that data are
  //! expanded, that is, day in the array appear consecutive.
  double GetValue(int);

  //! Returns an array of the values in the CDayValueList. The values are
  //! stored in the same order they appear in in the CDayValueList.
  double *GetValues();

  //! Returns an array of the days in the CDayValueList. The days are
  //! stored in the same order they appear in in the CDayValueList.
  double *GetDays();

  //! Return the value at the given position.
  double GetValueAbs(int);

  //! Sets the day and value at a given day.
  void SetPair(CDayValue *);

  //! Sets the day and value at an absolute position in the list.
  void SetPairAbs(int, int, double);

  //! Performs linear interpolation.
  void LinInterpolBtwDates(int ,int);

  //! Performs cubic spline interpolation.
  void CubicInterpolBtwDates(int, int, double, double);

  //! Prints the CDayValueList in a nice way.
  void PrettyPrint(void);

  //! Print the CDdayValueList in a way suitable for Gnuplot.
  void GnuplotPrint(void);

  //! Runs some legality checks.
  void Check(void);
};
#endif // __DAYVALUELIST_H__



/*  Data structures
File:      dayvaluelist.cpp
*/

//#include <iomanip>
//#include <iostream>
//#include <fstream>
//#include <stdio.h>

#include \"Macro.h\"
#include \"dayvaluelist.h\"

//using namespace std;

/*!
  For this basic constructor no values have to be supplied. As no values
  a given by the user the day and the vallue is set to -1.
*/
CDayValue::CDayValue(void){
  dDay = -1;
  dValue = -1;
};

/*!
  This constructer is used for loading the class with a day and a value
  from the beginning. The first argument is the day and the second is the
  value. No checks regarding feasibility of the day is made.
*/
CDayValue::CDayValue(double dday, double dval){
  dDay = dday;
  dValue = dval;
};

CDayValue::~CDayValue(void){};

/*!
  This function is first of all available in order to assist the developer
  in the debugging process. It prints the information of a CDayValue to
  the screen in a nice readable way
*/
void CDayValue::PrettyPrint(void){
//    cout << \" (\" << dDay << \",\" << dValue << \") \";
};

/*!
  This function is used to set both values of a CDayValue. The first argument
  is the day and the second argument is the value. No checks regarding the
  feasibility of the day is performed.
*/
void CDayValue::Set(double d, double v){
  dDay = d;
  dValue = v;
};

/*!
  Just like Set(double, double) this function set both values of a CDayValue.
  Here the CDayValue is initiated by copying the values from another
  CDayValue given by a pointer. No legality checks are made.
*/
void CDayValue::Set(CDayValue *dv){
  dDay = dv->dDay;
  dValue = dv->dValue;
};

/*!
  This function returns the day. Before returning the day it is casted from
  a double to a int.
*/
int CDayValue::Day(void){
  return ((int) dDay);
};

/*!
  This function simple returns the value.
*/
double CDayValue::Value(void){
  return dValue;
};



//
// Class: CDayValueList
//



CDayValueList::CDayValueList(void){
};

CDayValueList::CDayValueList(int iL, double adDays[], double adVals[]){
  iLen = iL;
  aList = new CDayValue [iLen];
 
  for(int ci = 0; ci < iLen; ci++){
    aList[ci].Set(adDays[ci], adVals[ci]);
  };
  LOTSexe( Check() );
};

/*!
  This constructor sets up a list of the size given by the first argument. The
  second argument denotes the number of the first day in the list. Days are
  then set consequtively for the whole list. All stockprices are initialized
  as -1 to indicate the absence of information.
*/
CDayValueList::CDayValueList(int cL, int cStDay){
  // length, startday

  iLen = cL;
  aList = new CDayValue [iLen];
 
  for(int cI = 0; cI < iLen; cI++){
    aList[cI].Set(cI+cStDay, -1);
  };
};


CDayValueList::CDayValueList(CDayValueList *cvd) {
 
  CDayValue *DayVal;

  iLen = cvd->Length();
  aList = new CDayValue [iLen];
 
  for (int cI = 0; cI < iLen; cI++) {
    DayVal = cvd->GetPairAbs(cI);
    aList[cI].Set(DayVal->Day(), DayVal->Value());
  };
};
 
CDayValueList::CDayValueList(char *file_name){
  int days[50000];
  double values[50000];
  int top = 0;

  ifstream infile( file_name);
  int day = 1;
  double value = 1;

  if( ! infile ){
    cout << \"Opening file >\" << file_name << \"< failed, bailing out.\" << endl;
    exit(0);
  };
   
  while ( infile >> day ){
    infile >> value;

    days[top] = day;
    values[top] = value;
    top++;
  };

  iLen = top;
  aList = new CDayValue [iLen];
 
  for(int ci = 0; ci < iLen; ci++){
    aList[ci].Set(days[ci], values[ci]);
  };

  LOTSexe( Check() );
};


CDayValueList::~CDayValueList(void){
  delete aList;
};

/*!
  This function is first of all available in order to assist the developer
  in the debugging process. It prints the information of a CDayValueList to
  the screen in a nice readable way.
*/
void  CDayValueList::PrettyPrint(void){
  /*cout << \"CDayValueList, Length: \" << iLen << endl;
  for(int cI = 0; cI < iLen; cI++){
    aList[cI].PrettyPrint();
    cout << endl;
  };
  cout << endl;*/
};

/*!
  The days and values are printed in a format suited for the open-source
  plotting program Gnuplot. Basicly all values are printed in two colums:
  first containing the days and the second containing the values.
*/
void  CDayValueList::GnuplotPrint(void){
  /*for(int cI = 0; cI < iLen; cI++)
    cout << aList[cI].Day() << \"  \" << aList[cI].Value() << endl;
  cout << endl;*/
};

/*!
  This function returns the length of the list of stock quotation, that is,
  the number of stock quotations are returned as an integer.
*/
int CDayValueList::Length(void){
  return iLen;
};

int CDayValueList::EndDay(void){
  return aList[iLen-1].Day();
};

int CDayValueList::StartDay(void){
  return aList[0].Day();
};

int CDayValueList::GetDayAbs(int pos){
// abs pos
  LOTSassert( pos >= 0 && pos < iLen);
  return aList[pos].Day();
};


double CDayValueList::GetValue(int day){  // assuming an expanded list !!!
  LOTSassert( day >= StartDay() && day <= EndDay() );
  return aList[day - StartDay()].Value();
};

double CDayValueList::GetValueAbs(int pos){
  LOTSassert( pos >= 0 && pos < iLen);
  return aList[pos].Value();
}

CDayValue *CDayValueList::GetPair(int day){
  // day
  LOTSassert( day >= StartDay() && day <= EndDay() );
  return &aList[day - StartDay()];
};

CDayValue *CDayValueList::GetPairAbs(int pos){
  LOTSassert( pos >= 0 && pos < iLen);
  // Abs. pos
  return &aList[pos]; 
}

/*!
  This function assumes that there are no \"holes\" in the list of dates, that
  is, if day x is stored in position y, x+1 is stored in position y+1.
*/
void CDayValueList::SetPair(CDayValue *dv){
  aList[dv->Day()-aList[0].Day()].Set(dv);
};

void CDayValueList::SetPairAbs(int pos, int day, double value) {
  LOTSassert( pos >= 0 && pos < iLen);
  aList[pos].Set((double) day, value);
}

/*!
  This function performs linear interpolation between the two dates given
  as arguments. The first argument the starting point and the second
  argument is the ending point. It is assumed (and not checked) that the
  list of stock quotations is expanded, that is, that all dates between the
  first and the second argument is present, but may contain incorrect values.
  These values are set according to the definition of linear interpolation.
*/
void CDayValueList::LinInterpolBtwDates(int iDayFrom,int iDayTo){

  LOTSassert( iDayTo > iDayFrom );

  double dFactor = (GetValue(iDayTo) - GetValue(iDayFrom))/((double) iDayTo - iDayFrom);
  double dBasicVal = GetValue(iDayFrom);
 
  CDayValue InterpolDay;

  for(int cI = 1; cI < iDayTo - iDayFrom; cI++){
    InterpolDay.Set(iDayFrom + cI, dBasicVal + cI*dFactor);
    SetPair(&InterpolDay);
  };
};

/*!
  This function perform cubic interpolation between two dates given as the
  first two arguments. It is assumed (and not checked) that the list of
  stock quotations is expanded, that is, that all dates between the first
  and the second argument is present, but may contan incorrect values.
  The cubic spline interpolation values are computed according to \"Numerical
  Recipes in C - The Art of Scientific Computing\", second edition, section
  3.3 \"Cubic spline interpolation\".
*/
void CDayValueList::CubicInterpolBtwDates(int iDayFrom,int iDayTo,
                      double y2a_klo, double y2a_khi) {

  LOTSassert( iDayTo > iDayFrom );

  double dResult = 1;
  CDayValue *InterpolDay;

  InterpolDay = new CDayValue();

  for(int cI = 1; cI < iDayTo - iDayFrom; cI++){
    dResult = splint_light(((double) iDayFrom), ((double) iDayTo),
              GetValue(iDayFrom), GetValue(iDayTo),  // y-values
              y2a_klo, y2a_khi, ((double) iDayFrom+cI));
    InterpolDay->Set(iDayFrom + cI, dResult);
    SetPair(InterpolDay);
  };
};
 
/*!
  This function is a computes the cubic spline value for a given value.
  It is based on the cubic spline interpolation from \"Numerical Recipes in C -
  The Art of Scientific Computing\" page 116.
*/
double CDayValueList::splint_light(double xa_klo, double xa_khi,
                  double ya_klo, double ya_khi,
                  double y2a_klo, double y2a_khi,
                  double x) {
  // Numerical Recepies 3.3 p. 116

  double h, b, a, y;
 
  h = xa_khi - xa_klo;
  LOTSassert(h != 0.0);

  a = (xa_khi - x)/h;
  b = (x - xa_klo)/h;
 
  y = a*ya_klo+b*ya_khi+((a*a*a-a)*y2a_klo+(b*b*b-b)*y2a_khi)*(h*h)/6.0;

  return y;
};


/*!
  Replaced by splint_light. Only included for reference. DO NOT USE.
*/
double CDayValueList::splint(double xa[], double ya[], double y2a[], int n,
                double x) {
  // Numerical Recepies 3.3 p. 116

  int klo, khi, k;
  double h, b, a, y;
 
  klo = 1;
  khi = n;
 
  while (khi - klo > 1) {
    k = (khi + klo) >> 1;
    if (xa[k] > x)
      khi = k;
    else
      klo = k;
  }
 
  h = xa[khi] - xa[klo];
  LOTSassert(h != 0.0);

  a = (xa[khi] - x)/h;
  b = (x - xa[klo])/h;
 
  y = a*ya[klo]+b*ya[khi]+((a*a*a-a)*y2a[klo]+(b*b*b-b)*y2a[khi])*(h*h)/6.0;

  return y;
};

double *CDayValueList::GetValues(){

  double *y = new double[Length()];
 
  for (int cI = 0; cI < Length(); cI++)
    y[cI] = GetValueAbs(cI);

  return y;
}

double *CDayValueList::GetDays(){

  double *adY = new double[Length()];
 
  for (int cI = 0; cI < Length(); cI++)
    adY[cI] = GetDayAbs(cI);

  return adY;
}

void CDayValueList::Check(void){
  LOTSassert( StartDay() >= 0 );
  LOTSassert( StartDay() < EndDay() );
};

/Jennemaan

Avatar billede fastpoint Nybegynder
08. maj 2001 - 10:30 #1
fjern ; efter den sidste linie
void CDayValueList::Check(void){
  LOTSassert( StartDay() >= 0 );
  LOTSassert( StartDay() < EndDay() );
}; <--

tror jeg nok
Avatar billede fastpoint Nybegynder
08. maj 2001 - 10:31 #2
og gætter mig frem...c++ skal man..men vc++ ved jeg ikke
Avatar billede borrisholt Novice
08. maj 2001 - 10:34 #3
du har sletter linjen #include \"stdafx.h\"


....

Jens B
Avatar billede borrisholt Novice
08. maj 2001 - 10:36 #4
hvis du opretter en ny console application

og retter


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

#include \"stdafx.h\"

int main(int argc, char* argv[])
{
    printf(\"Hello World!\\n\");
    return 0;
}

til

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

//#include \"stdafx.h\" <--- HER er der retter

int main(int argc, char* argv[])
{
    printf(\"Hello World!\\n\");
    return 0;
}

og trykker compiler får du præcis den fejl.

Jens B http://fotx.net/borrisholt
Avatar billede jpk Nybegynder
08. maj 2001 - 10:37 #5
Du kan indsætte linien:
#include \"stdafx.h\"
øverst i din .cpp-fil, eller vælge
Project->Settings, fanebladet C++ og \"Precompiled Headers\" i comboboxen. Sæt så prik i \"Not using precompiled headers\"
Avatar billede jennemaan Nybegynder
08. maj 2001 - 11:04 #6
thx for hjælpen!

/Jennemaan
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester