ssd5 网络拍卖 实验一
编辑器加载中...
Advertisement.h
View Code
#ifndef ADVERTISEMENT_H
#define ADVERTISEMENT_H
#include <queue>
#include <iostream>
#include <string>
#include "Date.h"
using namespace std;
class Advertisement;
istream &operator>>(istream &stream, Advertisement &a);
class Advertisement {
private:
int number;
int quantity;
string title;
string seller_email;
string body;
Date start;
Date close;
public:
Advertisement(void);
Advertisement(const Advertisement &a);
Advertisement (string title, string seller_email, string body,
Date start, Date close, int quantity);
virtual void setStart (const Date &start);
virtual void setClose (const Date &close);
virtual void setTitle (string title);
virtual void setBody (string body);
virtual void setNumber (int number);
virtual void setEmail (string email);
virtual void setQuantity (int quantity);
virtual Date getStart () const;
virtual Date getClose () const;
virtual string getTitle() const;
virtual string getBody() const;
virtual string getEmail() const;
virtual int getNumber () const;
virtual int getQuantity() const;
virtual bool operator==(const Advertisement&) const;
};
#endif
Advertisement.cpp
View Code
#include <iostream>
#include "Advertisement.h"
using namespace std;
Advertisement::Advertisement()
{
this->number = 0;
this->quantity=0;
this->seller_email=this->title=this->body="";
}
Advertisement::Advertisement(const Advertisement &a)
{
this->number = a.getNumber();
this->quantity=a.getQuantity();
this->title = a.getTitle();
this->seller_email=a.getEmail();
this->body=a.getBody();
this->start=a.getStart();
this->close=a.getClose();
}
Advertisement::Advertisement(std::string title, std::string seller_email, std::string body, Date start, Date close, int quantity)
{
this->quantity=quantity;
this->title = title;
this->seller_email=seller_email;
this->body=body;
this->start=start;
this->close=close;
}
void Advertisement::setStart(const Date &start)
{
this->start = start;
}
void Advertisement::setClose(const Date &close)
{
this->close = close;
}
void Advertisement::setBody(std::string body)
{
this->body = body;
}
void Advertisement::setEmail(std::string email)
{
this->seller_email = email;
}
void Advertisement::setNumber(int number)
{
this->number = number;
}
void Advertisement::setQuantity(int quantity)
{
this->quantity = quantity;
}
void Advertisement::setTitle(std::string title)
{
this->title = title;
}
string Advertisement::getBody() const
{
return this->body;
}
string Advertisement::getEmail() const
{
return this->seller_email;
}
string Advertisement::getTitle() const
{
return this->title;
}
Date Advertisement::getStart() const
{
return this->start;
}
Date Advertisement::getClose() const
{
return this->close;
}
int Advertisement::getNumber()const
{
return this->number;
}
int Advertisement::getQuantity()const
{
return this->quantity;
}
bool Advertisement::operator==(const Advertisement& a)const
{
if(this->number==a.getNumber())
return true;
else return false;
}
istream &operator>>(istream &stream, Advertisement &a)
{
string title,email,body;
int quantity;
Date start,close;
stream>>title>>email>>quantity>>start>>close>>body;
a.setTitle(title);
a.setBody(body);
a.setEmail(email);
a.setStart(start);
a.setClose(close);
a.setQuantity(quantity);
return stream;
}
Client.h
View Code
#ifndef CLIENT_H
#define CLIENT_H
#include <string>
#include <vector>
#include "Date.h"
using namespace std;
class Client;
istream &operator>>(istream &stream, Client &c);
class Client {
private:
string fname;
string lname;
string email;
string passwd;
public:
Client(void);
Client(Client const &c);
Client (string &fname, string &lname, string &email, string &passwd);
virtual void setFname(const string&);
virtual void setLname(const string&);
virtual void setEmail(const string&);
virtual void setPasswd(const string&);
virtual string getFname () const;
virtual string getLname () const;
virtual string getEmail () const;
virtual string getPasswd () const;
virtual bool verifyPasswd(string passwd);
};
#endif
Client.cpp
View Code
#include <iostream>
#include <string.h>
#include "Client.h"
using namespace std;
Client::Client()
{
this->fname = "";
this->email = "";
this->lname = "";
this->passwd= "";
}
Client::Client(const Client &c)
{
this->fname = c.getFname();
this->lname = c.getLname();
this->email = c.getEmail();
this->passwd = c.getPasswd();
}
Client::Client(std::string &fname, std::string &lname, std::string &email, std::string &passwd)
{
this->fname = fname;
this->lname = lname;
this->email = email;
this->passwd = passwd;
}
void Client::setEmail(const std::string &email)
{
this->email = email;
}
void Client::setFname(const std::string &fname)
{
this->fname = fname;
}
void Client::setPasswd(const std::string &passwd)
{
this->passwd = passwd;
}
void Client::setLname(const std::string &lname)
{
this->lname = lname;
}
string Client::getFname() const
{
return this->fname;
}
string Client::getLname() const
{
return this->lname;
}
string Client::getEmail() const
{
return this->email;
}
string Client::getPasswd() const
{
return this->passwd;
}
bool Client::verifyPasswd(std::string passwd)
{
if(this->passwd == passwd)return true;
else return false;
}
istream &operator>>(istream &stream, Client &c)
{
string fname,lname,email,passwd;
stream>>fname>>lname>>email>>passwd;
c.setFname(fname);
c.setLname(lname);
c.setEmail(email);
c.setPasswd(passwd);
return stream;
}
Date.h
View Code
#ifndef DATE_H
#define DATE_H
#include <iostream>
using namespace std;
class Date;
ostream &operator<<(ostream&, const Date&);
istream &operator>>(istream&, Date&);
class Date {
private:
int month;
int day;
int year;
int hour;
int minute;
int second;
public:
Date(void);
Date (int month, int day, int year, int hour, int minute, int second);
virtual void setMonth(int&);
virtual void setDay(int&);
virtual void setYear(int&);
virtual void setHour(int&);
virtual void setMinute(int&);
virtual void setSecond(int&);
virtual int getMonth(void) const;
virtual int getDay(void) const;
virtual int getYear(void) const;
virtual int getHour(void) const;
virtual int getMinute(void) const;
virtual int getSecond(void) const;
virtual bool operator== (const Date &rhs);
virtual bool operator< (const Date &left);
virtual void operator=(const Date &date);
};
#endif
Date.cpp
View Code
#include <iostream>
#include <string>
#include "Date.h"
using namespace std;
Date::Date()
{
this->day = 0;
this->month=0;
this->year = 0;
this->minute = 0;
this->hour = 0;
this->second =0;
}
Date::Date(int month,int day,int year,int hour,int minute,int second)
{
this->month = month;
this->day = day;
this->year = year;
this->hour = hour;
this->minute = minute;
this->second = second;
}
void Date::setMonth(int &month)
{
this->month = month;
}
void Date::setDay(int &day)
{
this->day = day;
}
void Date::setYear(int &year)
{
this->year = year;
}
void Date::setMinute(int &minute)
{
this->minute = minute;
}
void Date::setSecond(int &second)
{
this->second = second;
}
void Date::setHour(int &hour)
{
this->hour = hour;
}
int Date::getDay() const
{
return this->day;
}
int Date::getHour() const
{
return this->hour;
}
int Date::getMinute() const
{
return this->minute;
}
int Date::getYear() const
{
return this->year;
}
int Date::getSecond() const
{
return this->second;
}
int Date::getMonth() const
{
return this->month;
}
bool Date::operator==(const Date &rhs)
{
return (this->day==rhs.day)&&(this->year==rhs.year)&&(this->month==rhs.month)&&(this->hour==rhs.hour)&&
(this->minute == rhs.minute)&&(this->second == rhs.second);
}
bool Date::operator <(const Date &rhs)
{
if(this->year>rhs.year)return false;
else if(this->year<rhs.year)return true;
else if(this->month>rhs.month)return false;
else if(this->month<rhs.month)return true;
else if(this->day>rhs.day)return false;
else if(this->day<rhs.day)return true;
else if(this->hour>rhs.hour)return false;
else if(this->hour<rhs.hour)return true;
else if(this->minute>rhs.minute)return false;
else if(this->minute<rhs.minute)return true;
else if(this->second>rhs.second)return false;
else if(this->second<rhs.second)return true;
else return false;
}
ostream &operator<<(ostream& os,const Date& date)
{
return os<<date.getMonth()<<"/"<<date.getDay()<<"/"<<date.getYear()<<" "
<<date.getHour()<<":"<<date.getMinute()<<":"<<date.getSecond()<<" "<<endl;
}
istream &operator>>(istream& is, Date& date)
{
string s;
is>>s;
int year=0,month=0,day=0,hour=0,second=0,minute=0,i;
int len = s.length(),k=0;
for(i = 0; i<len ; i++)
{
if(s[i]=='/')
k++;
else
{
if(k==0)
month =month*10+s[i]-'0';
else if(k==1)
day =day*10+s[i]-'0';
else if(k==2)
year =year*10+s[i]-'0';
}
}
is>>s;
len = s.length();
k = 0;
for(i = 0; i<len ; i++)
{
if(s[i]==':')
k++;
else
{
if(k==0)hour =hour*10+s[i]-'0';
else if(k==1)minute =minute*10+s[i]-'0';
else if(k==2)second =second*10+s[i]-'0';
}
}
date.setYear(year);
date.setMonth(month);
date.setDay(day);
date.setHour(hour);
date.setMinute(minute);
date.setSecond(second);
return is;
}
void Date::operator= (const Date& date)
{
this->year = date.getYear();
this->month = date.getMonth();
this->day = date.getDay();
this->hour = date.getHour();
this->minute = date.getMinute();
this->second = date.getSecond();
}
posted on 2011-08-30 20:56 NewPanderKing 阅读(401) 评论(0) 编辑 收藏 举报