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;
}
- Paste into ChatGPT and ask it to refactor.
- Now ask ChatGPT to create a Makefile.
- Create a GitHub project, add files, clone, build and test.
- Now ask ChatGPT to translate to Python
