c++增删改查引发了异常: 读取访问权限冲突

CSDN问答 2021-12-30 05:47:23 阅读数:640

c++ 引发 增删 删改 发了
#pragma once#include<string>#include<iostream>using namespace std;class employee{public: employee(); virtual void pay(); virtual void display(); virtual void setemployee(); int getno(); void setno(); void setname(); string getname();public: int no; string name; double salary; };#pragma once#include<vector>#include "salesman.h"class management{public: void add(); void decrease(); void revise(); void search();private: int type=0; int l = 0, m = 0,n = 0; int sum1 = 0,sum2 = 0,sum3 = 0; employee em[1000]; manager ma[1000]; salesman sa[1000]; technique te[1000]; };#pragma once#include"technique.h"class manager : public employee{public: manager(); virtual void display(); virtual void setemployee();private: double monthpay;};#include"manager.h"class salesman : public employee{public: salesman(); //virtual void add(); virtual void display(); virtual void setemployee();private: double commrate=0, sales=0;};#pragma once#include"employee.h"class technique : public employee{public: technique(); // virtual void add(); virtual void setemployee(); virtual void display(); private: double hourlyrate; int workhours; };#include <iostream>#include"employee.h"using namespace std;employee::employee() { salary = 0; //no = 0;}void employee::pay() {}void employee::display() {}int employee::getno(){ return no;}void employee::setno(){ cout << "请输入员工编号:" << endl; cin >> no;}void employee::setname(){ cout << "请输入员工姓名" << endl; cin >> name;}string employee::getname(){ return name;}#include "management.h"#include"employee.h"#include<iostream>#include<string.h>using namespace std;void employee::setemployee(){}void management::add(){ cout << "输入本次想增添的员工数" << endl; int a; cin >> a; for (int i=1; i<=a; i++) { employee em; cout << "请输入本次想增添的第" << i << "个员工的信息" << endl; cout << "请选择身份:" << endl; cout << "1.经理 2.售货员 3.技术员" << endl; cin >> type; if (type == 1) { ma[l++].setemployee(); sum1++; } else if (type == 2) { sa[m++].setemployee(); sum2++; } else if (type == 3) { te[n++].setemployee(); sum3++; } } cout << "增加成功!" << endl; system("pause"); system("cls");}void management::decrease(){ int k; cout << "请输入你想删除的员工编号:" << endl; cin >> k; for (int i = 0; i < sum1; i++) { if (k == ma[i].getno()) { for (int j = i; j < sum1; j++) { ma[i]=ma[i+1]; } cout << "删除成功!\n"; } } for (int i = 0; i < sizeof(sa); i++) { if (k == sa[i].getno()) { for (int j = i; j < sizeof(sa); j++) { sa[i+1] = sa[i]; } cout << "删除成功!\n"; } } for (int i = 0; i < sizeof(te); i++) { if (k == te[i].getno()) { for (int j = i; j < sizeof(te); j++) { te[i] = te[i + 1]; } cout << "删除成功!\n"; } } cout << "无该人员信息!请确认ID是否正确\n"; }void management::revise(){ int k,m,i=0; string n; cout << "请输入要修改信息的员工编号" << endl; cin >> k; for (int i = 0; i < sizeof(ma); i++) { if (k == ma[i].getno()) { cout << "选择需要修改的信息 1.姓名 2.编号" << endl; cin >> m; switch (m) { case 1: //cin >> n; ma[i].setname(); ma[i].getname(); break; case 2: //ma[i].setno(stoi(n)); ma[i].setno(); ma[i].getno(); break; } cout << "修改成功"; } }}void management::search(){ int k,m; int i; cout << "请选择身份:" << endl; cout << "1.经理 2.售货员 3.技术员" << endl; cin >> m; cout << "请输入要查找的员工编号:" << endl; cin >> k; switch (k) { case(1): for (i = 0; i < sizeof(ma); i++) { if (k == ma[i].getno()) { ma[i].display(); } } case(2): for (i = 0; i < sizeof(sa); i++) { if (k == sa[i].getno()) { sa[i].display(); } } case(3): for (i = 0; i < sizeof(te); i++) { if (k ==te[i].getno()) { te[i].display(); } } } cout << "查找失败" << endl; }#include "manager.h"#include "employee.h"manager::manager() :employee(){ monthpay = 0;}void manager::setemployee(){ //cout << "请输入员工姓名" << endl; //cin >> name; //cout << "请输入员工编号" << endl; //cin >> no; setname(); setno(); cout << "月工资" << endl; cin>>monthpay ;}void manager::display() { cout << "经理:" << name << ",编号" << manager::no << ",月工资:" << manager::monthpay << endl;}#include "salesman.h"salesman::salesman() :employee(){ }void salesman::setemployee() { cout << "请输入员工姓名" << endl; cin >> name; cout << "请输入员工编号" << endl; cin >> no; cout << "月销售额" << endl; cin >> sales; commrate = 0.04; salary = sales * commrate;}void salesman::display() { cout << "销售员:" << name << ",编号" << no << ",月工资:" << salary << endl;}#include "technique.h"technique::technique() :employee(){ hourlyrate = 150; workhours = 0;}void technique::setemployee() { cout << "请输入员工姓名" << endl; cin >> name; cout << "请输入员工编号" << endl; cin >> no; cout << "请输入工作时长(以小时为单位)" << endl; cin >> workhours; salary = hourlyrate * workhours;}void technique::display() { cout << "技术员:" << name << ",编号" << technique::no << ",月工资:" << technique::salary << endl;}#include<stdio.h>#include<conio.h>#include"management.h"void menu(){ cout << "————————————————————————————————" << endl; cout << "———————————欢迎来到员工管理系统———————————" << endl; cout << "——————————————0.退出———————————————" << endl; cout << "————————————1.增添员工信息—————————————" << endl; cout << "————————————2.删除员工信息—————————————" << endl; cout << "————————————3.更改员工信息—————————————" << endl; cout << "————————————4.查找员工信息—————————————" << endl; cout << "————————————————————————————————" << endl; cout << "请输入相关序号" << endl; }void menu1(){ }void menu();void menu1();int main(){ int k; while (1) { menu(); int k; cin >> k; system("cls"); management a; switch (k) { case 1: //system("cls"); a.add(); //a.print(); system("pause"); system("cls"); break; case 2: a.decrease(); system("pause"); system("cls"); break; case 3: a.revise(); system("pause"); system("cls"); break; case 4: a.search(); system("pause"); system("cls"); break; case 0: cout << "退出" << endl; system("cls"); } } return 0;} 

img


我一运行删除修改功能就报如下错误

还有这样的警告,但是我不会指针,只想用数组

img




采纳答案:

no改成this.no


版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7617870