Iris Thesis
sa schoolunknown
plain_text
7 months ago
4.3 kB
8
Indexable
Never
#include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; // function to split a string into vector of strings vector<string> split(string str, char delimiter) { vector<string> tokens; string token; size_t pos = 0; while ((pos = str.find(delimiter)) != string::npos) { token = str.substr(0, pos); tokens.push_back(token); str.erase(0, pos + 1); } tokens.push_back(str); return tokens; } // function to display the menu void displayMenu() { cout << "Sistema ng Pag-order ng T-shirt para sa mga Mag-aaral" << endl; cout << "-------------------------------------------------" << endl; cout << "1. Magdagdag ng bagong customer" << endl; cout << "2. Mag-modify ng impormasyon ng customer" << endl; cout << "3. Mag-order ng T-shirt" << endl; cout << "4. Ipakita ang lahat ng mga customer" << endl; cout << "5. Exit" << endl; } // function to add a new customer void addCustomer(vector<vector<string>> &customers) { string name, section; cout << "Magdagdag ng bagong customer" << endl; cout << "Pangalan: "; cin >> name; cout << "Seksyon: "; cin >> section; vector<string> customer = { name, section }; customers.push_back(customer); cout << "Ang customer ay naidagdag na." << endl; } // function to modify customer information void modifyCustomer(vector<vector<string>> &customers) { string name, section; cout << "Mag-modify ng impormasyon ng customer" << endl; cout << "Pangalan ng customer na gustong i-modify: "; cin >> name; bool found = false; for (vector<string> &customer : customers) { if (customer[0] == name) { found = true; cout << "Bagong seksyon: "; cin >> section; customer[1] = section; cout << "Ang impormasyon ng customer ay na-update na." << endl; break; } } if (!found) { cout << "Hindi natagpuan ang customer." << endl; } } // function to place an order void placeOrder(vector<vector<string>> &customers) { string name; int quantity; cout << "Mag-order ng T-shirt" << endl; cout << "Pangalan ng customer: "; cin >> name; bool found = false; for (vector<string> &customer : customers) { if (customer[0] == name) { found = true; cout << "Kuwantiti: "; cin >> quantity; cout << quantity << " T-shirt(s) ay na-order para kay " << name << "." << endl; break; } } if (!found) { cout << "Hindi natagpuan ang customer." << endl; } } // function to display all customers void displayCustomers(vector<vector<string>> &customers) { cout << "Mga customer: " << endl; for (vector<string> &customers : customers) { cout << customer[0] << "\t" << customer[1] << endl; } } // function to read data from a CSV file void readData(vector<vector<string>> &customers) { ifstream file("customers.csv"); if (file.is_open()) { string line; while (getline(file, line)) { vector<string> customer = split(line, ','); customers.push_back(customer); } file.close(); } else { cout << "Hindi ma-access ang file." << endl; } } // function to write data to a CSV file void writeData(vector<vector<string>> &customers) { ofstream file("customers.csv"); if (file.is_open()) { for (vector<string> &customer : customers) { file << customer[0] << "," << customer[1] << "\n"; } file.close(); } else { cout << "Hindi ma-access ang file." << endl; } } int main() { vector<vector<string>> customers; readData(customers); int choice; do { displayMenu(); cout << "Pumili ng isang opsyon: "; cin >> choice; switch (choice) { case 1: addCustomer(customers); writeData(customers); break; case 2: modifyCustomer(customers); writeData(customers); break; case 3: placeOrder(customers); break; case 4: displayCustomers(customers); break; case 5: cout << "Maraming salamat sa paggamit ng sistema!" << endl; break; default: cout << "Hindi wastong opsyon. Paki-ulit." << endl; } } while (choice != 5); return 0; }