//(Qt已鸽)
//shelf.h
#ifndef SHELF_H
#define SHELF_H
#include <string>
#include <vector>
using namespace std;
class shelf
{
public:
shelf();
virtual ~shelf();
void clear_this();
void setter();
void f_setter();
long long phone_pointer();
int time_pointer();
bool check_used();
int company_iter();
int packnum_iter();
protected:
private:
int package_num, company_identifier, time_chk, r_postal_code, s_postal_code;
string receiver, r_address, sender, s_address;
long long r_phone, s_phone;
bool checker;
};
#endif // SHELF_H
//shelf.cpp
#include "shelf.h"
#include "iostream"
#include "vector"
#include "fstream"
using namespace std;
shelf::shelf()
{
shelf::checker = 0;
}
ofstream out("atarashi.txt",ios::app);
ifstream in("atarashi.txt");
shelf::~shelf()
{
//guess what i am thinking?
}
void shelf::clear_this()
{
shelf::checker = 0;
//cout << "cleared successfully!" << endl;
}
void shelf::setter()
{
cout << "package number is?" << endl;
cin >> shelf::package_num;
out<<shelf::package_num;out<<" ";
cout << "which company?" << endl;
cin >> shelf::company_identifier;
out<<shelf::company_identifier;out<<" ";
cout << "receiver?" << endl;
cin >> shelf::receiver;
out<<shelf::receiver;out<<" ";
cout << "his/her phone number?" << endl;
cin >> shelf::r_phone;
out<<shelf::r_phone;out<<" ";
cout << "his/her address?" << endl;
cin >> shelf::r_address;
out<<shelf::r_address;out<<" ";
cout << "receiver's postal code?" << endl;
cin >> shelf::r_postal_code;
out<<shelf::r_postal_code;out<<" ";
cout << "sender?" << endl;
cin >> shelf::sender;
out<<shelf::sender;out<<" ";
cout << "his/her address?" << endl;
cin >> shelf::s_address;
out<<shelf::s_address;out<<" ";
cout << "his/her postal code?" << endl;
cin >> shelf::s_postal_code;
out<<shelf::s_postal_code;out<<" ";
cout << "his/her phone number?" << endl;
cin >> shelf::s_phone;
out<<shelf::s_phone;
cout << "set successfully!" << endl; //
out<<endl;
shelf::checker=1;
}
bool shelf::check_used()
{
if(checker)
return true;
else
return false;
}
long long shelf::phone_pointer()
{
return shelf::r_phone;
}
int shelf::company_iter()
{
return company_identifier;
}
int shelf::packnum_iter()
{
return package_num;
}
//main.cpp
#include <bits/stdc++.h>
#include "shelf.h"
using namespace std;
typedef long long ll;
int day_count[99][12][31];
int myear, mmonth, mday;
void my_time_setter()
{
cout << "year" << endl;
cin >> myear;
cout << "month" << endl;
cin >> mmonth;
cout << "date" << endl;
cin >> mday;
day_count[myear - 2000][mmonth][mday]++;
}
int main()
{
ios::sync_with_stdio(0);
shelf Syst1[1001];
ofstream out("atarashi.txt", ios::app);
ifstream ita("atarashi.txt");
int company_counter[1000];
string company_names[1000];
memset(day_count, 0, sizeof day_count);
int flag, flag1, flag2, flag3, flag4;
int overall_sum, overall_receive, overall_deliver;
int package_num;
ll phone_number;
typedef pair <int, ll> P;
map <int, ll>p_nums;
map <int, int> p_rem;
overall_sum = 0;
overall_deliver = 0;
overall_receive = 0;
bool for_checker = 1;
//int req_year, req_month, req_day, req_hour, req_minute;
//int til_year, til_month, til_day, til_hour, til_minute;
ll req_sum, til_sum;
//int m_receive[31], m_deliver[31], m_corp_receive[31], m_corp_deliver[31];
flag1 = 0;
while(1)
{
cout << "admin enter 1 to start" << endl;
cout << "guest enter 2 to start" << endl;
cout << "0 to exit" << endl;
cin >> flag;
if(flag == 1)
{
while(!flag1)
{
cout << "pleAse lOg in fiRst!enter the password" << endl;
string s1, s2, s3, s4;
s1 = "7355608";
s2 = "114514";
s3 = "1919810";
cin >> s4;
if(s4 == s1 || s4 == s2 || s4 == s3)
{
flag1 = 1;
break;
}
cout << "Password Error!" << endl;
}
cout << "1 to enter in information" << endl;
cout << "2 to deliver" << endl;
cout << "3 to check the situation or delete(with the package number)" << endl;
cout << "4 to get the overall amount / received / not received" << endl;
cout << "5 to check according date/company" << endl;
cout << "0 to exit" << endl;
cin >> flag2;
if(flag2 == 0)break;
if(flag2 == 1)
{
for(int i = 1; i <= 1001; i++)
{
if(!Syst1[i].check_used())
{
out << i;
out << endl;
Syst1[i].setter();
cout << "the number is " << i << endl;
cout << "please enter the current time!" << endl;
my_time_setter();
p_rem[Syst1[i].packnum_iter()] = i;
ll phone_num;
phone_num = Syst1[i].phone_pointer();
p_nums[i] = phone_num;
overall_sum++;
company_counter[Syst1[i].company_iter()]++;
break;
}
}
}
if(flag2 == 2)
{
cout << "1 to deliver with phone number" << endl;
cout << "2 to deliver with package number" << endl;
cin >> flag3;
if(flag3 == 1)
{
cout << "key in the phone number" << endl;
cin >> phone_number;
for_checker = 1;
for(int i = 1; i <= 1001; i++)
{
if(p_nums[i] == phone_number)
{
cout << "No." << Syst1[i].packnum_iter() << " package delivered successfully" << endl;
p_nums.erase(i);
p_rem.erase(i);
Syst1[i].clear_this();
overall_receive++;
for_checker = 0;
}
}
if(for_checker == 1)cout << "Not Found" << endl;
}
if(flag3 == 2)
{
cout << "key in the package number" << endl;
cin >> package_num;
if(Syst1[p_rem[package_num]].check_used())
{
p_nums.erase(p_rem[package_num]);
cout << "No." << package_num << " delivered successfully" << endl;
Syst1[p_rem[package_num]].clear_this();
overall_receive++;
}
else cout << "it has been received!" << endl;
}
}
if(flag2 == 3)
{
cout << "key in the number you want to check" << endl;
cin >> package_num;
if(Syst1[p_rem[package_num]].check_used())
{
cout << "not received yet" << endl;
int flag23a;
cout << "if to clear ,enter 1" << endl;
cout << "else 0" << endl;
cin >> flag23a;
if(flag23a)Syst1[p_rem[package_num]].clear_this();
}
else
{
cout << "received / not on shelf" << endl;
}
}
if(flag2 == 4)
{
cout << "received packages:" << overall_sum << endl;
cout << "delivered packages:" << overall_receive << endl;
cout << "delivered packages:" << overall_sum - overall_receive << endl;
}
if(flag2 == 5)
{
cout << "key in 1 to check amount of packages not received (by companies) / 2 to check by date/0 to exit" << endl;
cin >> flag4;
while(flag4)
{
if(flag4 == 1)
{
int cmpn;
cout << "key in company number" << endl;
cin >> cmpn;
cout << company_counter[cmpn] << endl;
}
if(flag4 == 2)
{
int s_yyyy, s_mm, s_dd, e_yyyy, e_mm, e_dd;
cout << "key in the start year?" << endl;
cin >> s_yyyy;
cout << "key in the start month?" << endl;
cin >> s_mm;
cout << "key in the start day?" << endl;
cin >> s_dd;
cout << "key in the due year?" << endl;
cin >> e_yyyy;
cout << "key in the due month?" << endl;
cin >> e_mm;
cout << "key in the due day?" << endl;
cin >> e_dd;
int flag4sum = 0;
for(int i = s_yyyy; i <= e_yyyy; i++)
{
for(int j = s_mm; j <= e_mm; j++)
{
for(int k = s_dd; k <= e_dd; k++)flag4sum += day_count[-2000 + i][j][k];
}
}
cout << flag4sum << endl;
}
cout << "key in 1 to check amount of packages not received (by companies) / 2 to check by date/0 to exit" << endl;
cin >> flag4;
}
}
}
else if(flag == 2)
{
cout << "key in your phone number" << endl;
int cnt = 0;
cin>>phone_number;
for(int i = 1; i <= 1001; i++)
{
if(p_nums[i] == phone_number)
{
cout << "package NO." << i << " not received" << endl;
cnt++;
}
}
if(!cnt)
cout << "your packages have all been delivered!" << endl;
}
else break;
}
}
困
debug有感:调整逻辑顺序时千万小心