|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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] |
-
这是出现的问题
|