![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
fstream(Reading and Writing) Support.
I cant find the errors on this codes, I'am having trouble fixing the fin and fout(fsream) for reading and writing from a file(filghts.txt), I have created the text file within my directory I havent triedin compliging the program using windows, I am running linux, I keep getting these errors:
flight.cc:342: error:`fstream' undeclared(first use this function) flight.cc:342: error Each undeclared identifier is reported only once for each function it appears in)flight.cc:342: error: parse error before`;' token flight.cc:347: error: `fin' undeclared flight.cc:347: error: `ios' undeclared flight.cc:347: error: parse error before`::' token flight.cc:348: error: `fout' undeclared flight.cc:401: error: parse error before`::' token flight.cc:530: error: `main' must return `int' This is the code #include <iostream>
#include <fstream>
#include <string>
enum StatusRec {Arrival,Departure};
enum Error_code {success,overflow,underflow,not_found};
struct TimeRec {
int hour,min,sec;
};
struct FlightRec{
char FlightNo[10];
StatusRec Status;
char Destination[20];
TimeRec Time;
TimeRec DelayTime;
};
template <class Node_entry>
struct Node{
Node_entry entry;
Node<Node_entry> *next;
Node();
Node(Node_entry item,Node<Node_entry> *link=NULL);
};
template <class List_entry>
class List{
public:
List();
List(List_entry item,List *link=NULL);
void clear();
bool empty() const;
int size() const;
void traverse(void (*visit)(List_entry &));
void add_delay(List_entry &item);
Error_code modify(const List_entry &item);
Error_code remove(const List_entry &item);
Error_code insert(const List_entry &item);
void print() const;
void printtofile() const;
~List();
List(const List<List_entry> ©);
void operator=(const List<List_entry> &original);
protected:
int count;
Node<List_entry> *head;
Node<List_entry> *tail;
};
List <FlightRec> flights;
TimeRec Now;
fstream fout;
bool operator<(const FlightRec &x, const FlightRec &y)
{
return (strcmp(x.FlightNo,y.FlightNo) < 0);
}
bool operator ==(const FlightRec &x,const FlightRec &y)
{
return (strcmp(x.FlightNo, y.FlightNo)==0);
}
template <class Node_entry>
Node<Node_entry>::Node()
{
next=NULL;
}
template <class Node_entry>
Node<Node_entry>::Node(Node_entry item, Node<Node_entry> *add_on)
{
entry=item;
next=add_on;
}
template <class List_entry>
List<List_entry>::List()
{
head=NULL;
}
template <class List_entry>
List<List_entry>::List(List_entry item,List *add_on)
{
head=item;
tail=add_on;
}
template <class List_entry>
void List<List_entry>::clear()
{
Node<List_entry> *tmp;
while(head!=NULL)
{
tmp=head;
head=head->next;
delete tmp;
}
}
template <class List_entry>
bool List<List_entry>::empty() const
{
return head==NULL;
}
template <class List_entry>
int List<List_entry>::size() const
{
int count=0;
Node<List_entry> *temp=head;
while (temp!=NULL)
{
count++;
temp=temp->next;
}
return count;
}
template <class List_entry>
void List<List_entry>::traverse(void (*visit)(List_entry &))
{
Node<List_entry> *current =head;
while(current!=NULL)
{
(*visit)(current->entry);
current = current->next;
}
}
template <class List_entry>
Error_code List<List_entry>::insert(const List_entry &item)
{
Node<List_entry> *new_entry=new Node<List_entry>(item);
if(new_entry==NULL) return overflow;
else if (empty())
head=new_entry;
else if(item<head->entry)
{
new_entry->next=head;
head=new_entry;
}
else
{
Node<List_entry> *previous=head, *current=head->next;
while(current!=NULL)
{
if(item<current->entry)
{
new_entry->next=current;
break;
}
previous=current;
current=current->next;
}
previous->next=new_entry;
}
return success;
}
template<class List_entry>
Error_code List<List_entry>::remove(const List_entry &item)
{
Node<List_entry> *current=head;
if (empty()) return underflow;
if (item<head->entry) return not_found;
if (item==head->entry)
{
head=head->next;
delete current;
return success;
}
Node<List_entry>*previous=current;
current=current->next;
while(current!=NULL)
{
if (item<head->entry) break;
if (item==current->entry)
{
previous->next=current->next;
delete current;
return success;
}
else
{
previous=current;
current=current->next;
}
}
return not_found;
}
template <class List_entry>
Error_code List<List_entry>::modify(const List_entry &item) //modify time
{
Node<List_entry> *current=head;
if (empty()) return underflow;
if (item<head->entry) return not_found;
if (item==head->entry)
{
head->entry.Time.hour=item.Time.hour;
head->entry.Time.min=item.Time.min;
head->entry.Time.sec=item.Time.sec;
return success;
}
Node<List_entry>*previous=current;
current=current->next;
while(current!=NULL)
{
if (item<head->entry) break;
if (item==current->entry)
{
current->entry.Time.hour=item.Time.hour;
current->entry.Time.min=item.Time.min;
current->entry.Time.sec=item.Time.sec;
return success;
}
else
{
previous=current;
current=current->next;
}
}
return not_found;
}
template<class List_entry>
void List<List_entry>::print() const
{
Node<List_entry> *temp=head;
if(empty()) cout<<"Empty List";
else
while (temp!=NULL)
{
cout<< temp->entry <<" ";
temp=temp->next;
}
cout<<endl;
}
template<class List_entry>
List<List_entry>::~List()
{
Node<List_entry> *tmp;
while(head!=NULL)
{
tmp=head;
head=head->next;
delete tmp;
}
}
template <class List_entry>
List<List_entry>::List(const List<List_entry> &original)
{
Node<List_entry> *new_copy,*original_node=original.head;
if(original_node==NULL) head=NULL;
else
{
head=new_copy = new Node<List_entry>(original_node->entry);
while(original_node->next!=NULL)
{
original_node=original_node->next;
new_copy->next=new Node<List_entry>(original_node->entry);
new_copy=new_copy->next;
}
}
}
template <class List_entry>
void List<List_entry>::operator=(const List<List_entry> &original)
{
Node<List_entry> *new_head,*new_copy,*original_node=original.head;
if (original_node==NULL) head=NULL;
else
{
new_copy=new_head=new Node<List_entry>(original_node->entry);
while(original_node->next!=NULL)
{
original_node=original_node->next;
new_copy->next=new Node<List_entry>(original_node->entry);
new_copy=new_copy->next;
}
}
clear();
head=new_head;
}
void readfile()
{
FlightRec flight;
fstream fin;
fstream fout;
int num;
char temp[10];
fin.open("flights.txt",ios::in);
while(!fin.eof())
{
fin.getline(flight.FlightNo,10);
fin.getline(flight.Destination,10);
fin >> num ;
if (num == 0) flight.Status=Arrival;
if (num == 1) flight.Status=Departure;
fin >> flight.Time.hour;
fin >> flight.Time.min ;
fin >> flight.Time.sec ;
fin >> flight.DelayTime.hour ;
fin >> flight.DelayTime.min ;
fin >> flight.DelayTime.sec ;
fin.getline(temp,10);
if (strcmp(flight.FlightNo,"")!=0) flights.insert(flight);
}
fin.close();
}
void WriteFile(FlightRec &flight)
{
fout<<flight.FlightNo<<'\n';
fout<<flight.Destination<<'\n';
fout<<flight.Status<<'\n';
fout<<flight.Time.hour<<'\n';
fout<<flight.Time.min<<'\n';
fout<<flight.Time.sec<<'\n';
fout<<flight.DelayTime.hour<<'\n';
fout<<flight.DelayTime.min<<'\n';
fout<<flight.DelayTime.sec<<'\n';
}
template<class List_entry>
void List<List_entry>::printtofile() const
{
Node<List_entry> *temp=head;
fout.open("flights.txt",ios::out);
while(temp!=NULL)
{
WriteFile(temp->entry);
temp=temp->next;
}
fout.close();
}
bool ReadFlight(FlightRec &flight)
{
char tmp;
std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
std::cout<<"Enter Destination: ";
std::cin>>flight.Destination;
std::cout<<"Departure or Arrival(D or A):";
std::cin>>tmp;
if(tmp=='D'||tmp=='d') flight.Status=Departure;
if(tmp=='A'||tmp=='a') flight.Status=Arrival;
std::cout<<"Enter Time: ";
std::cin>>flight.Time.hour;
std::cin>>flight.Time.min;
flight.Time.sec=0;
flight.DelayTime.hour=0;
flight.DelayTime.min=0;
flight.DelayTime.sec=0;
return strcmp(flight.FlightNo,"")!=0;
}
template <class List_entry>
void List<List_entry>::add_delay(List_entry &item)
{
Node<List_entry> *current =head;
while(current!=NULL)
{
if (item==current->entry)
{
current->entry.DelayTime.hour=item.DelayTime.hour;
current->entry.DelayTime.min=item.DelayTime.min;
current->entry.DelayTime.sec=item.DelayTime.sec;
}
current = current->next;
}
}
void PrintFlight(FlightRec &flight)
{
std::cout<<flight.FlightNo<<" "<<flight.Destination<<" ";
if(flight.Status==Departure)
std::cout<<"Departure"; else std::cout<<"Arrival\n";
if(flight.Time.hour<=9)
std::cout<<"0"<<flight.Time.hour;
else std::cout<<flight.Time.hour;
std::cout<<":";
if(flight.Time.min<=9)
std::cout<<"0"<<flight.Time.min;
else std::cout<<flight.Time.min;
std::cout<<":";
if(flight.Time.sec<=9)
std::cout<<"0"<<flight.Time.sec;
else std::cout<<"0"<<flight.Time.sec;
std::cout<<'\n';
std::cout << '\n';
if(flight.Time.hour<9)
std::cout<< "with delay " <<"0"<<flight.DelayTime.hour;
else std::cout<<flight.DelayTime.hour;
std::cout<<":";
if(Now.min<=9)
std::cout<<"0"<<flight.DelayTime.min;
else std::cout<<flight.DelayTime.min;
std::cout<<":";
if(Now.sec<=9)
std::cout<<"0"<<flight.DelayTime.sec;
else std::cout<<flight.DelayTime.sec;
std::cout<<'\n';
}
void not_departure_yet(FlightRec &flight)
{
if(flight.Status==1)
if(Now.hour<flight.Time.hour+flight.DelayTime.hour) PrintFlight(flight);
else if(Now.hour==flight.Time.hour+flight.DelayTime.hour)
if(Now.min<flight.Time.min+flight.DelayTime.min) PrintFlight(flight);
else if (Now.min==flight.Time.min+flight.DelayTime.min)
if(Now.sec<flight.Time.sec+flight.DelayTime.sec)
PrintFlight(flight);
}
void not_arrive_yet(FlightRec &flight)
{
if(flight.Status==0)
if(Now.hour<flight.Time.hour+flight.DelayTime.hour) PrintFlight(flight);
else if(Now.hour==flight.Time.hour+flight.DelayTime.hour)
if(Now.min<flight.Time.min+flight.DelayTime.min) PrintFlight(flight);
else if (Now.min==flight.Time.min+flight.DelayTime.min)
if(Now.sec<flight.Time.sec+flight.DelayTime.sec)
PrintFlight(flight);
}
void main ()
{
FlightRec flight;
int reply;
Error_code ecode;
readfile();
do{
std::cout<<"Enter 0: Insert Current Time"<<'\n';
std::cout<<" 1: Insert a new flight"<<'\n';
std::cout<<" 2: Delete(Cancel a Flight)"<<'\n';
std::cout<<" 3: Clear the List"<<'\n';
std::cout<<" 4: Print all the flights(default:sorted by FlightNo) "<<'\n';
std::cout<<" 5: Print all the flights that have not departure yet "<<'\n';
std::cout<<" 6: Print all the flights that have not arrive yet "<<'\n';
std::cout<<" 7: Size of the List"<<'\n';
std::cout<<" 8: Modify Time of a flight"<<'\n';
std::cout<<" 9: Enter Delay for a flight"<<'\n';
std::cout<<" 10: Exit "<<'\n';
std::cin>>reply;
switch(reply)
{
case 0: std::cout<<"Enter Current time in (hh mm) ";
std::cin>>Now.hour;
std::cin>>Now.min;
Now.sec=0;
std::cout<<"The current time is: ";
if(Now.hour<=9)
std::cout<<"0"<<Now.hour;
else std::cout<<Now.hour;
std::cout<<":";
if(Now.min<=9)
std::cout<<"0"<<Now.min;
else std::cout<<Now.min;
std::cout<<":";
if(Now.sec<=9)
std::cout<<"0"<<Now.sec;
else std::cout<<Now.sec;
std::cout<<'\n';
break;
case 1: if(ReadFlight(flight))
if(flights.insert(flight)==overflow)
std::cout<<"Memory Full "<<'\n';
break;
case 2: std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
ecode=flights.remove(flight);
if(ecode==underflow) std::cout<<"Empty List"<<'\n';
else if(ecode==not_found) std::cout<<"Not Found"<<'\n';
break;
case 3: flights.clear();
break;
case 4: flights.traverse(PrintFlight);
break;
case 5: flights.traverse(not_departure_yet);
break; // Print flights not departure yet
case 6: flights.traverse(not_arrive_yet);//Print flights not arrived yet
break;
case 7: std::cout<<"Size="<<flights.size()<<'\n';
break;
case 8: std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
std::cout<<"Enter new time for the flight:";
std::cin>>flight.Time.hour;
std::cin>>flight.Time.min;
flight.Time.sec=0;
ecode=flights.modify(flight); // Modify Time of a flight
if(ecode==underflow) std::cout<<"Empty List"<<'\n';
else if(ecode==not_found) std::cout<<"Not Found"<<'\n';
break;
case 9: std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
std::cout<<"Enter Delay(hh mm): ";
std::cin>>flight.DelayTime.hour;
std::cin>>flight.DelayTime.min;
flight.DelayTime.sec=0;
flights.add_delay(flight);
break;
case 10: reply=10;
break;
default: break;
}
}while(reply!=10);
flights.printtofile();
}
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
Ahh! For one,
void main int main For second, "fout" should be "cout". Thirdly, I think when you have fin.open("flights.txt",ios::in); it should be: fin.open("flights.txt",fstream::in);![]() |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Nop it didnt work, Changes made:
fout.open("flights.txt",ios::out);cout.open("flights.txt",ios::out);fin.open("flights.txt",ios::in);fin.open("flights.txt",fstream::in);
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Alright. I just edited this so it looked a little better and so it compiled properly. Whether it does what you want it to or not, I have no clue. But it compiles fine with GCC 3.4. One solution to your problem (the easiest solution) was to just use using namespace std at the beginning. Also, fout does not need to be cout. fout is his handle for outputting data to a file, not a typo. void main does need to be int main on almost all modern c++ compilers, namely GCC
![]() #include <iostream>
#include <fstream>
#include <string>
using namespace std; /// very important in order to remove class confusion and
/// redundant typing. puts std:: in front of all class mem-
/// bers that can be found within the std class.
enum StatusRec {Arrival,Departure};
enum Error_code {success,overflow,underflow,not_found};
struct TimeRec {
int hour,min,sec;
};
struct FlightRec {
char FlightNo[10];
StatusRec Status;
char Destination[20];
TimeRec Time;
TimeRec DelayTime;
};
template <class Node_entry>
struct Node {
Node_entry entry;
Node<Node_entry> *next;
Node();
Node(Node_entry item,Node<Node_entry> *link=NULL);
};
template <class List_entry>
class List {
public:
List();
List(List_entry item,List *link=NULL);
void clear();
bool empty() const;
int size() const;
void traverse(void (*visit)(List_entry &));
void add_delay(List_entry &item);
Error_code modify(const List_entry &item);
Error_code remove(const List_entry &item);
Error_code insert(const List_entry &item);
void print() const;
void printtofile() const;
~List();
List(const List<List_entry> ©);
void operator=(const List<List_entry> &original);
protected:
int count;
Node<List_entry> *head;
Node<List_entry> *tail;
};
List <FlightRec> flights;
TimeRec Now;
ofstream fout;
bool operator<(const FlightRec &x, const FlightRec &y)
{
return (strcmp(x.FlightNo,y.FlightNo) < 0);
}
bool operator ==(const FlightRec &x,const FlightRec &y)
{
return (strcmp(x.FlightNo, y.FlightNo)==0);
}
template <class Node_entry>
Node<Node_entry>::Node()
{
next=NULL;
}
template <class Node_entry>
Node<Node_entry>::Node(Node_entry item, Node<Node_entry> *add_on)
{
entry=item;
next=add_on;
}
template <class List_entry>
List<List_entry>::List()
{
head=NULL;
}
template <class List_entry>
List<List_entry>::List(List_entry item,List *add_on)
{
head=item;
tail=add_on;
}
template <class List_entry>
void List<List_entry>::clear()
{
Node<List_entry> *tmp;
while(head!=NULL)
{
tmp=head;
head=head->next;
delete tmp;
}
}
template <class List_entry>
bool List<List_entry>::empty() const
{
return head==NULL;
}
template <class List_entry>
int List<List_entry>::size() const
{
int count=0;
Node<List_entry> *temp=head;
while (temp!=NULL)
{
count++;
temp=temp->next;
}
return count;
}
template <class List_entry>
void List<List_entry>::traverse(void (*visit)(List_entry &))
{
Node<List_entry> *current =head;
while(current!=NULL)
{
(*visit)(current->entry);
current = current->next;
}
}
template <class List_entry>
Error_code List<List_entry>::insert(const List_entry &item)
{
Node<List_entry> *new_entry=new Node<List_entry>(item);
if(new_entry==NULL) return overflow;
else if (empty())
head=new_entry;
else if(item<head->entry)
{
new_entry->next=head;
head=new_entry;
}
else
{
Node<List_entry> *previous=head, *current=head->next;
while(current!=NULL)
{
if(item<current->entry)
{
new_entry->next=current;
break;
}
previous=current;
current=current->next;
}
previous->next=new_entry;
}
return success;
}
template<class List_entry>
Error_code List<List_entry>::remove(const List_entry &item)
{
Node<List_entry> *current=head;
if (empty()) return underflow;
if (item<head->entry) return not_found;
if (item==head->entry)
{
head=head->next;
delete current;
return success;
}
Node<List_entry>*previous=current;
current=current->next;
while(current!=NULL)
{
if (item<head->entry) break;
if (item==current->entry)
{
previous->next=current->next;
delete current;
return success;
}
else
{
previous=current;
current=current->next;
}
}
return not_found;
}
template <class List_entry>
Error_code List<List_entry>::modify(const List_entry &item) //modify time
{
Node<List_entry> *current=head;
if (empty()) return underflow;
if (item<head->entry) return not_found;
if (item==head->entry)
{
head->entry.Time.hour=item.Time.hour;
head->entry.Time.min=item.Time.min;
head->entry.Time.sec=item.Time.sec;
return success;
}
Node<List_entry>*previous=current;
current=current->next;
while(current!=NULL)
{
if (item<head->entry) break;
if (item==current->entry)
{
current->entry.Time.hour=item.Time.hour;
current->entry.Time.min=item.Time.min;
current->entry.Time.sec=item.Time.sec;
return success;
}
else
{
previous=current;
current=current->next;
}
}
return not_found;
}
template<class List_entry>
void List<List_entry>::print() const
{
Node<List_entry> *temp=head;
if(empty()) std::cout<<"Empty List"; /// since you've decided not to use 'using namespace std',
/// you have to declare the superclass (std) in relation
/// to its member function/class.
else
while (temp!=NULL)
{
cout<< temp->entry <<" ";
temp=temp->next;
}
cout<<endl;
}
template<class List_entry>
List<List_entry>::~List()
{
Node<List_entry> *tmp;
while(head!=NULL)
{
tmp=head;
head=head->next;
delete tmp;
}
}
template <class List_entry>
List<List_entry>::List(const List<List_entry> &original)
{
Node<List_entry> *new_copy,*original_node=original.head;
if(original_node==NULL) head=NULL;
else
{
head=new_copy = new Node<List_entry>(original_node->entry);
while(original_node->next!=NULL)
{
original_node=original_node->next;
new_copy->next=new Node<List_entry>(original_node->entry);
new_copy=new_copy->next;
}
}
}
template <class List_entry>
void List<List_entry>::operator=(const List<List_entry> &original)
{
Node<List_entry> *new_head,*new_copy,*original_node=original.head;
if (original_node==NULL) head=NULL;
else
{
new_copy=new_head=new Node<List_entry>(original_node->entry);
while(original_node->next!=NULL)
{
original_node=original_node->next;
new_copy->next=new Node<List_entry>(original_node->entry);
new_copy=new_copy->next;
}
}
clear();
head=new_head;
}
void readfile()
{
FlightRec flight;
fstream fin;
fstream fout;
int num;
char temp[10];
fin.open("flights.txt",ios::in);
while(!fin.eof())
{
fin.getline(flight.FlightNo,10);
fin.getline(flight.Destination,10);
fin >> num ;
if (num == 0) flight.Status=Arrival;
if (num == 1) flight.Status=Departure;
fin >> flight.Time.hour;
fin >> flight.Time.min ;
fin >> flight.Time.sec ;
fin >> flight.DelayTime.hour ;
fin >> flight.DelayTime.min ;
fin >> flight.DelayTime.sec ;
fin.getline(temp,10);
if (strcmp(flight.FlightNo,"")!=0) flights.insert(flight);
}
fin.close();
}
void WriteFile(FlightRec &flight)
{
fout<<flight.FlightNo<<'\n';
fout<<flight.Destination<<'\n';
fout<<flight.Status<<'\n';
fout<<flight.Time.hour<<'\n';
fout<<flight.Time.min<<'\n';
fout<<flight.Time.sec<<'\n';
fout<<flight.DelayTime.hour<<'\n';
fout<<flight.DelayTime.min<<'\n';
fout<<flight.DelayTime.sec<<'\n';
}
template<class List_entry>
void List<List_entry>::printtofile() const
{
Node<List_entry> *temp=head;
fout.open("flights.txt",ios::out);
while(temp!=NULL)
{
WriteFile(temp->entry);
temp=temp->next;
}
fout.close();
}
bool ReadFlight(FlightRec &flight)
{
char tmp;
std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
std::cout<<"Enter Destination: ";
std::cin>>flight.Destination;
std::cout<<"Departure or Arrival(D or A):";
std::cin>>tmp;
if(tmp=='D'||tmp=='d') flight.Status=Departure;
if(tmp=='A'||tmp=='a') flight.Status=Arrival;
std::cout<<"Enter Time: ";
std::cin>>flight.Time.hour;
std::cin>>flight.Time.min;
flight.Time.sec=0;
flight.DelayTime.hour=0;
flight.DelayTime.min=0;
flight.DelayTime.sec=0;
return strcmp(flight.FlightNo,"")!=0;
}
template <class List_entry>
void List<List_entry>::add_delay(List_entry &item)
{
Node<List_entry> *current =head;
while(current!=NULL)
{
if (item==current->entry)
{
current->entry.DelayTime.hour=item.DelayTime.hour;
current->entry.DelayTime.min=item.DelayTime.min;
current->entry.DelayTime.sec=item.DelayTime.sec;
}
current = current->next;
}
}
void PrintFlight(FlightRec &flight)
{
std::cout<<flight.FlightNo<<" "<<flight.Destination<<" ";
if(flight.Status==Departure)
std::cout<<"Departure"; else std::cout<<"Arrival\n";
if(flight.Time.hour<=9)
std::cout<<"0"<<flight.Time.hour;
else std::cout<<flight.Time.hour;
std::cout<<":";
if(flight.Time.min<=9)
std::cout<<"0"<<flight.Time.min;
else std::cout<<flight.Time.min;
std::cout<<":";
if(flight.Time.sec<=9)
std::cout<<"0"<<flight.Time.sec;
else std::cout<<"0"<<flight.Time.sec;
std::cout<<'\n';
std::cout << '\n';
if(flight.Time.hour<9)
std::cout<< "with delay " <<"0"<<flight.DelayTime.hour;
else std::cout<<flight.DelayTime.hour;
std::cout<<":";
if(Now.min<=9)
std::cout<<"0"<<flight.DelayTime.min;
else std::cout<<flight.DelayTime.min;
std::cout<<":";
if(Now.sec<=9)
std::cout<<"0"<<flight.DelayTime.sec;
else std::cout<<flight.DelayTime.sec;
std::cout<<'\n';
}
void not_departure_yet(FlightRec &flight)
{
if(flight.Status==1)
if(Now.hour<flight.Time.hour+flight.DelayTime.hour) PrintFlight(flight);
else if(Now.hour==flight.Time.hour+flight.DelayTime.hour)
if(Now.min<flight.Time.min+flight.DelayTime.min) PrintFlight(flight);
else if (Now.min==flight.Time.min+flight.DelayTime.min)
if(Now.sec<flight.Time.sec+flight.DelayTime.sec)
PrintFlight(flight);
}
void not_arrive_yet(FlightRec &flight)
{
if(flight.Status==0)
if(Now.hour<flight.Time.hour+flight.DelayTime.hour) PrintFlight(flight);
else if(Now.hour==flight.Time.hour+flight.DelayTime.hour)
if(Now.min<flight.Time.min+flight.DelayTime.min) PrintFlight(flight);
else if (Now.min==flight.Time.min+flight.DelayTime.min)
if(Now.sec<flight.Time.sec+flight.DelayTime.sec)
PrintFlight(flight);
}
int main ()
{
FlightRec flight;
int reply;
Error_code ecode;
readfile();
do{
std::cout<<"Enter 0: Insert Current Time"<<'\n';
std::cout<<" 1: Insert a new flight"<<'\n';
std::cout<<" 2: Delete(Cancel a Flight)"<<'\n';
std::cout<<" 3: Clear the List"<<'\n';
std::cout<<" 4: Print all the flights(default:sorted by FlightNo) "<<'\n';
std::cout<<" 5: Print all the flights that have not departure yet "<<'\n';
std::cout<<" 6: Print all the flights that have not arrive yet "<<'\n';
std::cout<<" 7: Size of the List"<<'\n';
std::cout<<" 8: Modify Time of a flight"<<'\n';
std::cout<<" 9: Enter Delay for a flight"<<'\n';
std::cout<<" 10: Exit "<<'\n';
std::cin>>reply;
switch(reply)
{
case 0: std::cout<<"Enter Current time in (hh mm) ";
std::cin>>Now.hour;
std::cin>>Now.min;
Now.sec=0;
std::cout<<"The current time is: ";
if(Now.hour<=9)
std::cout<<"0"<<Now.hour;
else std::cout<<Now.hour;
std::cout<<":";
if(Now.min<=9)
std::cout<<"0"<<Now.min;
else std::cout<<Now.min;
std::cout<<":";
if(Now.sec<=9)
std::cout<<"0"<<Now.sec;
else std::cout<<Now.sec;
std::cout<<'\n';
break;
case 1: if(ReadFlight(flight))
if(flights.insert(flight)==overflow)
std::cout<<"Memory Full "<<'\n';
break;
case 2: std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
ecode=flights.remove(flight);
if(ecode==underflow) std::cout<<"Empty List"<<'\n';
else if(ecode==not_found) std::cout<<"Not Found"<<'\n';
break;
case 3: flights.clear();
break;
case 4: flights.traverse(PrintFlight);
break;
case 5: flights.traverse(not_departure_yet);
break; // Print flights not departure yet
case 6: flights.traverse(not_arrive_yet);//Print flights not arrived yet
break;
case 7: std::cout<<"Size="<<flights.size()<<'\n';
break;
case 8: std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
std::cout<<"Enter new time for the flight:";
std::cin>>flight.Time.hour;
std::cin>>flight.Time.min;
flight.Time.sec=0;
ecode=flights.modify(flight); // Modify Time of a flight
if(ecode==underflow) std::cout<<"Empty List"<<'\n';
else if(ecode==not_found) std::cout<<"Not Found"<<'\n';
break;
case 9: std::cout<<"Enter FlightNo: ";
std::cin>>flight.FlightNo;
std::cout<<"Enter Delay(hh mm): ";
std::cin>>flight.DelayTime.hour;
std::cin>>flight.DelayTime.min;
flight.DelayTime.sec=0;
flights.add_delay(flight);
break;
case 10: reply=10;
break;
default: break;
}
} while(reply!=10);
flights.printtofile();
return 0; /// success
}
/// Edited by iignotus at gmail dot com -- mild code beautifying, successful compilation![]()
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Thanks iignotus, I had to add the std cause Linux does not recognize the library.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|