鱼C论坛

 找回密码
 立即注册
查看: 3269|回复: 14

求大神帮我改改这个程序,小弟实在弄不了了.

[复制链接]
发表于 2014-4-1 14:32:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 maverick 于 2014-4-1 14:40 编辑

#include "stdafx.h"
#include "iomanip"
#include "iostream"
#include<string>

using namespace std;

#define MAXSIZE 50

struct worker_a
{
long num;
char name[10];
char sex;
int age;
char title[10];
char position[10];
float wage;
};

class worker_b
{
    private:
                worker_a worker_struct[MAXSIZE];
                int total;
    public:
                worker_b();
                int insert_seq(int i, worker_a x);
                int delete_seq(int i);
                void print_seq();
};

void menu();

void change(worker_a x,worker_a y)
{
        x.age=y.age;
        x.num=y.num;
        x.sex=y.sex;
        x.wage=y.wage;
        strcpy_s(x.name,y.name);
        strcpy_s(x.position,y.position);
        strcpy_s(x.title,y.title);
}

int _tmain(int argc, _TCHAR* argv[])
{
        worker_b worker_object;
        int n;
        //bool m = true;
        /*
        while (m)
        {
        menu();
        */
        cin >> n;
        switch (n)
        {
        case 1:
        {
        int i;
        worker_a x;
        cout << "请输入插入的位置" << endl;
        cin >> i;
        cout << "请输入员工的编号,姓名,性别,年龄,职务,职称,岗位薪酬:" << endl;
        cin >> x.num >> x.name >> x.sex >> x.age>> x.title >> x.position >> x.wage;
        cout<<"$$$$$$$$$$$$$$$$$$$$$"<<endl;
        worker_object.insert_seq(i, x);
        cout << "插入后的情况:" << endl;
        worker_object.print_seq();
        break;
        }
        /*
        case 2:
        {
        int i;
        cout << "请输入删除位置" << endl;
        cin >> i;
        worker_object.delete_seq(i);
        cout << "删除后的情况:" << endl;
        worker_object.print_seq();
        break;
        }
        */
        case 0:
        //m = false;
                cout<<"煞笔!!!"<<endl;
                break;
        }
/*
}
*/
        return 0;
}

void menu()
{
cout << endl;
cout << "1.插入" << endl;
cout << "2.删除" << endl;
cout << "0.退出" << endl;
cout << endl;
cout << "请选择:" << endl;
}

worker_b::worker_b()
{
        total = 0;
}

int worker_b::insert_seq(int i, worker_a x)
{
        int j;
        if (total == MAXSIZE)
        {
                cout << "table is full" << endl;
                return -1;
        }
        if (i < 0 || i >(total))
        {
                cout << "place is wrong!" << endl;
                return 0;
        }
        for (j = total; j >= i; j--)
        {
               
                change(worker_struct[j+1],worker_struct[j]);
        }
        change(worker_struct[i],x);
        ++ total;
        return 1;
}

int worker_b::delete_seq(int i)
{
        int j;
        if (i <0 || i > total)
        {
        cout << "this element don't exist" << endl;
        return -1;
        }
        for (j = i; j <= total - 1; j++)
        {
        change(worker_struct[j - 1],worker_struct[j]);
        }
        --total;
        return 0;
}

void worker_b::print_seq()
{
        int i;
        cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
        for (i = 0; i <= total - 1; i++)
        {
        cout << worker_struct[i].num << setw(10) <<
        worker_struct[i].name << setw(10) <<
        worker_struct[i].sex << setw(10) <<
        worker_struct[i].age << setw(10) <<
        worker_struct[i].title << setw(10) <<
        worker_struct[i].position << setw(10) <<
        worker_struct.wage << setw(10) << endl;
        }
        cout << endl << endl;
}
[/i][/i][/i][/i][/i][/i][/i]

这是出现的问题

这是出现的问题
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2014-4-2 10:11:50 | 显示全部楼层

strcpy与strcpy_s有什么区别?   我原来用的是strcpy,后来编译器提醒我用strcpy会出错,我就根据提示换成strcpy_s.
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-2 10:12:33 | 显示全部楼层
天使之约 发表于 2014-4-1 15:35
看不出问题在哪,但是帮你顶高点,让高手帮忙看看

谢谢啦。。。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-2 11:02:28 | 显示全部楼层
woliubin 发表于 2014-4-2 09:52
#include "stdafx.h"
#include
#include

用strcpy好像也会出现出错,会出现Access Violation.
好像是调用strcpy时只有指针,未分配内存的缘故。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-4 02:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表