-
-
Save rhysforyou/5252624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include "Agent.h" | |
using namespace std; | |
int Agent:: size = 0; | |
Agent::Agent() | |
{ | |
number= 0; | |
name= ""; | |
mobile = ""; | |
} | |
Agent::Agent(int tempnumber, string temp_name, string temp_phone) | |
{ | |
number= tempnumber; | |
name= temp_name; | |
mobile= temp_phone; | |
} | |
void Agent::print_agent() | |
{ | |
cout << number << ";" << name << ";" << mobile << endl; | |
cout << endl; | |
} | |
Agent *Agent::gather_agent(int agent_num,Agent *list) | |
{ | |
for(int i=0; i < Agent::size; i++) | |
{ | |
if( list[i].number == agent_num) | |
return &list[i]; | |
} | |
cerr << "No such Agent" << endl; | |
return NULL; | |
} | |
Agent *get_agents (char *argv) | |
{ | |
char size_buffer[15]; | |
int tempnumber; | |
string temp_name; | |
string temp_phone; | |
Agent list; | |
cout << "Reading file..." << endl; | |
ifstream infile; | |
infile.open(argv); | |
infile.getline(size_buffer,'\n'); | |
Agent::size = atoi(size_buffer); | |
Agent *agents = new Agent[Agent::size]; | |
for( int i=0; i < Agent::size; i++) | |
{ | |
// read in agent number | |
string str= ""; | |
getline(infile,str,';'); | |
tempnumber = atoi(str.c_str()); | |
// read in name | |
getline(infile,temp_name,';'); | |
// read in phone | |
getline(infile,temp_phone,'\n'); | |
agents[i] = Agent(tempnumber,temp_name,temp_phone); | |
} | |
return agents; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
using namespace std; | |
#ifndef AGENT_H | |
#define AGENT_H | |
class Agent | |
{ | |
private: | |
int number; | |
string name; | |
string mobile; | |
public: | |
static int size; | |
Agent(); | |
Agent(int tempnumber, string temp_name, string temp_phone); | |
void print_agent(); | |
Agent *get_agents (char *argv); | |
static Agent *gather_agent(int agent_num,Agent *list); | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include "Buyer.h" | |
using namespace std; | |
int Buyer:: b_size = 0; | |
Buyer::Buyer() | |
{ | |
b_name = ""; | |
b_address= ""; | |
b_phone = ""; | |
} | |
Buyer::Buyer(string temp_bname, string temp_baddress, string temp_bphone) | |
{ | |
b_name= temp_bname; | |
b_address= temp_baddress; | |
b_phone= temp_bphone; | |
} | |
void Buyer::print_buyer() | |
{ | |
cout << b_name << ";" << b_address << ";" << b_phone << endl; | |
cout << endl; | |
} | |
Buyer *Buyer::gather_buyer(string buyer_phone,Buyer *contacts) | |
{ | |
for(int i=0; i < Buyer::b_size; i++) | |
{ | |
if( contacts[i].b_phone == buyer_phone) | |
return &contacts[i]; | |
} | |
cerr << "No such Buyer" << endl; | |
return NULL; | |
} | |
Buyer *get_buyer (char *argv) | |
{ | |
char b_buffer[15]; | |
string temp_bname, temp_baddress,temp_bphone; | |
Buyer contacts; | |
cout << "Load Buyer's information" << endl; | |
ifstream infile; | |
infile.open(argv); | |
infile.getline(b_buffer,'\n'); | |
Buyer::b_size = atoi(b_buffer); | |
Buyer *Buyers = new Buyer[Buyer::b_size]; | |
for( int i=0; i < Buyer::b_size; i++) | |
{ | |
// read in buyer name | |
getline(infile,temp_bname,';'); | |
// read in buyers address | |
getline(infile,temp_baddress,';'); | |
// read in Property type | |
getline(infile,temp_bphone,'\n'); | |
Buyers[i] = Buyer(temp_bname,temp_baddress,temp_bphone); | |
} | |
return Buyers; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
using namespace std; | |
#ifndef BUYER_H | |
#define BUYER_H | |
class Buyer | |
{ private: | |
string b_name; | |
string b_address; | |
string b_phone; | |
public: | |
static int b_size; | |
Buyer(); | |
Buyer(string temp_bname, string temp_baddress, string temp_bphone); | |
void print_buyer(); | |
Buyer *get_buyer (char *argv); | |
static Buyer *gather_buyer(string buyer_phone,Buyer *contacts); | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <string> | |
#include "Inspection.h" | |
#include "Agent.h" | |
#include "Buyer.h" | |
#include "Property.h" | |
using namespace std; | |
Inspection* Inspection:: firstbook; | |
Inspection:: Inspection() | |
{ | |
Date.day= 0; | |
Date.month= 0; | |
Date.year = 0; | |
Date.hour = 0; | |
Date.min = 0; | |
string comments=""; | |
next = NULL; | |
} | |
Inspection:: Inspection( int D, int MM, int YYYY , int hr, int minute, string comm) | |
{ | |
Date.day = D; | |
Date.month = MM; | |
Date.year = YYYY; | |
Date.hour = hr; | |
Date.min = minute; | |
comments = comm; | |
} | |
void Inspection:: printbooking() | |
{ | |
cout << endl; | |
cout << " the booking list:" << endl; | |
Inspection *tmp = firstbook; | |
if ( tmp == NULL) | |
{ | |
cout << "the bookings are empty"; | |
} | |
while( tmp != NULL) | |
{ | |
cout << "day:" << tmp->Date.day << endl; | |
cout << "month:" << tmp->Date.month << endl; | |
cout << "year:" << tmp->Date.year << endl; | |
cout << "time:" << tmp->Date.hour << ":" << tmp->Date.min << endl; | |
cout << "comments:" << tmp->comments << endl; | |
tmp = tmp->next; | |
} | |
} | |
void Inspection:: addNewBooking(Agent *list, Property *listings,Buyer *contacts) | |
{ | |
int D, MM , YYYY ,hr, minute, agent_num,property_id; | |
string comm, buyer_phone; | |
// get a new list | |
Inspection* newbooking = new Inspection; | |
// read in the data | |
while( newbooking->single_agent == NULL) | |
{ | |
cout << "agent number:"; | |
cin >> agent_num; | |
newbooking->single_agent = Agent::gather_agent(agent_num,list); | |
} | |
newbooking->single_agent->print_agent(); | |
while( newbooking->single_buyer == NULL) | |
{ | |
cout << "Buyer phone:"; | |
getline(cin,buyer_phone); | |
newbooking->single_buyer = Buyer::gather_buyer(buyer_phone,contacts); | |
} | |
newbooking->single_buyer->print_buyer(); | |
while( newbooking->single_property == NULL) | |
{ | |
cout << "Property id:"; | |
cin >> property_id; | |
newbooking->single_property = Property::gather_property(property_id,listings); | |
} | |
newbooking->single_property->print_property(); | |
cout << "Inspection Date(day month year):"; | |
cin >> D >> MM >> YYYY; | |
newbooking->Date.day = D; | |
newbooking->Date.month = MM; | |
newbooking->Date.year = YYYY; | |
cout << "Inspection Time(hour min):"; | |
cin >> hr >> minute; | |
newbooking->Date.hour = hr; | |
newbooking->Date.min = minute; | |
cin.ignore(); | |
cout << "Comments:"; | |
getline(cin,comm,'\n'); | |
newbooking->comments = comm; | |
// set temp to the first record | |
Inspection *tmp = Inspection::firstbook; | |
if( tmp != NULL) | |
{ | |
while ( tmp->next != NULL) | |
{ | |
tmp = tmp->next; | |
} | |
// point last node to new node | |
tmp->next = newbooking; | |
} | |
else | |
{ | |
// first node in the list | |
Inspection::firstbook = newbooking; | |
} | |
} | |
void Inspection:: searchBookings() | |
{ | |
} | |
void Inspection:: saveBookings() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
using namespace std; | |
#ifndef INSPECTION_H | |
#define INSPECTION_H | |
#include "Inspection.h" | |
struct DateTime | |
{ | |
int hour; | |
int min; | |
int day; | |
int month; | |
int year; | |
}; | |
class Agent; | |
class Buyer; | |
class Property; | |
class Inspection | |
{ | |
private: | |
DateTime Date; | |
string comments; | |
Inspection* next; | |
static Inspection* firstbook; | |
Agent *single_agent; | |
Buyer *single_buyer; | |
Property *single_property; | |
public: | |
Inspection(); | |
Inspection(int D,int MM ,int YYYY ,int hr,int minute,string comm); | |
void printbooking(); | |
static void addNewBooking(Agent *list, Property *listings,Buyer *contacts); | |
void searchBookings(); | |
void saveBookings(); | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include "Property.h" | |
using namespace std; | |
int Property:: p_size = 0; | |
Property::Property() | |
{ | |
ident= 0; | |
address= ""; | |
type = ""; | |
price = ""; | |
} | |
Property::Property(int temp_ident, string temp_paddress, string temp_ptype, string temp_pprice) | |
{ | |
ident = temp_ident; | |
address = temp_paddress; | |
type = temp_ptype; | |
price = temp_pprice; | |
} | |
void Property::print_property() | |
{ | |
cout << ident << ";" << address << ";" << type << ";" << price << endl; | |
cout << endl; | |
} | |
Property *Property::gather_property(int property_id,Property *listings) | |
{ | |
for(int i=0; i < Property::p_size; i++) | |
{ | |
if( listings[i].ident == property_id) | |
return &listings[i]; | |
} | |
cerr << "No such Property" << endl; | |
return NULL; | |
} | |
Property *get_property (char *argv) | |
{ | |
int temp_ident; | |
char p_buffer[15]; | |
string temp_paddress,temp_ptype ,temp_pprice; | |
Property listings; | |
cout << "Load properties information" << endl; | |
ifstream infile; | |
infile.open(argv); | |
infile.getline(p_buffer,'\n'); | |
Property::p_size = atoi(p_buffer); | |
Property *Properties = new Property[Property::p_size]; | |
for( int i=0; i < Property::p_size; i++) | |
{ | |
// read in Property number | |
string str= ""; | |
getline(infile,str,';'); | |
temp_ident = atoi(str.c_str()); | |
// read in Property address | |
getline(infile,temp_paddress,';'); | |
// read in Property type | |
getline(infile,temp_ptype,';'); | |
// read in property price | |
getline(infile,temp_pprice,'\n'); | |
Properties[i] = Property(temp_ident,temp_paddress,temp_ptype,temp_pprice); | |
} | |
return Properties; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
using namespace std; | |
#ifndef PROPERTY_H | |
#define PROPERTY_H | |
class Property | |
{ | |
private: | |
int ident; | |
string address; | |
string type; | |
string price; | |
public: | |
static int p_size; | |
Property(); | |
Property(int temp_ident, string temp_paddress, string temp_ptype, string temp_pprice); | |
void print_property(); | |
Property *get_property (char *argv); | |
static Property *gather_property(int property_id,Property *listings); | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include "Agent.h" | |
#include "Property.h" | |
#include "Buyer.h" | |
#include "Inspection.h" | |
using namespace std; | |
int menu(); | |
Agent *get_agents (char *argv); | |
Property *get_property (char *argv); | |
Buyer *get_buyer (char *argv); | |
int main(int argc, char *argv[]) | |
{ | |
bool Quit=false; | |
Inspection* firstbook; | |
Agent *list = get_agents(argv[1]); | |
cout << "loading agent records." << endl; | |
cout << endl; | |
for(int i=0; i < Agent::size; i++) | |
{ | |
list[i].print_agent(); | |
} | |
cout << endl; | |
Property *listings = get_property(argv[2]); | |
cout << endl; | |
for(int i=0; i < Property::p_size; i++) | |
{ | |
listings[i].print_property(); | |
} | |
cout << endl; | |
Buyer *contacts = get_buyer(argv[3]); | |
cout << endl; | |
for(int i=0; i < Buyer::b_size; i++) | |
{ | |
contacts[i].print_buyer(); | |
} | |
cout << endl; | |
while(!Quit){ | |
switch(menu()){ | |
case 1: | |
{ | |
cout << " Add a new inspection" << endl; | |
firstbook->addNewBooking(list,listings,contacts); | |
firstbook->printbooking(); | |
} | |
break; | |
case 2: | |
cout << " go to search inspection" << endl; | |
break; | |
case 0: | |
Quit = true; | |
break; | |
default: | |
cout << "Invalid command!\n" << endl; | |
} | |
} | |
delete[] list; | |
delete[] listings; | |
delete[] contacts; | |
return 0; | |
} | |
int menu(){ | |
int Cmd; | |
cout << " 1. Book a new Inspection. "<< endl; | |
cout << " 2. search Inspection Bookings. "<< endl; | |
cout << " Input choice(0-quit)" << endl; | |
cout << "Command > "; | |
cin >> Cmd; | |
return Cmd; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment