CPP改写的联系人
来源:互联网 发布:乐乎记录生活 编辑:程序博客网 时间:2024/05/16 09:59
#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;
class date
{
private:
int year;
int month;
int day;
public:
void input();
void output();
#ifdef FAKE
void fake();
#endif
};
void date::input()
{
cout << "DATE [YYYY]: ";
cin >> year;
cout << "DATE [MM]: ";
cin >> month;
cout << "DATE [DD]: ";
cin >> day;
}
void date::output()
{
cout << setw(4) << setfill('0') << year << '-';
cout << setw(2) << setfill('0') << month << '-';
cout << setw(2) << setfill('0') << day << endl;
}
#ifdef FAKE
void date::fake()
{
int d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
year = rand() % 111 + 1900;
month = rand() % 12 + 1;
d[1] += ((year % 100 != 0) && (year % 4 == 0) || (year % 400 == 0));
day = rand() % d[month - 1] + 1;
}
#endif
struct contact
{
private:
string name;
string phone;
string mail;
date birthday;
#ifdef FAKE
static void fake_name(string &);
static void fake_phone(string &);
static void fake_mail(string &);
#endif
public:
#ifdef FAKE
void fake();
void input();
void output();
#endif
};
#ifdef FAKE
void contact::fake_name(string & name)
{
char buf[0x20];
int i, r;
r = rand() % 5 + 8;
for(i = 0; i < r; i++)
{
buf[i] = 'a' + rand() % 26;
}
buf[i] = 0;
name.append(buf);
}
void contact::fake_phone(string & phone)
{
char buf[0x20];
int s[30] = {130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189};
snprintf(buf, 0x20, "%3d%08d", s[rand() % 30], rand() % 100000000);
phone.append(buf);
}
void contact::fake_mail(string & mail)
{
int r;
string s[10] = {"@live.com", "@hotmail.com", "@msn.com", "@163.com", "@126.com", "@sina.com", "@qq.com", "@263.com", "@gmail.com", "@outlook.com"};
r = rand() % 10;
fake_name(mail);
mail.append(s[r]);
}
void contact::fake()
{
fake_name(name);
fake_phone(phone);
fake_mail(mail);
birthday.fake();
}
#endif
void contact::input()
{
}
void contact::output()
{
cout << setw(16) << setfill(' ') << left << name << ' ';
cout << setw(16) << setfill(' ') << left << phone << ' ';
cout << setw(16) << setfill(' ') << left << mail << ' ';
birthday.output();
cout << endl;
}
class array
{
public:
contact data[0x100];
int length;
int selected;
public:
array();
void add(const contact &);
void erase();
void list();
void select(int);
};
array::array()
{
length = 0;
selected = -1;
}
void array::add(const contact & c)
{
data[length] = c;
length++;
}
void array::erase()
{
for(int i = selected; i < length - 1; i++)
{
data[i] = data[i + 1];
}
length--;
}
void array::list()
{
for(int i = 0; i < length; i++)
{
cout << "[" << (i == selected ? '*' : ' ') << i << "] ";
data[i].output();
}
}
void array::select(int index)
{
selected = index;
}
int main()
{
#ifdef FAKE
srand(time(NULL));
#endif
string cmd;
array a;
while(true)
{
cout << "> ";
cin >> cmd;
if(cmd == "exit")
{
return 0;
}
else if(cmd == "add")
{
}
else if(cmd == "list")
{
a.list();
}
else if(cmd == "select")
{
int index;
cin >> index;
a.select(index);
}
else if(cmd == "delete")
{
a.erase();
}
#ifdef FAKE
else if(cmd == "fake")
{
int n;
cin >> n;
for(int i = a.length; i < a.length + n; i++)
{
a.data[i].fake();
}
a.length += n;
}
#endif
}
return 0;
}
#include <iomanip>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;
class date
{
private:
int year;
int month;
int day;
public:
void input();
void output();
#ifdef FAKE
void fake();
#endif
};
void date::input()
{
cout << "DATE [YYYY]: ";
cin >> year;
cout << "DATE [MM]: ";
cin >> month;
cout << "DATE [DD]: ";
cin >> day;
}
void date::output()
{
cout << setw(4) << setfill('0') << year << '-';
cout << setw(2) << setfill('0') << month << '-';
cout << setw(2) << setfill('0') << day << endl;
}
#ifdef FAKE
void date::fake()
{
int d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
year = rand() % 111 + 1900;
month = rand() % 12 + 1;
d[1] += ((year % 100 != 0) && (year % 4 == 0) || (year % 400 == 0));
day = rand() % d[month - 1] + 1;
}
#endif
struct contact
{
private:
string name;
string phone;
string mail;
date birthday;
#ifdef FAKE
static void fake_name(string &);
static void fake_phone(string &);
static void fake_mail(string &);
#endif
public:
#ifdef FAKE
void fake();
void input();
void output();
#endif
};
#ifdef FAKE
void contact::fake_name(string & name)
{
char buf[0x20];
int i, r;
r = rand() % 5 + 8;
for(i = 0; i < r; i++)
{
buf[i] = 'a' + rand() % 26;
}
buf[i] = 0;
name.append(buf);
}
void contact::fake_phone(string & phone)
{
char buf[0x20];
int s[30] = {130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189};
snprintf(buf, 0x20, "%3d%08d", s[rand() % 30], rand() % 100000000);
phone.append(buf);
}
void contact::fake_mail(string & mail)
{
int r;
string s[10] = {"@live.com", "@hotmail.com", "@msn.com", "@163.com", "@126.com", "@sina.com", "@qq.com", "@263.com", "@gmail.com", "@outlook.com"};
r = rand() % 10;
fake_name(mail);
mail.append(s[r]);
}
void contact::fake()
{
fake_name(name);
fake_phone(phone);
fake_mail(mail);
birthday.fake();
}
#endif
void contact::input()
{
}
void contact::output()
{
cout << setw(16) << setfill(' ') << left << name << ' ';
cout << setw(16) << setfill(' ') << left << phone << ' ';
cout << setw(16) << setfill(' ') << left << mail << ' ';
birthday.output();
cout << endl;
}
class array
{
public:
contact data[0x100];
int length;
int selected;
public:
array();
void add(const contact &);
void erase();
void list();
void select(int);
};
array::array()
{
length = 0;
selected = -1;
}
void array::add(const contact & c)
{
data[length] = c;
length++;
}
void array::erase()
{
for(int i = selected; i < length - 1; i++)
{
data[i] = data[i + 1];
}
length--;
}
void array::list()
{
for(int i = 0; i < length; i++)
{
cout << "[" << (i == selected ? '*' : ' ') << i << "] ";
data[i].output();
}
}
void array::select(int index)
{
selected = index;
}
int main()
{
#ifdef FAKE
srand(time(NULL));
#endif
string cmd;
array a;
while(true)
{
cout << "> ";
cin >> cmd;
if(cmd == "exit")
{
return 0;
}
else if(cmd == "add")
{
}
else if(cmd == "list")
{
a.list();
}
else if(cmd == "select")
{
int index;
cin >> index;
a.select(index);
}
else if(cmd == "delete")
{
a.erase();
}
#ifdef FAKE
else if(cmd == "fake")
{
int n;
cin >> n;
for(int i = a.length; i < a.length + n; i++)
{
a.data[i].fake();
}
a.length += n;
}
#endif
}
return 0;
}
- CPP改写的联系人
- caffe 中classification.cpp的源码详解、改写
- 改写caffe classification.cpp使其支持批量读取图片
- 测试程序的改写
- 不能改写的R~
- 烦人的改写模式
- 改写TCPMP的界面
- 程序的自动改写
- 改写TCPMP的界面
- 改写Android的header
- 程序的自我改写
- 程序的自我改写
- 触摸屏驱动的改写
- GLOG的改写
- 改写spring的例子petclinic
- 改写Hibernate提供的uuid
- 没被改写的人生
- dshow中playwnd的改写
- 我的大学六年(单片机大师郭天祥原创)
- java base64
- poj 2253 Frogger 1797 Heavy Transportation
- :first选择器(jQuery)
- 数据结构的求长操作
- CPP改写的联系人
- Linux进程间通信方式
- Power BI中的QA功能预览
- lr学习笔记3:运行场景时遇到的问题及解决
- UVa 138 Street Numbers(数论&Pell方程)
- AIX常用命令略记
- WebShpere MQ 网络通信编程总结
- MOV EDI,EDI指令的解释(整理)
- myeclipse6.5的自动提示只有4个字符怎么解决