Update main.cpp

main
Rinats Andrejevs 2024-04-30 10:02:11 +00:00
parent a13a772b15
commit 4f1a32abf1
1 changed files with 21 additions and 21 deletions

View File

@ -4,14 +4,14 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <windows.h> #include <windows.h>
using namespace std; using namespace std; //Bibliotēku savienošana
class User { class User { //User klasu izveidošana datu saglabašanai
public: public:
string name, password; string name, password;
}; };
class FinancialRecord { class FinancialRecord { //FinancialRecord klasu izveidošana datu saglabašanai
public: public:
string id, date, description; string id, date, description;
double profit, loss; double profit, loss;
@ -21,7 +21,7 @@ public:
}; };
vector<string> split(string str, char delimiter) { vector<string> split(string str, char delimiter) { //Funkcija lai sadalītu informāciju txt filā
vector<string> result; vector<string> result;
stringstream ss(str); stringstream ss(str);
string item; string item;
@ -31,7 +31,7 @@ vector<string> split(string str, char delimiter) {
return result; return result;
} }
void register_user(vector<User>& users) { void register_user(vector<User>& users) { //Funkcija lai registretu lietotaju
cout << "\nRegistering a new user\n"; cout << "\nRegistering a new user\n";
string name, password; string name, password;
cout << "Enter new user name: "; cout << "Enter new user name: ";
@ -45,7 +45,7 @@ void register_user(vector<User>& users) {
cout << "\nNew user has been registered successfully."; cout << "\nNew user has been registered successfully.";
} }
bool login_user(const vector<User>& users, string& username, string& password) { bool login_user(const vector<User>& users, string& username, string& password) { //Funkcija lai iejiet izveidota lietotajā
cout << "\nLogging in...\n"; cout << "\nLogging in...\n";
cout << "Enter username: "; cout << "Enter username: ";
cin >> username; cin >> username;
@ -61,7 +61,7 @@ bool login_user(const vector<User>& users, string& username, string& password) {
return false; return false;
} }
void display_additional_menu() { void display_additional_menu() { //Izvelne lietotajam
cout << "\nAdditional Menu:\n"; cout << "\nAdditional Menu:\n";
cout << "1. Add Record\n"; cout << "1. Add Record\n";
cout << "2. Edit User\n"; cout << "2. Edit User\n";
@ -78,7 +78,7 @@ void display_additional_menu() {
cout << "0. Exit\n"; cout << "0. Exit\n";
} }
void add_record(vector<FinancialRecord>& records) { void add_record(vector<FinancialRecord>& records) { //Funkcija lai pievienotu ierakstu
cout << "\nAdding a new financial record...\n"; cout << "\nAdding a new financial record...\n";
string id, date, description; string id, date, description;
double profit, loss; double profit, loss;
@ -97,7 +97,7 @@ void add_record(vector<FinancialRecord>& records) {
records.push_back(FinancialRecord(to_string(next_id), date, description, profit, loss)); records.push_back(FinancialRecord(to_string(next_id), date, description, profit, loss));
} }
void edit_user(vector<User>& users) { void edit_user(vector<User>& users) { //Funkcija lai samainitu lietotaja datus
cout << "\nEditing user details...\n"; cout << "\nEditing user details...\n";
string username, new_name, new_password; string username, new_name, new_password;
cout << "Enter username to edit: "; cout << "Enter username to edit: ";
@ -117,7 +117,7 @@ void edit_user(vector<User>& users) {
cout << "User not found.\n"; cout << "User not found.\n";
} }
void delete_user(vector<User>& users) { void delete_user(vector<User>& users) { //Funkcija lai izdsestu lietotaju
cout << "\nDeleting a user...\n"; cout << "\nDeleting a user...\n";
string username; string username;
cout << "Enter username to delete: "; cout << "Enter username to delete: ";
@ -132,7 +132,7 @@ void delete_user(vector<User>& users) {
cout << "User not found.\n"; cout << "User not found.\n";
} }
void edit_record(vector<FinancialRecord>& records) { void edit_record(vector<FinancialRecord>& records) { //Funkcija lai samainitu datus par izrakstu
cout << "\nEditing a financial record...\n"; cout << "\nEditing a financial record...\n";
string record_id; string record_id;
cout << "Enter the ID of the record you want to edit: "; cout << "Enter the ID of the record you want to edit: ";
@ -156,7 +156,7 @@ void edit_record(vector<FinancialRecord>& records) {
cout << "Record not found.\n"; cout << "Record not found.\n";
} }
void delete_record(vector<FinancialRecord>& records) { void delete_record(vector<FinancialRecord>& records) { //Funkcija lai izdsestu izrakstu
cout << "\nDeleting a financial record...\n"; cout << "\nDeleting a financial record...\n";
string record_id; string record_id;
cout << "Enter the ID of the record you want to delete: "; cout << "Enter the ID of the record you want to delete: ";
@ -172,7 +172,7 @@ void delete_record(vector<FinancialRecord>& records) {
cout << "Record not found.\n"; cout << "Record not found.\n";
} }
void output_analytics(const vector<FinancialRecord>& records) { void output_analytics(const vector<FinancialRecord>& records) { //Funkcija lai izvadit analitiskus datus
cout << "\nGenerating analytics data...\n"; cout << "\nGenerating analytics data...\n";
double total_profit = 0, total_loss = 0; double total_profit = 0, total_loss = 0;
for (const FinancialRecord& record : records) { for (const FinancialRecord& record : records) {
@ -184,7 +184,7 @@ void output_analytics(const vector<FinancialRecord>& records) {
cout << "Net Profit: $" << (total_profit - total_loss) << endl; cout << "Net Profit: $" << (total_profit - total_loss) << endl;
} }
void save_records_to_file(const vector<FinancialRecord>& records) { void save_records_to_file(const vector<FinancialRecord>& records) { //Funkcija lai saglabatu izrakstus txt filā
cout << "\nSaving records to a file...\n"; cout << "\nSaving records to a file...\n";
ofstream outfile("financial_records.txt"); ofstream outfile("financial_records.txt");
if (outfile.is_open()) { if (outfile.is_open()) {
@ -209,7 +209,7 @@ void draw_graph() {
cout << "\nDrawing graphs..."; cout << "\nDrawing graphs...";
} }
void total_value(const vector<FinancialRecord>& records) { void total_value(const vector<FinancialRecord>& records) { //Funkcija lai paradītu pilna darījumu summa
cout << "\nCalculating total value...\n"; cout << "\nCalculating total value...\n";
double total_profit = 0; double total_profit = 0;
for (const FinancialRecord& record : records) { for (const FinancialRecord& record : records) {
@ -218,7 +218,7 @@ void total_value(const vector<FinancialRecord>& records) {
cout << "Total profit: $" << total_profit << endl; cout << "Total profit: $" << total_profit << endl;
} }
void output_loss(const vector<FinancialRecord>& records) { void output_loss(const vector<FinancialRecord>& records) { //Funkcija lai paradītu pilna darījumu summa
cout << "\nCalculating and displaying loss...\n"; cout << "\nCalculating and displaying loss...\n";
double total_loss = 0; double total_loss = 0;
for (const FinancialRecord& record : records) { for (const FinancialRecord& record : records) {
@ -227,7 +227,7 @@ void output_loss(const vector<FinancialRecord>& records) {
cout << "Total loss: $" << total_loss << endl; cout << "Total loss: $" << total_loss << endl;
} }
void output_profit(const vector<FinancialRecord>& records) { void output_profit(const vector<FinancialRecord>& records) { //Funkcija lai paradītu pilno peļņu
cout << "\nCalculating and displaying profit...\n"; cout << "\nCalculating and displaying profit...\n";
double total_value = 0; double total_value = 0;
for (const FinancialRecord& record : records) { for (const FinancialRecord& record : records) {
@ -238,7 +238,7 @@ void output_profit(const vector<FinancialRecord>& records) {
int main() { int main() {
vector<FinancialRecord> records; vector<FinancialRecord> records; //vektors kur saglabas izraksti (records)
vector<User> users; vector<User> users;
int choice; int choice;
@ -248,10 +248,10 @@ int main() {
cin >> choice; cin >> choice;
switch (choice) { switch (choice) {
case 1: case 1:
register_user(users); register_user(users); //reģistrācija jauno lietotāju
break; break;
case 2: case 2:
if (login_user(users, username, password)) { if (login_user(users, username, password)) { //Iejiet jau izveidotā lietotajā
int additional_choice; int additional_choice;
do { do {
display_additional_menu(); display_additional_menu();
@ -304,7 +304,7 @@ int main() {
} }
break; break;
case 3: case 3:
cout << "\nExiting program...\n"; cout << "\nExiting program...\n"; //exit programma
break; break;
default: default:
cout << "\nInvalid choice. Please try again.\n"; cout << "\nInvalid choice. Please try again.\n";