C++ hierarchy of classes

Here is my small c++ program which makes use of hierarchy. Any feedback is welcome.

#include <iostream>
#include <string>
#include <stdlib.h>
class Form {
    protected:
        std::string c, d, f, x;
    public:
        void base() {
        std::cout << "Enter Username: ";
        std::cin >> d;
        std::cout << "Enter Password: ";
        std::cin >> c;
        system("clear");
        }
};
class pass1 : Form {
    public:
        void ethan() {
            while (c != "24090844" && d != "Ethan") {
                base();
            }
        }
};
class pass2 : Form {
    public:
        void Yeeter() {
            while (c != "4984" && d != "Yeeter") {
                base();
            }
        }
};
int main()
{
    pass1 object1;
    object1.ethan();
    int a;
    std::cout << "1 = Calc 2 = Money Manager";
    std::cin >> a;
    system("clear");
    if (a == 2){
        std::string c;
        pass2 object2;
        object2.Yeeter();
        int y, s, d, l;
        s = 4000;
        std::cout << "Would you like to withdrawl or add to your account:  ";
        std::cin >> c;
        system("clear");
        if (c == "add")
        {
            std::cout << "balance: " << s << std::endl  << std::endl  << std::endl ;
            std::cout << "How much do you want to deposit:  ";
            std::cin >> d;
            system("clear");
            std::cout << "Balance: " << s+l << std::endl << std::endl << std::endl;
            std::cout << "You total money is " << s+l;
        }
        if (c == "withdrawl")
        {
            std::cout << "balance: " << s <<std::endl  << std::endl << std::endl ;
            std::cout << "How mcuh do you want to take: ";
            std::cin  >> l;
            system("clear");
            std::cout << "Balance: " << s - l <<std::endl << std::endl <<std::endl;
            std::cout << "here is your money: " << l << std::endl;
        }
    }
    if (a == 1){
        std::string b;
        int flag = 0;
        char a;
        int r, d;
        while (flag==0) {
            std::cout << "enter the oporator: ";
            std::cin >> a;
            system("clear");
            std::cout << "Enter the numbers: ";
            std::cin >> r >> d;
            system("clear");
            switch (a)
            {
                case '+':
                    std::cout << r + d << std::endl;
                    break;
                case '-':
                    std::cout << r - d << std::endl;
                    break;
                case '*':
                    std::cout << r*d << std::endl;
                    break;
                case '/':
                    std::cout << r/d << std::endl;
                    break;
            }
            std::cout << "type 'again' to do another calcation: ";
            std::cin >> b;
            system("clear");
            if (b != "again")
            {
                flag = 1;
            }
        }
    }
return 0;
}
2 Likes

Great work Ethan!

I know you’re doing this stuff just to learn C++. Next step is to apply it to a real world project that you can solve with C++.

1 Like

i can tell he is trying to do that, he would ask me when we learn during lunch on what he should make, but i don’t have the best ideas.

Here’s an idea for a project:

Make a “madlibs” generator. Start with a template from a madlibs site (for example, check out http://www.madtakes.com ) and make a C++ program that will generate it for you.

It could ask the user to provide all the information (noun, occupation, verb, etc), like this:

and then generate a story based on that input.