Code:
Code:
#include <iostream>
using namespace std;
#include "Flight.h"
Flight::Flight(){
num = 0;
dest[0] = '\0';
}
Flight::Flight(int n, const char* d){
if((n>-1) && (strcmp(d,'\0') == 1)){
num = n;
strcpy(dest,d);
}
else{
num = 0;
dest[0] = '\0' ;
}
}
Flight::~Flight(){
}
Flight& Flight::width(int w){
cout.width(w);
cout << num << dest <<endl;
return *this;
}
int Flight::number() const{
return num;
}
const char* Flight::destination() const{
return dest;
}
ostream& operator<<(ostream& os, const Flight& st){
os << st.num << ' ' << st.dest << endl;
return os;
}
void display(Flight flight) {
cout << flight.width(2) << endl;
}
int main ( ) {
Flight f, g(857, "Toronto");
cout << g.width(9) << endl;
f = g;
display(f);
cout << f.number() << endl;
cout << f.destination() << endl;
return 0;
}
Header:
Code:
class Flight{
int num;
char dest[15];
public:
Flight();
Flight(int n, const char* d);
~Flight();
const char* destination() const;
int number() const;
Flight& width(int);
friend ostream& operator<<(ostream& os, const Flight& s);
};
I dont know what the problem is, but when i run this compiled it doesnt give any output.