Getting better with C++

FunnyVALENTINE

FunnyVALENTINE

D4C LOVE TRAIN
Joined
Apr 19, 2026
Posts
1,659
Reputation
1,741
C++:
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cctype>
#include<filesystem>
#include<algorithm>
#include<random>
#include<bitset>
#include<set>
#include<string_view>
#include<memory>
#include<cmath>
#include<cctype>
#include<fstream>

using std::vector;
using std::string;
using std::unordered_map;
using std::bitset;
using std::cout;
using std::cin;
using std::cerr;

class Book
{
public:
    int id{};
    string title{};
    string author{};
    int year{};
    bool available{};
};

class Library
{
public:
    vector<Book> collection =
    {
        {1,"The Hobbit","J.R.R. Tolkien", 1937, true},
        {2,"1984", "George Orwell", 1949, true},
        {3,"To Kill A Mockingbird", "Harper Lee", 1960, true},
        {4, "The Great Gatsby", "F.Scott Fitzgerald", 1925,true},
        {5, "Pride and Prejudice", "Jane Austen", 1813, true},
        {6, "The Cather In The Rye", "J.D.Salinger", 1951, true},
        {7, "The Alchemist", "Paulo Coelho", 1988, true},
        {8, "The Da Vinci Code", "Dan Brown", 2003, true},
        {9, "Clean Code", "Robert C Martin", 2008, true},
        {10, "The Pragmatic Programmer", "Andrew Hunt & David Thomas", 1999, true}

    };
};

bool userExists(const string& username);

class User
{
public:
    string username{};
    string password{};
    bool existing_user{};

    void input()
    {
        bool valid_name{};

        do
        {
            existing_user = false;
            valid_name = true;

            cout << "Enter Your UserName: ";
            std::getline(cin >> std::ws, username);

            if (username.length() < 8 or username.length() > 20)
            {
                cout << "Username should not be less than 8 or more than 20 characters\n";
                valid_name = false;
            }

            else if (userExists(username))
            {

                cout << "UserName already exists\n";
                cout << "Choose a different username or If you have an account login to it\n";
                cout << '\n';
                valid_name = false;
                existing_user = true;
                return;
            }

            for (char c : username)
            {
                if (!std::isalnum(static_cast<unsigned char>(c)))
                {
                    cout << "Username Should only contain Alphabets or numericals\n";
                    valid_name = false;
                    break;
                }
            }
        } while (!valid_name);


        bool valid_password{};
        bool is_upper{};
        bool is_digit{};
        bool is_symbol{};

        do
        {
            valid_password = true;
            is_upper = false;
            is_digit = false;
            is_symbol = false;

            cout << "Enter a Password Between 8-20 characters: ";
            cin >> password;

            if (password.length() < 8 or password.length() > 20)
            {
                cout << "Password should not be above 8 or 20 characters\n";
                valid_password = false;
            }


            for (char c : password)
            {
                if (std::isupper(static_cast<unsigned char>(c)))
                {
                    is_upper = true;
                }
                if (std::isdigit(static_cast<unsigned char>(c)))
                {
                    is_digit = true;
                }
                if (std::ispunct(static_cast<unsigned char>(c)))
                {
                    is_symbol = true;
                }
            }

            if (!is_upper)
            {
                cout << "Password must contain alteast one uppercase letter\n";
                valid_password = false;
            }
            if (!is_digit)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }
            if (!is_symbol)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }

        } while (!valid_password);
    }
};

bool bookExists(int id);

int main()
{
    

    User a;
    int option{};

    do
    {
        cout << "------------------MAIN MENU------------------\n";
        cout << "1.Sign Up and Register to start borrowing books\n";
        cout << "2.Login and Explore the Library to borrow and exchange books\n";
        cout << "3.Exit\n";

        cout << "Enter a number between 1-3 to begin operation: ";
        cin >> option;

        if (option == 1)
        {
            a.input();
            if (!a.existing_user)
            {
                std::ofstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for writing\n";
                }

                file << "Username: " << a.username << '\n';
                file << "Password: " << a.password << '\n';
                file.close();
            }
        }

        else if (option == 2)
        {
            int count{};
            string s_ID{};

            std::ifstream file3{ "borrowed_books.json" };
            if (!file3)
            {
                cerr << "File will be created once you borrow your first book\n";
            }

            while (std::getline(file3, s_ID))
            {
                if (s_ID.find("\"id\"") != string::npos)
                {
                    ++count;
                }
            }


            
                string stored_username{};
                string stored_password{};

                string Username{};
                string Password{};

                std::ifstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for reading\n";
                }

                cout << "Enter Your Username\n";
                std::getline(cin >> std::ws, Username);

                cout << "Enter Your Password\n";
                cin >> Password;

                while (std::getline(file, stored_username) && std::getline(file, stored_password))
                {
                    if (stored_username == "Username: " + Username && stored_password == "Password: " + Password)
                    {
                        cout << "Login Successful\n";


                        bool logged_in{ true };
                        int choice{};
                        Library library{};
                        Book book;

                        while (logged_in)
                        {
                            cout << "----------MENU----------\n";
                            cout << "------------------------\n";
                            cout << "1.View Books\n";
                            cout << "2.Check Book Availability\n";
                            cout << "3.Search and Borrow Books\n";
                            cout << "4.Return Books\n";
                            cout << "5.To Exit\n";


                            cout << "Enter a Number between 1-4 to beging Operation: ";
                            cin >> choice;

                            switch (choice)
                            {
                            case 1:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.id << ". "
                                        << book.title
                                        << " by "
                                        << book.author
                                        << '\n';
                                }
                                break;
                            }

                            case 2:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.title << " by "
                                        << book.author << " is "
                                        << (book.available ? "Available" : "Not Available")
                                        << '\n';

                                }
                                break;
                            }

                            case 3:
                            {
                                int search_id{};
                                cout << "Enter the search Id of the book you want to borrow: ";

                                cin >> search_id;
                                auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                    {
                                        return book.id == search_id;
                                    });

                                if (it == library.collection.end())
                                {
                                    cout << "Book Not Found\n";
                                    break;
                                }

                                if (count == 5)
                                {
                                    cout << "You Already have 5 books\n";
                                    break;
                                }

                                if (bookExists(it->id))
                                {
                                    cout << "Book Already Exists In Your Collection!\n";
                                    break;
                                }



                                if (it->available)
                                {
                                    std::ofstream file{ "borrowed_books.json" };

                                    file << "{\n";
                                    file << "  \"books\": [\n";

                                    file << "    {\n";
                                    file << "      \"id\": " << it->id << "," << '\n';
                                    file << "      \"title\": \"" << it->title << "\"" << "," << '\n';
                                    file << "      \"author\": \"" << it->author << "\"" << "," << '\n';
                                    file << "      \"year\": " << it->year << "," << '\n';
                                    it->available = false;
                                    file << "      \"available\": " << std::boolalpha << it->available << '\n';
                                    file << "    },\n";

                                    file << "  ]\n";
                                    file << "}\n";
                                    file.close();

                                    string line{};
                                    vector<string>lines{};
                                    char option{};

                                    int num{ 4 };

                                    std::ifstream file1{ "borrowed_books.json" };

                                    while (std::getline(file1, line))
                                    {
                                        lines.push_back(line);
                                    }
                                    file1.close();

                                    for (size_t i = 0; i < 4; ++i)
                                    {
                                        cout << "You can " << num << " more books continue ? : ";
                                        cin >> option;

                                        if (option == 'y' || option == 'Y')
                                        {
                                            for (size_t j = 0; j < lines.size(); ++j)
                                            {
                                                if (lines[j].find(']') != std::string::npos)
                                                {
                                                    cout << "Enter the search Id of the book you want to borrow: ";
                                                    cin >> search_id;

                                                    auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                                        {
                                                            return book.id == search_id;
                                                        });

                                                    if (it == library.collection.end())
                                                    {
                                                        cout << "Book Not Found\n";
                                                        break;
                                                    }

                                                    it->available = false;

                                                    lines.insert(lines.begin() + j,
                                                        {
                                                            "    {",
                                                            "      \"id\": " + std::to_string(it->id) + ",",
                                                            "      \"title\": \"" + it->title + "\",",
                                                            "      \"author\": \"" + it->author + "\",",
                                                            "      \"year\": " + std::to_string(it->year) + ",",
                                                            "      \"available\": " + std::string(it->available ? "true" : "false"),
                                                            "    },"

                                                        });




                                                    num -= 1;

                                                    std::ofstream file{ "borrowed_books.json" };
                                                    for (const auto& x : lines)
                                                    {

                                                        file << x << '\n';
                                                    }
                                                    break;

                                                }
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }


                                else
                                {
                                    cout << "Book Not Available\n";
                                }
                                break;
                                }
                            
                            case 4:
                            {
                                char choiceYN{};
                                do
                                {
                                    

                                    int book_ID{};

                                    cout << "Enter the Id of the book you wanna return: ";
                                    cin >> book_ID;

                                    if (bookExists(book_ID))
                                    {
                                        vector<string>lines{};

                                        string line{};

                                        std::ifstream file{ "borrowed_books.json" };

                                        while (std::getline(file, line))
                                        {
                                            lines.push_back(line);
                                        }

                                        for (size_t i = 1;i < lines.size(); ++i)
                                        {
                                            if (lines[i].find("\"id\"") != string::npos)
                                            {
                                                string stored_id = lines[i];
                                                stored_id = stored_id.substr(12);
                                                stored_id.erase(stored_id.size() - 1);

                                                int new_stored_id = stoi(stored_id);

                                                if (new_stored_id == book_ID)
                                                {
                                                    lines.erase(lines.begin() + i - 1, lines.begin() + i + 6);
                                                    break;
                                                }
                                            }
                                        }
                                        std::ofstream file1{ "borrowed_books.json" };
                                        for (const auto& x : lines)
                                        {

                                            file1 << x << '\n';
                                        }
                                    }

                                    cout << "Do you want to continue ??  (q to quit): ";
                                    cin >> choiceYN;
                                } while (choiceYN != 'q');
                                break;
                            }
                            case 5:
                            {
                                logged_in = false;
                                break;
                            }
                            default:
                            {
                                cout << "Invalid Option\n";
                            }
                        }


                    }


                }

            }

            
        }
        

        else if (option == 3)
        {
            cout << "See You Again\n";
        }
    }

    while (option != 3);



    return 0;
}

bool userExists(const string& username)
{
    string stored_username{};

    std::ifstream file{ "login.txt" };

    if (!file)
    {
        cerr << "file cannot be opened for reading\n";
        return false;
    }

    while (std::getline(file, stored_username))
    {
        if (stored_username == "Username: " + username)
        {
            cout << "Checking.....\n";
            return true;
        }
    }
    return false;
}

bool bookExists(int id)
{
    string stored_id{};

    std::ifstream file{ "borrowed_books.json" };
    std::getline(file, stored_id);
    std::getline(file, stored_id);
    

    while (std::getline(file, stored_id))
    {
        if (stored_id.find("\"id\"") != std::string::npos)
        {
            stored_id = stored_id.substr(12);
            stored_id.erase(stored_id.size() - 1);
            int new_id = std::stoi(stored_id);

            if (new_id == id)
            {
                cout << "Book Found\n";
                return true;
            }
        }

    }
    return false;
}

Today I just built a solid Library system :Chadge:.
Very soon I'll Work with real databases :Chadge:

Say No To VibeCoding :Chadge:
Say NO to AI :Chadge:

If you build projects with AI my nigga just rope at this point you are not a real developer :feelsrope:.

Very Very Soon I'll build something like facebook and become a billionaire :feelshah:.

HAHAHAHAHAHAHAAHA KEEP ROTTING INCELS :feelskek::feelskek::feelskek::feelskek:
I'LL GET INVESTMENTS FOR MY APP :feelskek::feelskek::feelskek::feelskek:
AND WILL BECOME THE KING OF SILICON VALLEY :feelskek::feelskek::feelskek::feelskek:
 
  • +1
  • Love it
  • JFL
Reactions: shedontluv-U, satangoy, LXR and 4 others
Bump :HMMMM:
 
  • +1
Reactions: shedontluv-U and LXR
WOw
 
  • +1
Reactions: FunnyVALENTINE
Cool can you hack websites with it
 
  • +1
Reactions: FunnyVALENTINE
C++:
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cctype>
#include<filesystem>
#include<algorithm>
#include<random>
#include<bitset>
#include<set>
#include<string_view>
#include<memory>
#include<cmath>
#include<cctype>
#include<fstream>

using std::vector;
using std::string;
using std::unordered_map;
using std::bitset;
using std::cout;
using std::cin;
using std::cerr;

class Book
{
public:
    int id{};
    string title{};
    string author{};
    int year{};
    bool available{};
};

class Library
{
public:
    vector<Book> collection =
    {
        {1,"The Hobbit","J.R.R. Tolkien", 1937, true},
        {2,"1984", "George Orwell", 1949, true},
        {3,"To Kill A Mockingbird", "Harper Lee", 1960, true},
        {4, "The Great Gatsby", "F.Scott Fitzgerald", 1925,true},
        {5, "Pride and Prejudice", "Jane Austen", 1813, true},
        {6, "The Cather In The Rye", "J.D.Salinger", 1951, true},
        {7, "The Alchemist", "Paulo Coelho", 1988, true},
        {8, "The Da Vinci Code", "Dan Brown", 2003, true},
        {9, "Clean Code", "Robert C Martin", 2008, true},
        {10, "The Pragmatic Programmer", "Andrew Hunt & David Thomas", 1999, true}

    };
};

bool userExists(const string& username);

class User
{
public:
    string username{};
    string password{};
    bool existing_user{};

    void input()
    {
        bool valid_name{};

        do
        {
            existing_user = false;
            valid_name = true;

            cout << "Enter Your UserName: ";
            std::getline(cin >> std::ws, username);

            if (username.length() < 8 or username.length() > 20)
            {
                cout << "Username should not be less than 8 or more than 20 characters\n";
                valid_name = false;
            }

            else if (userExists(username))
            {

                cout << "UserName already exists\n";
                cout << "Choose a different username or If you have an account login to it\n";
                cout << '\n';
                valid_name = false;
                existing_user = true;
                return;
            }

            for (char c : username)
            {
                if (!std::isalnum(static_cast<unsigned char>(c)))
                {
                    cout << "Username Should only contain Alphabets or numericals\n";
                    valid_name = false;
                    break;
                }
            }
        } while (!valid_name);


        bool valid_password{};
        bool is_upper{};
        bool is_digit{};
        bool is_symbol{};

        do
        {
            valid_password = true;
            is_upper = false;
            is_digit = false;
            is_symbol = false;

            cout << "Enter a Password Between 8-20 characters: ";
            cin >> password;

            if (password.length() < 8 or password.length() > 20)
            {
                cout << "Password should not be above 8 or 20 characters\n";
                valid_password = false;
            }


            for (char c : password)
            {
                if (std::isupper(static_cast<unsigned char>(c)))
                {
                    is_upper = true;
                }
                if (std::isdigit(static_cast<unsigned char>(c)))
                {
                    is_digit = true;
                }
                if (std::ispunct(static_cast<unsigned char>(c)))
                {
                    is_symbol = true;
                }
            }

            if (!is_upper)
            {
                cout << "Password must contain alteast one uppercase letter\n";
                valid_password = false;
            }
            if (!is_digit)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }
            if (!is_symbol)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }

        } while (!valid_password);
    }
};

bool bookExists(int id);

int main()
{
   

    User a;
    int option{};

    do
    {
        cout << "------------------MAIN MENU------------------\n";
        cout << "1.Sign Up and Register to start borrowing books\n";
        cout << "2.Login and Explore the Library to borrow and exchange books\n";
        cout << "3.Exit\n";

        cout << "Enter a number between 1-3 to begin operation: ";
        cin >> option;

        if (option == 1)
        {
            a.input();
            if (!a.existing_user)
            {
                std::ofstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for writing\n";
                }

                file << "Username: " << a.username << '\n';
                file << "Password: " << a.password << '\n';
                file.close();
            }
        }

        else if (option == 2)
        {
            int count{};
            string s_ID{};

            std::ifstream file3{ "borrowed_books.json" };
            if (!file3)
            {
                cerr << "File will be created once you borrow your first book\n";
            }

            while (std::getline(file3, s_ID))
            {
                if (s_ID.find("\"id\"") != string::npos)
                {
                    ++count;
                }
            }


           
                string stored_username{};
                string stored_password{};

                string Username{};
                string Password{};

                std::ifstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for reading\n";
                }

                cout << "Enter Your Username\n";
                std::getline(cin >> std::ws, Username);

                cout << "Enter Your Password\n";
                cin >> Password;

                while (std::getline(file, stored_username) && std::getline(file, stored_password))
                {
                    if (stored_username == "Username: " + Username && stored_password == "Password: " + Password)
                    {
                        cout << "Login Successful\n";


                        bool logged_in{ true };
                        int choice{};
                        Library library{};
                        Book book;

                        while (logged_in)
                        {
                            cout << "----------MENU----------\n";
                            cout << "------------------------\n";
                            cout << "1.View Books\n";
                            cout << "2.Check Book Availability\n";
                            cout << "3.Search and Borrow Books\n";
                            cout << "4.Return Books\n";
                            cout << "5.To Exit\n";


                            cout << "Enter a Number between 1-4 to beging Operation: ";
                            cin >> choice;

                            switch (choice)
                            {
                            case 1:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.id << ". "
                                        << book.title
                                        << " by "
                                        << book.author
                                        << '\n';
                                }
                                break;
                            }

                            case 2:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.title << " by "
                                        << book.author << " is "
                                        << (book.available ? "Available" : "Not Available")
                                        << '\n';

                                }
                                break;
                            }

                            case 3:
                            {
                                int search_id{};
                                cout << "Enter the search Id of the book you want to borrow: ";

                                cin >> search_id;
                                auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                    {
                                        return book.id == search_id;
                                    });

                                if (it == library.collection.end())
                                {
                                    cout << "Book Not Found\n";
                                    break;
                                }

                                if (count == 5)
                                {
                                    cout << "You Already have 5 books\n";
                                    break;
                                }

                                if (bookExists(it->id))
                                {
                                    cout << "Book Already Exists In Your Collection!\n";
                                    break;
                                }



                                if (it->available)
                                {
                                    std::ofstream file{ "borrowed_books.json" };

                                    file << "{\n";
                                    file << "  \"books\": [\n";

                                    file << "    {\n";
                                    file << "      \"id\": " << it->id << "," << '\n';
                                    file << "      \"title\": \"" << it->title << "\"" << "," << '\n';
                                    file << "      \"author\": \"" << it->author << "\"" << "," << '\n';
                                    file << "      \"year\": " << it->year << "," << '\n';
                                    it->available = false;
                                    file << "      \"available\": " << std::boolalpha << it->available << '\n';
                                    file << "    },\n";

                                    file << "  ]\n";
                                    file << "}\n";
                                    file.close();

                                    string line{};
                                    vector<string>lines{};
                                    char option{};

                                    int num{ 4 };

                                    std::ifstream file1{ "borrowed_books.json" };

                                    while (std::getline(file1, line))
                                    {
                                        lines.push_back(line);
                                    }
                                    file1.close();

                                    for (size_t i = 0; i < 4; ++i)
                                    {
                                        cout << "You can " << num << " more books continue ? : ";
                                        cin >> option;

                                        if (option == 'y' || option == 'Y')
                                        {
                                            for (size_t j = 0; j < lines.size(); ++j)
                                            {
                                                if (lines[j].find(']') != std::string::npos)
                                                {
                                                    cout << "Enter the search Id of the book you want to borrow: ";
                                                    cin >> search_id;

                                                    auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                                        {
                                                            return book.id == search_id;
                                                        });

                                                    if (it == library.collection.end())
                                                    {
                                                        cout << "Book Not Found\n";
                                                        break;
                                                    }

                                                    it->available = false;

                                                    lines.insert(lines.begin() + j,
                                                        {
                                                            "    {",
                                                            "      \"id\": " + std::to_string(it->id) + ",",
                                                            "      \"title\": \"" + it->title + "\",",
                                                            "      \"author\": \"" + it->author + "\",",
                                                            "      \"year\": " + std::to_string(it->year) + ",",
                                                            "      \"available\": " + std::string(it->available ? "true" : "false"),
                                                            "    },"

                                                        });




                                                    num -= 1;

                                                    std::ofstream file{ "borrowed_books.json" };
                                                    for (const auto& x : lines)
                                                    {

                                                        file << x << '\n';
                                                    }
                                                    break;

                                                }
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }


                                else
                                {
                                    cout << "Book Not Available\n";
                                }
                                break;
                                }
                           
                            case 4:
                            {
                                char choiceYN{};
                                do
                                {
                                   

                                    int book_ID{};

                                    cout << "Enter the Id of the book you wanna return: ";
                                    cin >> book_ID;

                                    if (bookExists(book_ID))
                                    {
                                        vector<string>lines{};

                                        string line{};

                                        std::ifstream file{ "borrowed_books.json" };

                                        while (std::getline(file, line))
                                        {
                                            lines.push_back(line);
                                        }

                                        for (size_t i = 1;i < lines.size(); ++i)
                                        {
                                            if (lines[i].find("\"id\"") != string::npos)
                                            {
                                                string stored_id = lines[i];
                                                stored_id = stored_id.substr(12);
                                                stored_id.erase(stored_id.size() - 1);

                                                int new_stored_id = stoi(stored_id);

                                                if (new_stored_id == book_ID)
                                                {
                                                    lines.erase(lines.begin() + i - 1, lines.begin() + i + 6);
                                                    break;
                                                }
                                            }
                                        }
                                        std::ofstream file1{ "borrowed_books.json" };
                                        for (const auto& x : lines)
                                        {

                                            file1 << x << '\n';
                                        }
                                    }

                                    cout << "Do you want to continue ??  (q to quit): ";
                                    cin >> choiceYN;
                                } while (choiceYN != 'q');
                                break;
                            }
                            case 5:
                            {
                                logged_in = false;
                                break;
                            }
                            default:
                            {
                                cout << "Invalid Option\n";
                            }
                        }


                    }


                }

            }

           
        }
       

        else if (option == 3)
        {
            cout << "See You Again\n";
        }
    }

    while (option != 3);



    return 0;
}

bool userExists(const string& username)
{
    string stored_username{};

    std::ifstream file{ "login.txt" };

    if (!file)
    {
        cerr << "file cannot be opened for reading\n";
        return false;
    }

    while (std::getline(file, stored_username))
    {
        if (stored_username == "Username: " + username)
        {
            cout << "Checking.....\n";
            return true;
        }
    }
    return false;
}

bool bookExists(int id)
{
    string stored_id{};

    std::ifstream file{ "borrowed_books.json" };
    std::getline(file, stored_id);
    std::getline(file, stored_id);
   

    while (std::getline(file, stored_id))
    {
        if (stored_id.find("\"id\"") != std::string::npos)
        {
            stored_id = stored_id.substr(12);
            stored_id.erase(stored_id.size() - 1);
            int new_id = std::stoi(stored_id);

            if (new_id == id)
            {
                cout << "Book Found\n";
                return true;
            }
        }

    }
    return false;
}

Today I just built a solid Library system :Chadge:.
Very soon I'll Work with real databases :Chadge:

Say No To VibeCoding :Chadge:
Say NO to AI :Chadge:

If you build projects with AI my nigga just rope at this point you are not a real developer :feelsrope:.

Very Very Soon I'll build something like facebook and become a billionaire :feelshah:.

HAHAHAHAHAHAHAAHA KEEP ROTTING INCELS :feelskek::feelskek::feelskek::feelskek:
I'LL GET INVESTMENTS FOR MY APP :feelskek::feelskek::feelskek::feelskek:
AND WILL BECOME THE KING OF SILICON VALLEY :feelskek::feelskek::feelskek::feelskek:
@Jason Voorhees next codingjesus is here
 
  • +1
  • JFL
  • Hmm...
Reactions: sub1foidslayer, Riley209711 and FunnyVALENTINE
C++:
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cctype>
#include<filesystem>
#include<algorithm>
#include<random>
#include<bitset>
#include<set>
#include<string_view>
#include<memory>
#include<cmath>
#include<cctype>
#include<fstream>

using std::vector;
using std::string;
using std::unordered_map;
using std::bitset;
using std::cout;
using std::cin;
using std::cerr;

class Book
{
public:
    int id{};
    string title{};
    string author{};
    int year{};
    bool available{};
};

class Library
{
public:
    vector<Book> collection =
    {
        {1,"The Hobbit","J.R.R. Tolkien", 1937, true},
        {2,"1984", "George Orwell", 1949, true},
        {3,"To Kill A Mockingbird", "Harper Lee", 1960, true},
        {4, "The Great Gatsby", "F.Scott Fitzgerald", 1925,true},
        {5, "Pride and Prejudice", "Jane Austen", 1813, true},
        {6, "The Cather In The Rye", "J.D.Salinger", 1951, true},
        {7, "The Alchemist", "Paulo Coelho", 1988, true},
        {8, "The Da Vinci Code", "Dan Brown", 2003, true},
        {9, "Clean Code", "Robert C Martin", 2008, true},
        {10, "The Pragmatic Programmer", "Andrew Hunt & David Thomas", 1999, true}

    };
};

bool userExists(const string& username);

class User
{
public:
    string username{};
    string password{};
    bool existing_user{};

    void input()
    {
        bool valid_name{};

        do
        {
            existing_user = false;
            valid_name = true;

            cout << "Enter Your UserName: ";
            std::getline(cin >> std::ws, username);

            if (username.length() < 8 or username.length() > 20)
            {
                cout << "Username should not be less than 8 or more than 20 characters\n";
                valid_name = false;
            }

            else if (userExists(username))
            {

                cout << "UserName already exists\n";
                cout << "Choose a different username or If you have an account login to it\n";
                cout << '\n';
                valid_name = false;
                existing_user = true;
                return;
            }

            for (char c : username)
            {
                if (!std::isalnum(static_cast<unsigned char>(c)))
                {
                    cout << "Username Should only contain Alphabets or numericals\n";
                    valid_name = false;
                    break;
                }
            }
        } while (!valid_name);


        bool valid_password{};
        bool is_upper{};
        bool is_digit{};
        bool is_symbol{};

        do
        {
            valid_password = true;
            is_upper = false;
            is_digit = false;
            is_symbol = false;

            cout << "Enter a Password Between 8-20 characters: ";
            cin >> password;

            if (password.length() < 8 or password.length() > 20)
            {
                cout << "Password should not be above 8 or 20 characters\n";
                valid_password = false;
            }


            for (char c : password)
            {
                if (std::isupper(static_cast<unsigned char>(c)))
                {
                    is_upper = true;
                }
                if (std::isdigit(static_cast<unsigned char>(c)))
                {
                    is_digit = true;
                }
                if (std::ispunct(static_cast<unsigned char>(c)))
                {
                    is_symbol = true;
                }
            }

            if (!is_upper)
            {
                cout << "Password must contain alteast one uppercase letter\n";
                valid_password = false;
            }
            if (!is_digit)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }
            if (!is_symbol)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }

        } while (!valid_password);
    }
};

bool bookExists(int id);

int main()
{
   

    User a;
    int option{};

    do
    {
        cout << "------------------MAIN MENU------------------\n";
        cout << "1.Sign Up and Register to start borrowing books\n";
        cout << "2.Login and Explore the Library to borrow and exchange books\n";
        cout << "3.Exit\n";

        cout << "Enter a number between 1-3 to begin operation: ";
        cin >> option;

        if (option == 1)
        {
            a.input();
            if (!a.existing_user)
            {
                std::ofstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for writing\n";
                }

                file << "Username: " << a.username << '\n';
                file << "Password: " << a.password << '\n';
                file.close();
            }
        }

        else if (option == 2)
        {
            int count{};
            string s_ID{};

            std::ifstream file3{ "borrowed_books.json" };
            if (!file3)
            {
                cerr << "File will be created once you borrow your first book\n";
            }

            while (std::getline(file3, s_ID))
            {
                if (s_ID.find("\"id\"") != string::npos)
                {
                    ++count;
                }
            }


           
                string stored_username{};
                string stored_password{};

                string Username{};
                string Password{};

                std::ifstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for reading\n";
                }

                cout << "Enter Your Username\n";
                std::getline(cin >> std::ws, Username);

                cout << "Enter Your Password\n";
                cin >> Password;

                while (std::getline(file, stored_username) && std::getline(file, stored_password))
                {
                    if (stored_username == "Username: " + Username && stored_password == "Password: " + Password)
                    {
                        cout << "Login Successful\n";


                        bool logged_in{ true };
                        int choice{};
                        Library library{};
                        Book book;

                        while (logged_in)
                        {
                            cout << "----------MENU----------\n";
                            cout << "------------------------\n";
                            cout << "1.View Books\n";
                            cout << "2.Check Book Availability\n";
                            cout << "3.Search and Borrow Books\n";
                            cout << "4.Return Books\n";
                            cout << "5.To Exit\n";


                            cout << "Enter a Number between 1-4 to beging Operation: ";
                            cin >> choice;

                            switch (choice)
                            {
                            case 1:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.id << ". "
                                        << book.title
                                        << " by "
                                        << book.author
                                        << '\n';
                                }
                                break;
                            }

                            case 2:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.title << " by "
                                        << book.author << " is "
                                        << (book.available ? "Available" : "Not Available")
                                        << '\n';

                                }
                                break;
                            }

                            case 3:
                            {
                                int search_id{};
                                cout << "Enter the search Id of the book you want to borrow: ";

                                cin >> search_id;
                                auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                    {
                                        return book.id == search_id;
                                    });

                                if (it == library.collection.end())
                                {
                                    cout << "Book Not Found\n";
                                    break;
                                }

                                if (count == 5)
                                {
                                    cout << "You Already have 5 books\n";
                                    break;
                                }

                                if (bookExists(it->id))
                                {
                                    cout << "Book Already Exists In Your Collection!\n";
                                    break;
                                }



                                if (it->available)
                                {
                                    std::ofstream file{ "borrowed_books.json" };

                                    file << "{\n";
                                    file << "  \"books\": [\n";

                                    file << "    {\n";
                                    file << "      \"id\": " << it->id << "," << '\n';
                                    file << "      \"title\": \"" << it->title << "\"" << "," << '\n';
                                    file << "      \"author\": \"" << it->author << "\"" << "," << '\n';
                                    file << "      \"year\": " << it->year << "," << '\n';
                                    it->available = false;
                                    file << "      \"available\": " << std::boolalpha << it->available << '\n';
                                    file << "    },\n";

                                    file << "  ]\n";
                                    file << "}\n";
                                    file.close();

                                    string line{};
                                    vector<string>lines{};
                                    char option{};

                                    int num{ 4 };

                                    std::ifstream file1{ "borrowed_books.json" };

                                    while (std::getline(file1, line))
                                    {
                                        lines.push_back(line);
                                    }
                                    file1.close();

                                    for (size_t i = 0; i < 4; ++i)
                                    {
                                        cout << "You can " << num << " more books continue ? : ";
                                        cin >> option;

                                        if (option == 'y' || option == 'Y')
                                        {
                                            for (size_t j = 0; j < lines.size(); ++j)
                                            {
                                                if (lines[j].find(']') != std::string::npos)
                                                {
                                                    cout << "Enter the search Id of the book you want to borrow: ";
                                                    cin >> search_id;

                                                    auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                                        {
                                                            return book.id == search_id;
                                                        });

                                                    if (it == library.collection.end())
                                                    {
                                                        cout << "Book Not Found\n";
                                                        break;
                                                    }

                                                    it->available = false;

                                                    lines.insert(lines.begin() + j,
                                                        {
                                                            "    {",
                                                            "      \"id\": " + std::to_string(it->id) + ",",
                                                            "      \"title\": \"" + it->title + "\",",
                                                            "      \"author\": \"" + it->author + "\",",
                                                            "      \"year\": " + std::to_string(it->year) + ",",
                                                            "      \"available\": " + std::string(it->available ? "true" : "false"),
                                                            "    },"

                                                        });




                                                    num -= 1;

                                                    std::ofstream file{ "borrowed_books.json" };
                                                    for (const auto& x : lines)
                                                    {

                                                        file << x << '\n';
                                                    }
                                                    break;

                                                }
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }


                                else
                                {
                                    cout << "Book Not Available\n";
                                }
                                break;
                                }
                           
                            case 4:
                            {
                                char choiceYN{};
                                do
                                {
                                   

                                    int book_ID{};

                                    cout << "Enter the Id of the book you wanna return: ";
                                    cin >> book_ID;

                                    if (bookExists(book_ID))
                                    {
                                        vector<string>lines{};

                                        string line{};

                                        std::ifstream file{ "borrowed_books.json" };

                                        while (std::getline(file, line))
                                        {
                                            lines.push_back(line);
                                        }

                                        for (size_t i = 1;i < lines.size(); ++i)
                                        {
                                            if (lines[i].find("\"id\"") != string::npos)
                                            {
                                                string stored_id = lines[i];
                                                stored_id = stored_id.substr(12);
                                                stored_id.erase(stored_id.size() - 1);

                                                int new_stored_id = stoi(stored_id);

                                                if (new_stored_id == book_ID)
                                                {
                                                    lines.erase(lines.begin() + i - 1, lines.begin() + i + 6);
                                                    break;
                                                }
                                            }
                                        }
                                        std::ofstream file1{ "borrowed_books.json" };
                                        for (const auto& x : lines)
                                        {

                                            file1 << x << '\n';
                                        }
                                    }

                                    cout << "Do you want to continue ??  (q to quit): ";
                                    cin >> choiceYN;
                                } while (choiceYN != 'q');
                                break;
                            }
                            case 5:
                            {
                                logged_in = false;
                                break;
                            }
                            default:
                            {
                                cout << "Invalid Option\n";
                            }
                        }


                    }


                }

            }

           
        }
       

        else if (option == 3)
        {
            cout << "See You Again\n";
        }
    }

    while (option != 3);



    return 0;
}

bool userExists(const string& username)
{
    string stored_username{};

    std::ifstream file{ "login.txt" };

    if (!file)
    {
        cerr << "file cannot be opened for reading\n";
        return false;
    }

    while (std::getline(file, stored_username))
    {
        if (stored_username == "Username: " + username)
        {
            cout << "Checking.....\n";
            return true;
        }
    }
    return false;
}

bool bookExists(int id)
{
    string stored_id{};

    std::ifstream file{ "borrowed_books.json" };
    std::getline(file, stored_id);
    std::getline(file, stored_id);
   

    while (std::getline(file, stored_id))
    {
        if (stored_id.find("\"id\"") != std::string::npos)
        {
            stored_id = stored_id.substr(12);
            stored_id.erase(stored_id.size() - 1);
            int new_id = std::stoi(stored_id);

            if (new_id == id)
            {
                cout << "Book Found\n";
                return true;
            }
        }

    }
    return false;
}

Today I just built a solid Library system :Chadge:.
Very soon I'll Work with real databases :Chadge:

Say No To VibeCoding :Chadge:
Say NO to AI :Chadge:

If you build projects with AI my nigga just rope at this point you are not a real developer :feelsrope:.

Very Very Soon I'll build something like facebook and become a billionaire :feelshah:.

HAHAHAHAHAHAHAAHA KEEP ROTTING INCELS :feelskek::feelskek::feelskek::feelskek:
I'LL GET INVESTMENTS FOR MY APP :feelskek::feelskek::feelskek::feelskek:
AND WILL BECOME THE KING OF SILICON VALLEY :feelskek::feelskek::feelskek::feelskek:
u arent verified tho so u arent making it far bud lol
 
  • Hmm...
Reactions: FunnyVALENTINE
  • JFL
  • Hmm...
Reactions: FunnyVALENTINE and Riley209711
C++:
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cctype>
#include<filesystem>
#include<algorithm>
#include<random>
#include<bitset>
#include<set>
#include<string_view>
#include<memory>
#include<cmath>
#include<cctype>
#include<fstream>

using std::vector;
using std::string;
using std::unordered_map;
using std::bitset;
using std::cout;
using std::cin;
using std::cerr;

class Book
{
public:
    int id{};
    string title{};
    string author{};
    int year{};
    bool available{};
};

class Library
{
public:
    vector<Book> collection =
    {
        {1,"The Hobbit","J.R.R. Tolkien", 1937, true},
        {2,"1984", "George Orwell", 1949, true},
        {3,"To Kill A Mockingbird", "Harper Lee", 1960, true},
        {4, "The Great Gatsby", "F.Scott Fitzgerald", 1925,true},
        {5, "Pride and Prejudice", "Jane Austen", 1813, true},
        {6, "The Cather In The Rye", "J.D.Salinger", 1951, true},
        {7, "The Alchemist", "Paulo Coelho", 1988, true},
        {8, "The Da Vinci Code", "Dan Brown", 2003, true},
        {9, "Clean Code", "Robert C Martin", 2008, true},
        {10, "The Pragmatic Programmer", "Andrew Hunt & David Thomas", 1999, true}

    };
};

bool userExists(const string& username);

class User
{
public:
    string username{};
    string password{};
    bool existing_user{};

    void input()
    {
        bool valid_name{};

        do
        {
            existing_user = false;
            valid_name = true;

            cout << "Enter Your UserName: ";
            std::getline(cin >> std::ws, username);

            if (username.length() < 8 or username.length() > 20)
            {
                cout << "Username should not be less than 8 or more than 20 characters\n";
                valid_name = false;
            }

            else if (userExists(username))
            {

                cout << "UserName already exists\n";
                cout << "Choose a different username or If you have an account login to it\n";
                cout << '\n';
                valid_name = false;
                existing_user = true;
                return;
            }

            for (char c : username)
            {
                if (!std::isalnum(static_cast<unsigned char>(c)))
                {
                    cout << "Username Should only contain Alphabets or numericals\n";
                    valid_name = false;
                    break;
                }
            }
        } while (!valid_name);


        bool valid_password{};
        bool is_upper{};
        bool is_digit{};
        bool is_symbol{};

        do
        {
            valid_password = true;
            is_upper = false;
            is_digit = false;
            is_symbol = false;

            cout << "Enter a Password Between 8-20 characters: ";
            cin >> password;

            if (password.length() < 8 or password.length() > 20)
            {
                cout << "Password should not be above 8 or 20 characters\n";
                valid_password = false;
            }


            for (char c : password)
            {
                if (std::isupper(static_cast<unsigned char>(c)))
                {
                    is_upper = true;
                }
                if (std::isdigit(static_cast<unsigned char>(c)))
                {
                    is_digit = true;
                }
                if (std::ispunct(static_cast<unsigned char>(c)))
                {
                    is_symbol = true;
                }
            }

            if (!is_upper)
            {
                cout << "Password must contain alteast one uppercase letter\n";
                valid_password = false;
            }
            if (!is_digit)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }
            if (!is_symbol)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }

        } while (!valid_password);
    }
};

bool bookExists(int id);

int main()
{
   

    User a;
    int option{};

    do
    {
        cout << "------------------MAIN MENU------------------\n";
        cout << "1.Sign Up and Register to start borrowing books\n";
        cout << "2.Login and Explore the Library to borrow and exchange books\n";
        cout << "3.Exit\n";

        cout << "Enter a number between 1-3 to begin operation: ";
        cin >> option;

        if (option == 1)
        {
            a.input();
            if (!a.existing_user)
            {
                std::ofstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for writing\n";
                }

                file << "Username: " << a.username << '\n';
                file << "Password: " << a.password << '\n';
                file.close();
            }
        }

        else if (option == 2)
        {
            int count{};
            string s_ID{};

            std::ifstream file3{ "borrowed_books.json" };
            if (!file3)
            {
                cerr << "File will be created once you borrow your first book\n";
            }

            while (std::getline(file3, s_ID))
            {
                if (s_ID.find("\"id\"") != string::npos)
                {
                    ++count;
                }
            }


           
                string stored_username{};
                string stored_password{};

                string Username{};
                string Password{};

                std::ifstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for reading\n";
                }

                cout << "Enter Your Username\n";
                std::getline(cin >> std::ws, Username);

                cout << "Enter Your Password\n";
                cin >> Password;

                while (std::getline(file, stored_username) && std::getline(file, stored_password))
                {
                    if (stored_username == "Username: " + Username && stored_password == "Password: " + Password)
                    {
                        cout << "Login Successful\n";


                        bool logged_in{ true };
                        int choice{};
                        Library library{};
                        Book book;

                        while (logged_in)
                        {
                            cout << "----------MENU----------\n";
                            cout << "------------------------\n";
                            cout << "1.View Books\n";
                            cout << "2.Check Book Availability\n";
                            cout << "3.Search and Borrow Books\n";
                            cout << "4.Return Books\n";
                            cout << "5.To Exit\n";


                            cout << "Enter a Number between 1-4 to beging Operation: ";
                            cin >> choice;

                            switch (choice)
                            {
                            case 1:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.id << ". "
                                        << book.title
                                        << " by "
                                        << book.author
                                        << '\n';
                                }
                                break;
                            }

                            case 2:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.title << " by "
                                        << book.author << " is "
                                        << (book.available ? "Available" : "Not Available")
                                        << '\n';

                                }
                                break;
                            }

                            case 3:
                            {
                                int search_id{};
                                cout << "Enter the search Id of the book you want to borrow: ";

                                cin >> search_id;
                                auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                    {
                                        return book.id == search_id;
                                    });

                                if (it == library.collection.end())
                                {
                                    cout << "Book Not Found\n";
                                    break;
                                }

                                if (count == 5)
                                {
                                    cout << "You Already have 5 books\n";
                                    break;
                                }

                                if (bookExists(it->id))
                                {
                                    cout << "Book Already Exists In Your Collection!\n";
                                    break;
                                }



                                if (it->available)
                                {
                                    std::ofstream file{ "borrowed_books.json" };

                                    file << "{\n";
                                    file << "  \"books\": [\n";

                                    file << "    {\n";
                                    file << "      \"id\": " << it->id << "," << '\n';
                                    file << "      \"title\": \"" << it->title << "\"" << "," << '\n';
                                    file << "      \"author\": \"" << it->author << "\"" << "," << '\n';
                                    file << "      \"year\": " << it->year << "," << '\n';
                                    it->available = false;
                                    file << "      \"available\": " << std::boolalpha << it->available << '\n';
                                    file << "    },\n";

                                    file << "  ]\n";
                                    file << "}\n";
                                    file.close();

                                    string line{};
                                    vector<string>lines{};
                                    char option{};

                                    int num{ 4 };

                                    std::ifstream file1{ "borrowed_books.json" };

                                    while (std::getline(file1, line))
                                    {
                                        lines.push_back(line);
                                    }
                                    file1.close();

                                    for (size_t i = 0; i < 4; ++i)
                                    {
                                        cout << "You can " << num << " more books continue ? : ";
                                        cin >> option;

                                        if (option == 'y' || option == 'Y')
                                        {
                                            for (size_t j = 0; j < lines.size(); ++j)
                                            {
                                                if (lines[j].find(']') != std::string::npos)
                                                {
                                                    cout << "Enter the search Id of the book you want to borrow: ";
                                                    cin >> search_id;

                                                    auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                                        {
                                                            return book.id == search_id;
                                                        });

                                                    if (it == library.collection.end())
                                                    {
                                                        cout << "Book Not Found\n";
                                                        break;
                                                    }

                                                    it->available = false;

                                                    lines.insert(lines.begin() + j,
                                                        {
                                                            "    {",
                                                            "      \"id\": " + std::to_string(it->id) + ",",
                                                            "      \"title\": \"" + it->title + "\",",
                                                            "      \"author\": \"" + it->author + "\",",
                                                            "      \"year\": " + std::to_string(it->year) + ",",
                                                            "      \"available\": " + std::string(it->available ? "true" : "false"),
                                                            "    },"

                                                        });




                                                    num -= 1;

                                                    std::ofstream file{ "borrowed_books.json" };
                                                    for (const auto& x : lines)
                                                    {

                                                        file << x << '\n';
                                                    }
                                                    break;

                                                }
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }


                                else
                                {
                                    cout << "Book Not Available\n";
                                }
                                break;
                                }
                           
                            case 4:
                            {
                                char choiceYN{};
                                do
                                {
                                   

                                    int book_ID{};

                                    cout << "Enter the Id of the book you wanna return: ";
                                    cin >> book_ID;

                                    if (bookExists(book_ID))
                                    {
                                        vector<string>lines{};

                                        string line{};

                                        std::ifstream file{ "borrowed_books.json" };

                                        while (std::getline(file, line))
                                        {
                                            lines.push_back(line);
                                        }

                                        for (size_t i = 1;i < lines.size(); ++i)
                                        {
                                            if (lines[i].find("\"id\"") != string::npos)
                                            {
                                                string stored_id = lines[i];
                                                stored_id = stored_id.substr(12);
                                                stored_id.erase(stored_id.size() - 1);

                                                int new_stored_id = stoi(stored_id);

                                                if (new_stored_id == book_ID)
                                                {
                                                    lines.erase(lines.begin() + i - 1, lines.begin() + i + 6);
                                                    break;
                                                }
                                            }
                                        }
                                        std::ofstream file1{ "borrowed_books.json" };
                                        for (const auto& x : lines)
                                        {

                                            file1 << x << '\n';
                                        }
                                    }

                                    cout << "Do you want to continue ??  (q to quit): ";
                                    cin >> choiceYN;
                                } while (choiceYN != 'q');
                                break;
                            }
                            case 5:
                            {
                                logged_in = false;
                                break;
                            }
                            default:
                            {
                                cout << "Invalid Option\n";
                            }
                        }


                    }


                }

            }

           
        }
       

        else if (option == 3)
        {
            cout << "See You Again\n";
        }
    }

    while (option != 3);



    return 0;
}

bool userExists(const string& username)
{
    string stored_username{};

    std::ifstream file{ "login.txt" };

    if (!file)
    {
        cerr << "file cannot be opened for reading\n";
        return false;
    }

    while (std::getline(file, stored_username))
    {
        if (stored_username == "Username: " + username)
        {
            cout << "Checking.....\n";
            return true;
        }
    }
    return false;
}

bool bookExists(int id)
{
    string stored_id{};

    std::ifstream file{ "borrowed_books.json" };
    std::getline(file, stored_id);
    std::getline(file, stored_id);
   

    while (std::getline(file, stored_id))
    {
        if (stored_id.find("\"id\"") != std::string::npos)
        {
            stored_id = stored_id.substr(12);
            stored_id.erase(stored_id.size() - 1);
            int new_id = std::stoi(stored_id);

            if (new_id == id)
            {
                cout << "Book Found\n";
                return true;
            }
        }

    }
    return false;
}

Today I just built a solid Library system :Chadge:.
Very soon I'll Work with real databases :Chadge:

Say No To VibeCoding :Chadge:
Say NO to AI :Chadge:

If you build projects with AI my nigga just rope at this point you are not a real developer :feelsrope:.

Very Very Soon I'll build something like facebook and become a billionaire :feelshah:.

HAHAHAHAHAHAHAAHA KEEP ROTTING INCELS :feelskek::feelskek::feelskek::feelskek:
I'LL GET INVESTMENTS FOR MY APP :feelskek::feelskek::feelskek::feelskek:
AND WILL BECOME THE KING OF SILICON VALLEY :feelskek::feelskek::feelskek::feelskek:
Never knew this was impressive, my dad and siblings are all in IT and have Cisco books on not just C+ but the whole lot :p, I'm not interested though
 
  • +1
  • Hmm...
Reactions: sub1foidslayer and FunnyVALENTINE
This is some first year bs. Good luck getting a job in the future, im in the same boat as u. Only way is to become an entrepreneur
 
  • +1
Reactions: Riley209711 and FunnyVALENTINE
This is some first year bs. Good luck getting a job in the future, im in the same boat as u. Only way is to become an entrepreneur
Bro I'm only one month into this game :Chadge:
What year are you in :HMMMM:?
Also I'm self learning don't go to any university :hmmNice:.

What is your experience :HMMMM:?
 
  • +1
Reactions: Riley209711 and overdose
Starting my masters studies next semester
 
  • +1
Reactions: Riley209711 and FunnyVALENTINE
Bro I'm only one month into this game :Chadge:
What year are you in :HMMMM:?
Also I'm self learning don't go to any university :hmmNice:.

What is your experience :HMMMM:?
are you still in highschool? if ur going to go to uni its good to get some prior knowledge by self learning but if ur past that don't self learn tbh. either go to uni or don't waste your time because the job market is alr pretty cooked for people with degrees so imagine how difficult it will be without a degree.
 
  • +1
Reactions: FunnyVALENTINE
are you still in highschool? if ur going to go to uni its good to get some prior knowledge by self learning but if ur past that don't self learn tbh. either go to uni or don't waste your time because the job market is alr pretty cooked for people with degrees so imagine how difficult it will be without a degree.
Bro I'm 23 and neeting :Chadge:.
Nigga I'm an arrogant mentalcel who burned all his bridges :Chadge:
 
  • +1
Reactions: Riley209711
Nope also i don't wanna waste money
may i ask why not? it's good to not want to waste money but this is something that's worth it. i mean, if you expect to find a job in the future(especially in CS) u should at least try to graduate. a lot of companies wont hire u if you dont have a degree.
 
  • +1
Reactions: FunnyVALENTINE
Companies arent looking for people who are new in the industry bcs seniors can code with ai better. So only way to get a job is to have a degree and have your own projects to show. We are all doomed
 
  • +1
Reactions: Riley209711 and FunnyVALENTINE
may i ask why not? it's good to not want to waste money but this is something that's worth it. i mean, if you expect to find a job in the future(especially in CS) u should at least try to graduate. a lot of companies wont hire u if you dont have a degree.
Tbh I wanna be a solo dev and I'm already on intermediate level compared to beginner :DankPepe: .

I just need to gain even more knowledge and widen my understanding a bit and then boom Im gonna mog most dudes :Chadge:.

I'm gonna do this in a span of 6 months :MLADY:

Im gonna learn qt and openGL and boom :MLADY:.

I want to build a solo project :Chadge:
 
  • +1
Reactions: Riley209711
Coding seems like an incredibly important skill to learn ik some basic python and sql but I need to lock in
 
  • +1
Reactions: FunnyVALENTINE
Companies arent looking for people who are new in the industry bcs seniors can code with ai better. So only way to get a job is to have a degree and have your own projects to show. We are all doomed
fr bro even mfs with a degree are struggling in CS. degree is the bare minimum
 
  • +1
Reactions: FunnyVALENTINE
C++:
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cctype>
#include<filesystem>
#include<algorithm>
#include<random>
#include<bitset>
#include<set>
#include<string_view>
#include<memory>
#include<cmath>
#include<cctype>
#include<fstream>

using std::vector;
using std::string;
using std::unordered_map;
using std::bitset;
using std::cout;
using std::cin;
using std::cerr;

class Book
{
public:
    int id{};
    string title{};
    string author{};
    int year{};
    bool available{};
};

class Library
{
public:
    vector<Book> collection =
    {
        {1,"The Hobbit","J.R.R. Tolkien", 1937, true},
        {2,"1984", "George Orwell", 1949, true},
        {3,"To Kill A Mockingbird", "Harper Lee", 1960, true},
        {4, "The Great Gatsby", "F.Scott Fitzgerald", 1925,true},
        {5, "Pride and Prejudice", "Jane Austen", 1813, true},
        {6, "The Cather In The Rye", "J.D.Salinger", 1951, true},
        {7, "The Alchemist", "Paulo Coelho", 1988, true},
        {8, "The Da Vinci Code", "Dan Brown", 2003, true},
        {9, "Clean Code", "Robert C Martin", 2008, true},
        {10, "The Pragmatic Programmer", "Andrew Hunt & David Thomas", 1999, true}

    };
};

bool userExists(const string& username);

class User
{
public:
    string username{};
    string password{};
    bool existing_user{};

    void input()
    {
        bool valid_name{};

        do
        {
            existing_user = false;
            valid_name = true;

            cout << "Enter Your UserName: ";
            std::getline(cin >> std::ws, username);

            if (username.length() < 8 or username.length() > 20)
            {
                cout << "Username should not be less than 8 or more than 20 characters\n";
                valid_name = false;
            }

            else if (userExists(username))
            {

                cout << "UserName already exists\n";
                cout << "Choose a different username or If you have an account login to it\n";
                cout << '\n';
                valid_name = false;
                existing_user = true;
                return;
            }

            for (char c : username)
            {
                if (!std::isalnum(static_cast<unsigned char>(c)))
                {
                    cout << "Username Should only contain Alphabets or numericals\n";
                    valid_name = false;
                    break;
                }
            }
        } while (!valid_name);


        bool valid_password{};
        bool is_upper{};
        bool is_digit{};
        bool is_symbol{};

        do
        {
            valid_password = true;
            is_upper = false;
            is_digit = false;
            is_symbol = false;

            cout << "Enter a Password Between 8-20 characters: ";
            cin >> password;

            if (password.length() < 8 or password.length() > 20)
            {
                cout << "Password should not be above 8 or 20 characters\n";
                valid_password = false;
            }


            for (char c : password)
            {
                if (std::isupper(static_cast<unsigned char>(c)))
                {
                    is_upper = true;
                }
                if (std::isdigit(static_cast<unsigned char>(c)))
                {
                    is_digit = true;
                }
                if (std::ispunct(static_cast<unsigned char>(c)))
                {
                    is_symbol = true;
                }
            }

            if (!is_upper)
            {
                cout << "Password must contain alteast one uppercase letter\n";
                valid_password = false;
            }
            if (!is_digit)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }
            if (!is_symbol)
            {
                cout << "Password must contain alteast one digit\n";
                valid_password = false;
            }

        } while (!valid_password);
    }
};

bool bookExists(int id);

int main()
{
   

    User a;
    int option{};

    do
    {
        cout << "------------------MAIN MENU------------------\n";
        cout << "1.Sign Up and Register to start borrowing books\n";
        cout << "2.Login and Explore the Library to borrow and exchange books\n";
        cout << "3.Exit\n";

        cout << "Enter a number between 1-3 to begin operation: ";
        cin >> option;

        if (option == 1)
        {
            a.input();
            if (!a.existing_user)
            {
                std::ofstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for writing\n";
                }

                file << "Username: " << a.username << '\n';
                file << "Password: " << a.password << '\n';
                file.close();
            }
        }

        else if (option == 2)
        {
            int count{};
            string s_ID{};

            std::ifstream file3{ "borrowed_books.json" };
            if (!file3)
            {
                cerr << "File will be created once you borrow your first book\n";
            }

            while (std::getline(file3, s_ID))
            {
                if (s_ID.find("\"id\"") != string::npos)
                {
                    ++count;
                }
            }


           
                string stored_username{};
                string stored_password{};

                string Username{};
                string Password{};

                std::ifstream file{ "login.txt" };

                if (!file)
                {
                    cout << "File cannot be opened for reading\n";
                }

                cout << "Enter Your Username\n";
                std::getline(cin >> std::ws, Username);

                cout << "Enter Your Password\n";
                cin >> Password;

                while (std::getline(file, stored_username) && std::getline(file, stored_password))
                {
                    if (stored_username == "Username: " + Username && stored_password == "Password: " + Password)
                    {
                        cout << "Login Successful\n";


                        bool logged_in{ true };
                        int choice{};
                        Library library{};
                        Book book;

                        while (logged_in)
                        {
                            cout << "----------MENU----------\n";
                            cout << "------------------------\n";
                            cout << "1.View Books\n";
                            cout << "2.Check Book Availability\n";
                            cout << "3.Search and Borrow Books\n";
                            cout << "4.Return Books\n";
                            cout << "5.To Exit\n";


                            cout << "Enter a Number between 1-4 to beging Operation: ";
                            cin >> choice;

                            switch (choice)
                            {
                            case 1:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.id << ". "
                                        << book.title
                                        << " by "
                                        << book.author
                                        << '\n';
                                }
                                break;
                            }

                            case 2:
                            {
                                for (const auto& book : library.collection)
                                {
                                    cout << book.title << " by "
                                        << book.author << " is "
                                        << (book.available ? "Available" : "Not Available")
                                        << '\n';

                                }
                                break;
                            }

                            case 3:
                            {
                                int search_id{};
                                cout << "Enter the search Id of the book you want to borrow: ";

                                cin >> search_id;
                                auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                    {
                                        return book.id == search_id;
                                    });

                                if (it == library.collection.end())
                                {
                                    cout << "Book Not Found\n";
                                    break;
                                }

                                if (count == 5)
                                {
                                    cout << "You Already have 5 books\n";
                                    break;
                                }

                                if (bookExists(it->id))
                                {
                                    cout << "Book Already Exists In Your Collection!\n";
                                    break;
                                }



                                if (it->available)
                                {
                                    std::ofstream file{ "borrowed_books.json" };

                                    file << "{\n";
                                    file << "  \"books\": [\n";

                                    file << "    {\n";
                                    file << "      \"id\": " << it->id << "," << '\n';
                                    file << "      \"title\": \"" << it->title << "\"" << "," << '\n';
                                    file << "      \"author\": \"" << it->author << "\"" << "," << '\n';
                                    file << "      \"year\": " << it->year << "," << '\n';
                                    it->available = false;
                                    file << "      \"available\": " << std::boolalpha << it->available << '\n';
                                    file << "    },\n";

                                    file << "  ]\n";
                                    file << "}\n";
                                    file.close();

                                    string line{};
                                    vector<string>lines{};
                                    char option{};

                                    int num{ 4 };

                                    std::ifstream file1{ "borrowed_books.json" };

                                    while (std::getline(file1, line))
                                    {
                                        lines.push_back(line);
                                    }
                                    file1.close();

                                    for (size_t i = 0; i < 4; ++i)
                                    {
                                        cout << "You can " << num << " more books continue ? : ";
                                        cin >> option;

                                        if (option == 'y' || option == 'Y')
                                        {
                                            for (size_t j = 0; j < lines.size(); ++j)
                                            {
                                                if (lines[j].find(']') != std::string::npos)
                                                {
                                                    cout << "Enter the search Id of the book you want to borrow: ";
                                                    cin >> search_id;

                                                    auto it = std::find_if(library.collection.begin(), library.collection.end(), [search_id](const Book& book)
                                                        {
                                                            return book.id == search_id;
                                                        });

                                                    if (it == library.collection.end())
                                                    {
                                                        cout << "Book Not Found\n";
                                                        break;
                                                    }

                                                    it->available = false;

                                                    lines.insert(lines.begin() + j,
                                                        {
                                                            "    {",
                                                            "      \"id\": " + std::to_string(it->id) + ",",
                                                            "      \"title\": \"" + it->title + "\",",
                                                            "      \"author\": \"" + it->author + "\",",
                                                            "      \"year\": " + std::to_string(it->year) + ",",
                                                            "      \"available\": " + std::string(it->available ? "true" : "false"),
                                                            "    },"

                                                        });




                                                    num -= 1;

                                                    std::ofstream file{ "borrowed_books.json" };
                                                    for (const auto& x : lines)
                                                    {

                                                        file << x << '\n';
                                                    }
                                                    break;

                                                }
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }


                                else
                                {
                                    cout << "Book Not Available\n";
                                }
                                break;
                                }
                           
                            case 4:
                            {
                                char choiceYN{};
                                do
                                {
                                   

                                    int book_ID{};

                                    cout << "Enter the Id of the book you wanna return: ";
                                    cin >> book_ID;

                                    if (bookExists(book_ID))
                                    {
                                        vector<string>lines{};

                                        string line{};

                                        std::ifstream file{ "borrowed_books.json" };

                                        while (std::getline(file, line))
                                        {
                                            lines.push_back(line);
                                        }

                                        for (size_t i = 1;i < lines.size(); ++i)
                                        {
                                            if (lines[i].find("\"id\"") != string::npos)
                                            {
                                                string stored_id = lines[i];
                                                stored_id = stored_id.substr(12);
                                                stored_id.erase(stored_id.size() - 1);

                                                int new_stored_id = stoi(stored_id);

                                                if (new_stored_id == book_ID)
                                                {
                                                    lines.erase(lines.begin() + i - 1, lines.begin() + i + 6);
                                                    break;
                                                }
                                            }
                                        }
                                        std::ofstream file1{ "borrowed_books.json" };
                                        for (const auto& x : lines)
                                        {

                                            file1 << x << '\n';
                                        }
                                    }

                                    cout << "Do you want to continue ??  (q to quit): ";
                                    cin >> choiceYN;
                                } while (choiceYN != 'q');
                                break;
                            }
                            case 5:
                            {
                                logged_in = false;
                                break;
                            }
                            default:
                            {
                                cout << "Invalid Option\n";
                            }
                        }


                    }


                }

            }

           
        }
       

        else if (option == 3)
        {
            cout << "See You Again\n";
        }
    }

    while (option != 3);



    return 0;
}

bool userExists(const string& username)
{
    string stored_username{};

    std::ifstream file{ "login.txt" };

    if (!file)
    {
        cerr << "file cannot be opened for reading\n";
        return false;
    }

    while (std::getline(file, stored_username))
    {
        if (stored_username == "Username: " + username)
        {
            cout << "Checking.....\n";
            return true;
        }
    }
    return false;
}

bool bookExists(int id)
{
    string stored_id{};

    std::ifstream file{ "borrowed_books.json" };
    std::getline(file, stored_id);
    std::getline(file, stored_id);
   

    while (std::getline(file, stored_id))
    {
        if (stored_id.find("\"id\"") != std::string::npos)
        {
            stored_id = stored_id.substr(12);
            stored_id.erase(stored_id.size() - 1);
            int new_id = std::stoi(stored_id);

            if (new_id == id)
            {
                cout << "Book Found\n";
                return true;
            }
        }

    }
    return false;
}

Today I just built a solid Library system :Chadge:.
Very soon I'll Work with real databases :Chadge:

Say No To VibeCoding :Chadge:
Say NO to AI :Chadge:

If you build projects with AI my nigga just rope at this point you are not a real developer :feelsrope:.

Very Very Soon I'll build something like facebook and become a billionaire :feelshah:.

HAHAHAHAHAHAHAAHA KEEP ROTTING INCELS :feelskek::feelskek::feelskek::feelskek:
I'LL GET INVESTMENTS FOR MY APP :feelskek::feelskek::feelskek::feelskek:
AND WILL BECOME THE KING OF SILICON VALLEY :feelskek::feelskek::feelskek::feelskek:
Inb4 I copy paste into Vscode and press run, my account gets repbotted to Gandy Heaven
 
  • JFL
Reactions: FunnyVALENTINE and Riley209711
Inb4 I copy paste into Vscode and press run, my account gets repbotted to Gandy Heaven
Bhai are you a coder as well :HMMMM:?

How long have you been coding :HMMMM:?
 
  • +1
Reactions: LXR
Thats the point, I am not a coder. Thats what I meant to say.
Oh no problem bhai when you mentioned vscode i thought you were a coder :hmmNice:
 
  • +1
Reactions: LXR
  • +1
Reactions: FunnyVALENTINE
Thats coz I did homework for Computer Science in school in VScode
School teaching computer science :hmmNice:?!?
My school didn't do that :ogre:
 
  • Woah
Reactions: LXR
They taught how to do addition and subtraction in C++:lul:
Bro are you ICSE, Cambridge, IGCSE board :feelsthink:?
Cause I went to dogshit SSC :lasereyes:
 
  • +1
Reactions: LXR
Move to san fran QUICK
 
  • JFL
Reactions: FunnyVALENTINE
State Board
So you an SSC dude as well :DankPepe:?

So what age are you :HMMMM:??
Is this the new curriculum :HMMMM:??

Caus emy school wasn't like that :ogre:
 
  • +1
Reactions: LXR

Similar threads

_MVP_
Replies
0
Views
14
_MVP_
_MVP_
lifeless
Replies
5
Views
36
alurmo
alurmo
user83793
Replies
0
Views
22
user83793
user83793
chudcell999
Replies
24
Views
126
chudcell999
chudcell999

Users who are viewing this thread

Back
Top