📄 d_13_2.cpp
字号:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include "List.h" // 链表头文件
using namespace std;
class Person {
private:
string name,phone,address;
public:
Person()
{
string n,p,a;
cout << "请输入姓名、电话和地址:";
cin >> n >> p >> a;
name = n;
phone = p;
address = a;
}
string gName()
{ return name; }
void dispMeaage()
{ cout << setw(10)<<left << name<< setw(10)<<left << phone<< setw(10)<<left << address<<endl;
}
};
class note {
private:
List <Person> noteList;
public:
void noteDisp()
{ cout << setw(10)<<left << "姓名"<< setw(10)<<left << "电话" << setw(10)<<left << "地址" <<endl;
noteList.reset(0);
for (int i=0;i<noteList.size;++i)
{ (noteList.data()).dispMeaage();
noteList.next();
}
}
void noteDelete()
{ string n;
cout << "请输入要删除的姓名:";
cin >> n;
noteList.reset(0);
for (int i=0;i<noteList.size;++i)
{ if ((noteList.data()).gName()==n)
{ noteList.deleteNode();
break;
}
noteList.next();
}
}
void noteSearch()
{ string n;
cout << "请输入要查询的姓名:";
cin >> n;
noteList.reset(0);
for (int i=0;i<noteList.size;++i)
{ if ((noteList.data()).gName()==n)
{ (noteList.data()).dispMeaage();
break;
}
noteList.next();
}
}
void noteInsert(Person p)
{ noteList.insert(p);
}
};
void main()
{
note myNote;
Person p1,p2,p3;
myNote.noteInsert(p1);
myNote.noteInsert(p2);
myNote.noteInsert(p3);
myNote.noteDisp();
myNote.noteSearch();
myNote.noteDelete();
myNote.noteDisp();
cin.get();cin.get(); //等待结束,以便调测程序,可以删除
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -