c++ - Don't know how to call method of a class in main -


so programmed this, have main.cpp call method in class called getdata, im trying user input departure , destination, , output price , time (all data stored in textfile fly.txt)

it doesnt seem complicated, yet keep getting errors. have declared correctly in header file, , have called methods correctly in main body?

thanks in advance!

getdata.h

#ifndef getdata_h     #define getdata_h     #pragma once  class getdata { public: getdata(string dep,string des)      ifstream data("fly.txt"); string departure,destination,time; int price;     vector<string> flights;     vector<string> times;     vector<int> prices;  void getflights(string dep, string des); void gettime(string dep, string des); void getprice(string dep, string des); };  #endif 

getdata.cpp

#include "getdata.h" #include "std_lib_facilities.h"   getdata::getflights(string dep, string des){ while(data >> departure >> destination >> time >> price){     if (dep==departure && des=destination) flights.push_back(departure); } }  getdata::getprice(string dep, string des){ while(data >> departure >> destination >> time >> price){     if (dep==departure && des=destination) prices.push_back(price); }  }  getdata::gettime(string dep, string des){ while(data >> departure >> destination >> time >> price){     if (dep==departure && des=destination) times.push_back(time); }  } 

main.cpp

#include "std_lib_facilities.h" #include "getdata.h"  int main(){ getdata test;  cout<<"where flying from?"<<endl; string ideparture; cin>>ideparture; cout<<"where flying to?"<<endl; string idestination; cin>>idestination;  getdata.getflights(ideparture, idestination);   keep_window_open("q"); } 

in main():

getdata constructor needs 2 parameters: getdata test(string dep, string des);

in getdata

  • define class variables
  • #pragma once same #ifndef getdata_h [...]

getdata:

class getdata {   private:     std::ifstream data;     std::string departure,destination,time;     int price;     std::vector<std::string> flights;     std::vector<std::string> times;     std::vector<int> prices;   ... } 

...

(dep==departure && des==destination) 

...

void getdata::fn(...) 

i don't have patience find bugs...


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -