Hello everyone, I have got some questions and i am really hopping someone could help me out with them. I have a class privately encapsulated in another class. Now, I'm trying to make an object of it in my testDriver but I'm not quite sure how to do that. I've tried a bunch of things but it resulted in failure.
#include <vcl.h>
#pragma hdrstop
#include<iostream>
#include"Flights.h"
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[]){
string Adl, Mel;
// FlightsTL::Flight::FlightsTL:Flight::Flight b ;
cout<<"check if this works and then we are in business\n";
system("pause");
return 0;
}
I've written out all the code declarations in my header file and I've implemented it in the following CPP file (I'm going to put the code down). This is what my code looks like:
#include"Flights.h"
//Start House-keeping functions
/*Default constructor
*
*/
FlightsTL:: Flight:: Flight (){
setOrigin("");
setDestination("");
setDepartureTime(0);
setDuration(0) ;
}
/* Constructor for flight object
*
*
*/
FlightsTL:: Flight::Flight(const string &orig ,const string &destin ,const double &dep, const double &dur ){
org = orig;
dest = destin;
depTime =dep;
dura = dur;
}
/* copy constructor for flight object
*
*
*
FlightsTL:: Flight:: Flight(const Flight& rhs){
} */
/**destructor for flight object
*
*
*/
FlightsTL:: Flight:: ~Flight(){
}
//end House-keeping functions
//______________________________________________\\
/* Equals operation
*
*/
FlightsTL::Flight& FlightsTL:: Flight::operator=(const Flight& rhs){
return *this;
}
/* get origin
*
*/
string FlightsTL:: Flight::getOrigin() const{
return org;
}
/* get destination
*
*/
string FlightsTL:: Flight::getDestination()const{
return dest;
}
/* get departure time
*
*/
double FlightsTL:: Flight:: getDepartureTime()const{
return depTime;
}
/* get duration
*
*/
double FlightsTL:: Flight:: getDuration ()const{
return dura;
}
/* set origin
*
*/
void FlightsTL:: Flight:: setOrigin(string t ){
org = t;
}
/* set destination
*
*/
void FlightsTL:: Flight:: setDestination(string s){
dest =s;
}
/* set departure time
*
*/
void FlightsTL:: Flight:: setDepartureTime(double c){
depTime = c;
}
/* get duration
*
*/
void FlightsTL:: Flight:: setDuration(double d){
dura = d;
}
/* set all
*
*/
void FlightsTL:: Flight:: setAll(string a,string b,double c,double d){
setOrigin(a);
setDestination(b);
setDepartureTime(c);
setDuration(d) ;
}
/** ToString to display flight information
*
*/
string FlightsTL:: Flight:: toString()const{
string s;
double depT = getDepartureTime();
double durA = getDuration();
// convert double to string
char deptStr[50];
sprintf(deptStr,"%g",depT);
// convert to string
char durStr[50];
sprintf(durStr,"%g",durA);
// print all Flight information
s=getOrigin() +"\t"+ getDestination() + "\t"+ deptStr + "\t"+ durStr +"\n" ;
return s;
}
//__________________end of Flight implementation_____________\\
/*Default constructor
*
*/
FlightsTL::FlightsTL(){
FlightsNum = 0;
}
/* constructor
*
*
*/
// FlightsTL:: FlightsTL(int num){
// }
/*copy constructor
*
*
*/
FlightsTL:: FlightsTL (const FlightsTL& rhs){
Flights = rhs.Flights;
}
/*destructor
*
*
*/
FlightsTL:: ~FlightsTL(){
}
/*Equals operator
*
*
*/
FlightsTL& FlightsTL::operator=(const FlightsTL& rhs){
if (this != &rhs){
return *this;
}
return *this;
}
/* get FlightsNum
*
*/
int FlightsTL:: getFlightsNum (int num){
return FlightsNum;
}
/* set FlightsNum
*
*/
//void FlightsTL:: setFlightsNum(int num){
// }
/*add Flighr
*
*/
void FlightsTL:: addFlight(const string& origin , const string& destination,const double& depTime, const double& duration){
Flights.push_back(Flight(origin,destination,depTime,duration));
FlightsNum++;
}
/** ToString to display all flights and thier information
*
*/
string FlightsTL:: toString()const{
return 0;
}
I'd like to know how to instantiate the privately encapsulated class and the class that's encapsulating it in my testDriver. And if you notice anything else in the code which is bad please let me know.Thank you for help in advance:)
Jay F