c++で書かれた通信録(2.0)

11686 ワード

/*
         c++       
150        300 , 。。。
           
            
       ,       ,         
   map,    vector,       ,  map ,
             。          
     Group ,adresslist  Menu ,             
      :
1.        
2.               
3.     ,       ,      
4.    
*/
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

void Error(){
    cout << "
, " << endl; } void Checkerror(string &s,int maxn){ while(1){ cin >> s; if(s.length() > 1 || s[0] < '0' || s[0] - '0' > maxn) Error(); else return; } } class Group{ private: string name;// vector <string> v;// public: void assign(string s){// v.clear(); name = s; } void push(string s){// v.push_back(s); } void showname(){// cout << name << endl; } string getname(){ return name; } void print(){// if(v.size() == 0){ cout << "None" << endl; return; } for(int i = 0;i < v.size();i++) cout << i << ". " << v[i] << endl; } void clear(){// v.clear(); } void cut(string s){// for(int i = 0;i < v.size();i++) if(v[i] == s) v.erase(v.begin()+i); } }; class Contact_person{ private: char First;// string name,tel,remark,group;//remark ,grouop public: Contact_person(){group = "None";}//group void assign(string n,string t,string r){// First = n[0]; name = n; tel = t; remark = r; } void divide_into_group(string s){// group group = s; } string getname(){// name return name; } void showname(){// cout << name << endl; } void print(){// cout << "Name :" << name << endl; cout << "Tel :" << tel << endl; cout << "Remark:" << remark << endl; cout << "Group :" << group << endl; } }; class Adresslist{ private: vector <Group> vgroup; vector <Contact_person> vperson; public: void print_groupname(){// if(vgroup.size() == 0){ cout << " !" << endl; return; } cout << "
:" << endl; for(int i = 0;i < vgroup.size();i++){ printf("%d. ",i); vgroup[i].showname(); } } void print_personname(){// if(vperson.size() == 0){ cout << " !" << endl; return; } cout << "
:" << endl; for(int i = 0;i < vperson.size();i++){ printf("%d. ",i); vperson[i].showname(); } } void divide_into_group(Contact_person &c){// if(!vgroup.size()){ cout << "
, " << endl; return; } string s; while(1){ print_groupname(); cout << "
( ):"; cin >> s; if(s.length() > 1 || s[0] < '0' || s[0] - '0' >= vgroup.size()) Error(); else break; } int p = s[0] - '0'; s = vgroup[p].getname(); c.divide_into_group(s); vgroup[p].push(c.getname()); cout << "
!" << endl; } void buildperson(){// string name,tel,remark; Contact_person p; cout << "
:"; cin >> name; cout << "
:"; cin >> tel; cout << "
:"; cin >> remark; p.assign(name,tel,remark); while(1){ cout << "
(YES / NO)? "; string s; cin >> s; if(s == "YES"){ divide_into_group(p); break; } if(s == "NO"){ break; } Error(); } vperson.push_back(p); cout << "
!" << endl; } void buildgroup(){// string name; cout << "
:"; cin >> name; Group group; group.assign(name); vgroup.push_back(group); cout << "
!" << endl; } void managegroup(){//group string s; Checkerror(s,3); switch(s[0]){ case '0': cout << " !" << endl; return; case '1': buildgroup(); break; case '2': if(vgroup.size() == 0){ cout << " !" << endl; return; } for(int i = 0;i < vgroup.size();i++){ cout << " : "; vgroup[i].showname(); vgroup[i].print(); cout << endl; } break; case '3': vgroup.clear(); break; } } void managesearch(int t){//search string s; Checkerror(s,1); if(s[0] == '0'){ cout << " !" << endl; return; } if(s[0] == '1'){ vperson.erase(vperson.begin()+t); cout << "
!" << endl; } } void clear(){// vperson.clear(); for(int i = 0;i < vgroup.size();i++) vgroup[i].clear(); cout << "
!" << endl; } int search(){// cout << "
:"; string s; cin >> s; for(int i = 0;i < vperson.size();i++) if(vperson[i].getname() == s){ cout << "
!" << endl; vperson[i].print(); return i; } cout << " , !" << endl; return -1; } }; class Menu{ public: void primary(){// cout << endl << endl; cout << "1 . " << endl; cout << "2 . " << endl; cout << "3 . " << endl; cout << "4 . " << endl; cout << "5 . " << endl; cout << "0 . " << endl ; cout << "
:"; } void group(){// cout << endl << endl; cout << "1 . " << endl; cout << "2 . " << endl; cout << "3 . " << endl; cout << "0 . " << endl; cout << "
:"; } void search(){// cout << endl << endl; cout << "1. " << endl; cout << "0. " << endl; cout << "
:"; } }; void System(){ Menu menu; Adresslist adresslist; while(1){ string s; while(1){ menu.primary(); cin >> s; if(s.length() > 1 || s[0] < '0' || s[0] > '5') Error(); else break; } switch(s[0]){ case '0': cout << " !" << endl; return; case '1': adresslist.buildperson(); break; case '2': adresslist.print_personname(); break; case '3': menu.group(); adresslist.managegroup(); break; case '4': adresslist.clear(); break; case '5': int t = adresslist.search(); if(t != -1){ menu.search(); adresslist.managesearch(t); } break; } } } int main(){ cout << " !" << endl; System(); return 0; }