Code Refactoring and Translation with ChapGPT

Consider the following code:

// Original Code: Messy and Hard to Maintain
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// A very basic class for employees
class Employee {
public:
    string name;
    int age;
    double salary;

    Employee(string n, int a, double s) {
        name = n;
        age = a;
        salary = s;
    }

    void printDetails() {
        cout << "Name: " << name << ", Age: " << age << ", Salary: " << salary << endl;
    }
};

// Adding employees and performing operations
int main() {
    vector<Employee> employees;

    employees.push_back(Employee("Alice", 30, 50000));
    employees.push_back(Employee("Bob", 40, 60000));
    employees.push_back(Employee("Charlie", 35, 70000));

    for (int i = 0; i < employees.size(); i++) {
        employees[i].printDetails();
        if (employees[i].age > 35) {
            cout << employees[i].name << " is eligible for a promotion." << endl;
        }
    }

    cout << "Total Salary: ";
    double totalSalary = 0;
    for (int i = 0; i < employees.size(); i++) {
        totalSalary += employees[i].salary;
    }
    cout << totalSalary << endl;

    return 0;
}
  1. Paste into ChatGPT and ask it to refactor.
  2. Now ask ChatGPT to create a Makefile.
  3. Create a GitHub project, add files, clone, build and test.
  4. Now ask ChatGPT to translate to Python
Scroll to Top