C++ question. Beginner

Asked 2 years ago, Updated 2 years ago, 23 views

//#include <iostream>
#include <string>
using namespace std;

class Employ {
    string name;
    string type;
public:
    Employ(string name, string type) {
        this->name = name; this->type = type;
    }
    string getName() { return name; }
    string getType() { return type; }
    void setType(string type) { this->type = type; }
    void setName(string name) { this->name = name; }
    virtual void show() = 0;
};
class FullTime : public Employ {
    int year;
    int off;
    double salary;
public:
    FullTime(string name, string type, double salary, int year) : Employ(name, type) {
        this->salary = salary; this->year = year;
    }
    void recruit();
    void promotion();
    double getSalary() { return salary; }
    void setSalry(double salary) { this->salary = salary; }
    void show();
};
class PartTime : public Employ {
    int basic;
    int time;
public:
    PartTime(string name, string type, int basic, int time) : Employ(name, type) {
        this->basic = basic; this->time = time;
    }
    int getMoney() { return basic * time; }
    void show();
};
class Manager : public FullTime {
public:
    Manager(string name, string type, double salary, int year) : FullTime(name, type, salary, year) { ; }
    void show();

};
class Assistant : public FullTime {
public:
    Assistant(string name, string type, double salary, int year) : FullTime(name, type, salary, year) { ; }
    void show();
};
class Worker : public FullTime {
public:
    Worker(string name, string type, double salary, int year) : FullTime(name, type, salary, year) { ; }
    void show();
};
class Menu {
    int id = 0;
public:
    Employ *e[100];
    void addemploy();
    void searchemploy();
    void listemploy();
    void run();
};
void PartTime::show() {
    cout << getName() << ": " << getType() << "," << getMoney() << endl;
}
void FullTime::show() {
    cout << getName() << ": " << getType() << "," << getSalary() << endl;
}
void FullTime::promotion() {
    if (year > 5) {
        if (getType() == "Employee") {
            setType ("Deputy");
            double salary = getSalary();
            salary = salary + salary * 0.1;
            setSalry(salary);
        }
        else if (getType() == "Deputy") {
            setType ("Exaggeration");
            double salary = getSalary();
            salary = salary + salary * 0.1;
            setSalry(salary);
        }
    }
}
void FullTime::recruit() {

}
void Menu::addemploy() {
    string name, type;
    int year, basic, time, salary;
    cout << "Employee Name: ";
    getline(cin, name);
    cout << "Status: ";
    getline(cin, type);
    if (type == "part-time") {
        cout << "Basic fund: ";
        cin >> basic;
        cout << "Working hours: ";
        cin >> time;
        PartTime *p = new PartTime(name, type, basic, time);
        e[id] = p;
    }
    else {
        cout << "Working years: ";
        cin >> year;
        cout << "Salary: ";
        cin >> salary;
        FullTime *f = new FullTime(name, type, salary, year);
        e[id] = f;
    }
}
void Menu::searchemploy() {
    string name;
    cout << "Employees to be inquired are :";
    getline(cin, name);
    bool exit = true;
    for (int i = 0; i <= id; i++) {

    }
}
void Menu::listemploy() {
    for (int i = 0; i <= id; i++) {
        e[i]->show();
    }
    cout << endl;
}
void Menu::run() {
    bool exit = true;
    while (exit) {
        char menu;
        Cout < <. ; "menu selection (the employees, input : a inquiry : View : as a whole, s l, Termination : q > >"
        cin >> menu;
        switch (menu)
        {
        case 'A':
            addemploy();
            id += 1;
            cout << endl;
            break;
        case 'S':
            searchemploy();
            cout << endl;
            break;
        case 'L':
            listemploy();
            cout << endl;
            break;
        case 'Q':
            exit = false;
        default:
            break;
        }
    }
}
int main() {
    Menu *m = new Menu();
    m->run();

    delete m;
}

There will be a lot of errors because I tried to turn it around while I was writing this in the middle. I'd appreciate it if you could see if there were any elements that would pop up on the screenㅠ<

c++

2022-09-22 08:38

1 Answers

Try to get the input in sin instead of getline


2022-09-22 08:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.