陈桥驿站 陈桥驿站

C++课程设计:街道办事处信息系统

课程设计 C/C++ 阅读 ( 332 ) 陈桥驿站

简介

街道办事处信息系统。用类定义人员基本信息(姓名、年龄、职业、所在居委会、邮编、电话等),从用户界面中输入某一信息能显示所有符合条件的人员详细信息。并能正确地实现信息的编辑(增、删、改)。[CppPersonHamlet.zip]

<video src="../../../media/CppPersonHamlet.mp4"></video>

源码

#include <iostream>
#include <string>

using namespace std;

int all = 5; //系统中社区居民总人数

class Person{
public:
    Person(){
        
    };
    //基本属性
    int id; //编号
    string name; //姓名
    int age; //年龄
    string job; //职业
    string hamlet; //居委会
    string mail; //邮编
    string phone; //电话
    /*
    Person(int id, string name, string job, int age, string hamlet, string mail, string phone){
        //普通的构造方法
        this->id = id;
        this->name = name;
        this->age = age;
        this->job = job;
        this->hamlet = hamlet;
        this->mail = mail;
        this->phone = phone;
    }
     */
    Person(int id, string name, int age, string job, string hamlet, string mail, string phone):id(id), name(name), age(age), job(job), hamlet(hamlet), mail(mail), phone(phone){
        //拷贝构造函数
    }
    void print(){
        cout<< id << "\t" << name <<"\t" << age << "\t" << job << "\t" << hamlet << "\t" << mail << "\t" << phone << endl;
    }
};

int menu(){
    //主菜单
    int order;
    cout << "欢迎使用社区街道办事处信息系统" << endl;
    cout << "1.根据关键字查询" << endl;
    cout << "2.增加人员的信息" << endl;
    cout << "3.删除人员的信息" << endl;
    cout << "4.修改人员的信息" << endl;
    cout << "5.所有人员的信息" << endl;
    cout << "6.退出系统" << endl;
    cout << "请输入编号:";
    cin >> order;
    return order;
}

//do something ... ...

int main(){
    //初始化几个社区居民
    Person persons[1024] = {
        Person(1, "毕福剑", 60, "无业游民", "陈家沟小区", "243333", "15552111111"),
        Person(2, "赵本山", 70, "小品演员", "唐岛湾小区", "255555", "17888899999"),
        Person(3, "崔永元", 40, "整范冰冰", "钱塘江花园", "277777", "17999987654"),
        Person(4, "李咏", 50, "不幸去世", "温州商贸城", "259988", "13666644444"),
        Person(5, "周立波", 50, "吸毒被抓", "奥森花园小区", "324456", "17862515555")
    };
    Person person;
    string key; //关键字
    int id; //编号
    int order; //输入的菜单编号
    do{
        order = menu();
        switch (order) {
            case 1:
                //查询功能
                cout << "请输入查询的职业:";
                cin >> key;
                search(persons, key);
                break;
                
            case 2:
                //增加人员信息
                cout << "请输入姓名 年龄 职业 所在居委会 邮编 电话:" << endl;
                cin >> person.name >> person.age >> person.job >> person.hamlet >> person.mail >> person.phone;
                insert(persons, person);
                break;
                
            case 3:
                //删除人员信息
                cout << "请输入删除人员的编号:";
                cin >> id;
                if(isOutOfArrayBound(id) == 1){
                    cout << "相关人员不存在啊,哥哥(⊙﹏⊙)b" << endl;
                }
                else{
                    remove(id, persons);
                }
                break;
                
            case 4:
                //修改人员信息
                cout << "请输入修改人员的编号:";
                cin >> id;
                if(isOutOfArrayBound(id) == 1){
                    cout << "相关人员不存在啊,哥哥(⊙﹏⊙)b" << endl;
                }
                else{
                    cout << "请输入姓名 年龄 职业 所在居委会 邮编 电话:" << endl;
                    cin >> person.name >> person.age >> person.job >> person.hamlet >> person.mail >> person.phone;
                    replace(id, persons, person);
                }
                break;
                
            case 5:
                //所有人员信息
                findAll(persons);
                break;
                
            case 6:
                //退出
                cout << "谢谢使用^_^" << endl;
                break;
            default:
                cout << "菜单序号输入错误(⊙﹏⊙)b" << endl;
                break;
        }
    }while(order != 6);
    return 0;
}

编译错误

Person[]错写成Person person

MacBookPro:~ www.tomcat7.cn$ g++ -c person.cpp
person.cpp:68:5: error: use of undeclared identifier 'persons'; did you mean
      'person'?
    persons[all] = person;
    ^~~~~~~
    person
person.cpp:65:19: note: 'person' declared here

缺少参数Person persons[]

int insert(Person person){
                  ^
person.cpp:68:12: error: type 'Person' does not provide a subscript operator
    persons[all] = person;
    ~~~~~~~^~~~

缺少参数类型Person

person.cpp:72:20: error: C++ requires a type specifier for all declarations
int remove(int id, persons[]){
                   ^
person.cpp:132:21: error: no matching function for call to 'remove'
                    remove(id, persons);
                    ^~~~~~
person.cpp:72:5: note: candidate function not viable: no known conversion from
      'Person [1024]' to 'int *' for 2nd argument
int remove(int id, persons[]){
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2131:1: note: 
      candidate function template not viable: requires 3 arguments, but 2 were
      provided
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
^
/usr/include/stdio.h:263:6: note: candidate function not viable: requires 1
      argument, but 2 were provided
int      remove(const char *);
         ^

id重复定义

person.cpp:139:21: error: redefinition of 'id'
                int id;
                    ^
person.cpp:127:21: note: previous definition is here
                int id;
                    ^
5 errors generated.
jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

本文基于《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
文章链接:http://www.cctv3.net/archives/CppPersonHamlet.html (转载时请注明本文出处及文章链接)

课程设计C/C++
发表新评论
陈桥驿站已萌萌哒运行
© 2020百度云提供云加速服务 阿里云提供域名解析和云计算服务 鲁ICP备18036467号-2
PREVIOUS NEXT
雷姆
拉姆