forked from PMS-here/Parking_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PMS-here#3 from Pyojihwan/main
console
- Loading branch information
Showing
6 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "User.h" | ||
|
||
// Getter 및 Setter 함수 정의 | ||
|
||
string User::getUsername() const { | ||
return username; | ||
} | ||
|
||
void User::setUsername(const string& username) { | ||
this->username = username; | ||
} | ||
|
||
string User::getEmail() const { | ||
return email; | ||
} | ||
|
||
void User::setEmail(const string& email) { | ||
this->email = email; | ||
} | ||
|
||
string User::getPassword() const { | ||
return password; | ||
} | ||
|
||
void User::setPassword(const string& password) { | ||
this->password = password; | ||
} | ||
|
||
int User::getX() const { | ||
return x; | ||
} | ||
|
||
void User::setX(int x) { | ||
this->x = x; | ||
} | ||
|
||
int User::getY() const { | ||
return y; | ||
} | ||
|
||
void User::setY(int y) { | ||
this->y = y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef USER_H | ||
#define USER_H | ||
|
||
#include <string> | ||
|
||
using namespace std; | ||
|
||
class User { | ||
private: | ||
string username; | ||
string email; | ||
string password; | ||
int x; | ||
int y; | ||
|
||
public: | ||
// 기본 생성자 | ||
User() : x(0), y(0) {} | ||
|
||
// 매개변수가 있는 생성자 | ||
User(const string& username, const string& email, const string& password, int x, int y) | ||
: username(username), email(email), password(password), x(x), y(y) {} | ||
|
||
// Getter 및 Setter 함수들 | ||
string getUsername() const; | ||
void setUsername(const string& username); | ||
|
||
string getEmail() const; | ||
void setEmail(const string& email); | ||
|
||
string getPassword() const; | ||
void setPassword(const string& password); | ||
|
||
int getX() const; | ||
void setX(int x); | ||
|
||
int getY() const; | ||
void setY(int y); | ||
}; | ||
|
||
#endif // USER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
#include "UserManager.h" | ||
|
||
#ifdef _WIN32 | ||
#include <windows.h> | ||
#endif | ||
|
||
UserManager::UserManager(const string& filename) : filename(filename) { | ||
loadFromCSV(); | ||
} | ||
|
||
// 텍스트 색상을 설정하는 함수 (Windows에서만 동작) | ||
void UserManager::setColor(int color) { | ||
#ifdef _WIN32 | ||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); | ||
SetConsoleTextAttribute(hConsole, color); | ||
#endif | ||
} | ||
|
||
// 테두리 출력 함수 | ||
void UserManager::printBorder() { | ||
cout << "+------------------------------------------+\n"; | ||
} | ||
|
||
// 사용자 정보를 CSV 파일에 저장하는 함수 | ||
void UserManager::saveToCSV() { | ||
ofstream file(filename); | ||
|
||
if (file.is_open()) { | ||
for (const auto& user : users) { | ||
file << user.getUsername() << "," << user.getEmail() << "," << user.getPassword() << "," << user.getX() << "," << user.getY() << "\n"; | ||
} | ||
file.close(); | ||
} | ||
else { | ||
setColor(12); // Red | ||
cout << "Unable to open file for writing.\n"; | ||
setColor(7); // Reset to default | ||
} | ||
} | ||
|
||
// CSV 파일에서 사용자 정보를 불러오는 함수 | ||
void UserManager::loadFromCSV() { | ||
ifstream file(filename); | ||
|
||
if (file.is_open()) { | ||
string line; | ||
while (getline(file, line)) { | ||
stringstream ss(line); | ||
string username, email, password; | ||
int x, y; | ||
|
||
if (getline(ss, username, ',') && getline(ss, email, ',') && getline(ss, password, ',') && ss >> x && ss.ignore() && ss >> y) { | ||
User user; | ||
user.setUsername(username); | ||
user.setEmail(email); | ||
user.setPassword(password); | ||
user.setX(x); | ||
user.setY(y); | ||
|
||
users.push_back(user); | ||
} | ||
} | ||
file.close(); | ||
} | ||
else { | ||
setColor(12); // Red | ||
cout << "Unable to open file for reading.\n"; | ||
setColor(7); // Reset to default | ||
} | ||
} | ||
|
||
// 사용자 등록 함수 | ||
void UserManager::registerUser() { | ||
User newUser; | ||
|
||
printBorder(); | ||
setColor(11); // Cyan | ||
cout << "| User Registration |\n"; | ||
printBorder(); | ||
|
||
setColor(7); // Reset to default | ||
string username, email, password; | ||
int x, y; | ||
|
||
cout << "Enter username: "; | ||
cin >> username; | ||
newUser.setUsername(username); | ||
|
||
cout << "Enter email: "; | ||
cin >> email; | ||
newUser.setEmail(email); | ||
|
||
cout << "Enter password: "; | ||
cin >> password; | ||
newUser.setPassword(password); | ||
|
||
cout << "Enter x value: "; | ||
cin >> x; | ||
newUser.setX(x); | ||
|
||
cout << "Enter y value: "; | ||
cin >> y; | ||
newUser.setY(y); | ||
|
||
users.push_back(newUser); | ||
saveToCSV(); | ||
|
||
setColor(10); // Green | ||
cout << "User registered successfully!\n"; | ||
setColor(7); // Reset to default | ||
} | ||
|
||
// 사용자 로그인 함수 | ||
bool UserManager::loginUser() { | ||
string username, password; | ||
|
||
printBorder(); | ||
setColor(11); // Cyan | ||
cout << "| User Login |\n"; | ||
printBorder(); | ||
|
||
setColor(7); // Reset to default | ||
cout << "Enter username: "; | ||
cin >> username; | ||
cout << "Enter password: "; | ||
cin >> password; | ||
|
||
for (const auto& user : users) { | ||
if (user.getUsername() == username && user.getPassword() == password) { | ||
setColor(10); // Green | ||
cout << "Login successful! Welcome, " << user.getUsername() << ".\n"; | ||
setColor(7); // Reset to default | ||
return true; | ||
} | ||
} | ||
|
||
setColor(12); // Red | ||
cout << "Login failed. Please check your username and password.\n"; | ||
setColor(7); // Reset to default | ||
return false; | ||
} | ||
|
||
// 메인 메뉴 실행 함수 | ||
void UserManager::run() { | ||
int choice; | ||
while (true) { | ||
printBorder(); | ||
setColor(11); // Cyan | ||
cout << "| Main Menu |\n"; | ||
printBorder(); | ||
|
||
setColor(7); // Reset to default | ||
cout << "1. Register\n"; | ||
cout << "2. Login\n"; | ||
cout << "3. Exit\n"; | ||
cout << "Choose an option: "; | ||
cin >> choice; | ||
|
||
if (choice == 1) { | ||
registerUser(); | ||
} | ||
else if (choice == 2) { | ||
loginUser(); | ||
} | ||
else if (choice == 3) { | ||
setColor(10); // Green | ||
cout << "Exiting the program.\n"; | ||
setColor(7); // Reset to default | ||
break; | ||
} | ||
else { | ||
setColor(12); // Red | ||
cout << "Invalid option. Please choose again.\n"; | ||
setColor(7); // Reset to default | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef USERMANAGER_H | ||
#define USERMANAGER_H | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <vector> | ||
#include <string> | ||
#include "User.h" | ||
|
||
using namespace std; | ||
|
||
class UserManager { | ||
public: | ||
UserManager(const string& filename); | ||
void run(); | ||
|
||
private: | ||
vector<User> users; | ||
string filename; | ||
|
||
void setColor(int color); | ||
void printBorder(); | ||
void saveToCSV(); | ||
void loadFromCSV(); | ||
void registerUser(); | ||
bool loginUser(); | ||
}; | ||
|
||
#endif // USERMANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "UserManager.h" | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
UserManager userManager("users.csv"); | ||
userManager.run(); | ||
return 0; | ||
} |