Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// What is Object Oriented Programming (OOP) ////
- // I still remember my first days when I first attempted to learn how to code. Those dark nights with the blue glow against my face.
- // It was very intimidating at first. I literally had just typed in the word "How to program" and there were an endless scroll of
- // Google results that always gave me a different answer with each click. Being a naive person, I simply just click on the first
- // few search results. Click. Click. I checked out a couple of blog post, Quora posts, and Reddit. They were all very helpful, but
- // the biggest problem of them all....
- // Every site had a different answer. Oh god...I never had a straight answer. I even went on Coursera and Edx to attempt to look at
- // the curriculum...Yeah, there were pretty taunting at first. Questions, quizzes, exams. The videos were all very entertaining, but
- // I felt too much of a newb and I really struggle hard to acquire the right skills of a developer. (Props to those who are self-
- // taught). I felt like I needed something more structured and broken down. And thus.. This is how the long journey goes.
- // Week 1 - I need to know how to basics.
- // I have seen it all. From the "Learn on your phone, it's easy!" to "Coding Is Easy as 1,2,3" So encouraging! I love it!!
- // This is all they all begin. Simple syntax learning. Ummm. Hey, isn't this a book? Where do I code?
- // Good question...Umm..Let's start with a simple website! Cpp.sh (C++ shell). You may use any other editor, but for this
- // chapter's sake. We are starting with cpp.sh.
- // Upon pulling up the page, you should get something like this.
- //----------------------------------
- // Week 1 : Understanding The Output
- //----------------------------------
- // Yuck. This is some ugly code already.
- // What am I looking at? This looks so fun, doesn't it?
- // When I first started, I didn't know what this all meant either and I was basically told
- // to ignore everything and just listen to the steps.
- // Well...That was helpful...for a bit, but that didn't really contribute to my learning.
- // I really need to break down on everything and that is how I really learn.
- // So let's start!
- #include <iostream>
- #include <string>
- int main()
- {
- // (Thoughts) - To be honest, I really don't know what it all means at the moment.
- // I think they should have given us a more easier example.
- std::string name;
- std::cout << "What is your name? ";
- getline (std::cin, name);
- std::cout << "Hello, " << name << "!\n";
- }
- //----------------------------------
- // Week 1.1 : Simple Code
- //----------------------------------
- // How about we start with this instead?
- // Copy everything below and paste it into your editor of choice. (cpp.sh?)
- #include <iostream>
- int main()
- {
- std::cout << "Whoa, whoa, whoa!!! I'm alive!!! ";
- }
- //----------------------------------
- // Week 1.2 : Output - First Crack
- //----------------------------------
- // So, I copied the code into cpp.sh and ran it.
- // I saw on the bottom, the words "Whoa, whoa, whoa!!! I'm alive!!! "
- // That is pretty creepy... I wonder what happened?
- // 1) Try changing the words in the " ", and try running the program again.
- // *****What happened?
- // I saw that the words changed. Hmm. Okay, interesting.
- // Why not, we make our own sentence now?
- // ******Fill in the blank
- // ________ << "I'm some code";
- // Now, take this line above and try inserting into your code.
- // I wrote an example answer in the next section.
- //----------------------------------
- // Week 1.25 : Output Code - Example
- //----------------------------------
- #include <iostream>
- int main()
- {
- std::cout << "Whoa, whoa, whoa!!! I'm alive!!! ";
- std::cout << "I'm some code";
- }
- //----------------------------------
- // Week 1.3 : Output - Second Crack
- //----------------------------------
- // To be honest, I really don't know what I did.
- // I literally copied that strange std::cout line and change the words inside the "".
- // Yeah, that is basically it. That was literally my first lesson.
- // I don't know what happened, but try to what some of the syntax means.
- // Let's breakdown this line of code
- // std::cout << "Whoa, whoa, whoa!!! I'm alive!!! ";
- // What is std::cout?
- // std::cout means Standard C Output
- // Whenever, I write this word, it means that I want to output something onto the screen.
- // What is << ?
- // << is one of the operator overloads.
- // The exact name for "<<" is insertion operator.
- // Whenever we use "<<", we want to insert something into something.
- // std::cout << "Whoa, whoa, whoa!!! I'm alive!!! ";
- // ****Can you find what is happening in this screen now?
- // Basically, we are taking the sentence within "", and inserting it into the standard output or aka, our screen.
- // Now let's take a look at some more lines.
- // #include <iostream>
- // int main()
- // {
- // std::cout << "Whoa, whoa, whoa!!! I'm alive!!! ";
- // std::cout << "I'm some code";
- // }
- // What is #include <iostream>
- // This line is read as "include input and output stream".
- // This is considered as a "library header". Which acts a unique code empower.
- // For example, if we were to type in the words std::cout on its own, without the library
- // header <iostream>, then std::cout would have no usage and looks like gibberish to the computer.
- // However, when we add #include <iostream> to the top of our program, this grants unique abilities
- // to a series of words. Now std::cout translates and holds the meaning of
- // standard C-Out and it makes sense to the computer. Now does it make sense that it is called a library header now?
- // What is int main()?
- // I spent a long time trying to figure out what this was. Nobody actually told me and using Google was too complicated.
- // After figuring out what it was, I found out it was called the main function. Basically, this main function is a signal to
- // the computer to start here or "THIS IS LINE 1". No matter how big your code is, 100, 500, or 1000. The computer will start at
- // int main() because you told the computer that is line 1!
- // What are { } ?
- // These are brackets. They just hold code and it belongs to watever it is on top.
- // Codie Monster
- // { everything inside these brackets belong to Codie Monster }
- //----------------------------------
- // Week 1.4 : Exercise 1 - Make your own code
- //----------------------------------
- // Based on what you learned so far, try writing your own code and getting it to work in cpp.sh.
- // Try it and then paste your code into this box.
- // ***************
- //----------------------------------
- // Week 2 : If and Else Statements
- //----------------------------------
- // Okay, so I know how to output a couple of sentences onto the screen. A week should have already passed if I were studying this on // my own. Outrageous isn't it? I remembered when I first started, I was told to go install this, go install that, make this run.
- // It felt like a cat and mouse game. I kept on moving around and I didn't know if I was making any progress or not. There were
- // so many code editors out there and I didn't know which was good or not. No tutorial was there to help and it basically took me
- // almost a week to get my first code out. Very strange indeed.
- // By now, the most infamous "Hello World" example should be a breeze and accomplishmentable.
- // Hint: (Just output "Hello World")
- // I am or should be ready to tackle problems!! Yes? Let's start!
- // The next on the list are "If and While Statements".
- //----------------------------------
- // Week 2.1 : If Statements
- //----------------------------------
- // What does the word "If" mean in English?
- // I remembered when I first taught English, this was also a very important "grammar structure" that most of my ESOL students
- // had to learn. The way I structured it was...
- // If ..... Then.....
- // If I went to play ball, then the dogs would come out.
- // If (condition), then (action)
- // In code, this follows the exact structure.
- // Here is the syntax for if C++ statements.
- // if (condition)
- // {then this code run};
- //----------------------------------
- // Week 2.15 : If Statements Example Code
- //----------------------------------
- // Try running the code below and see if it works or not.
- // Then try
- #include <iostream>
- int main()
- {
- int x = 10;
- if (x = 10)
- {
- std::cout << "Yes, X is 10";
- }
- else
- {
- std::cout << "No, X does not equal 10";
- }
- }
- //----------------------------------
- // Week 2.175 : If Statements Example Code Comment
- //----------------------------------
- // What the? Did I see an extra line of code?
- // What are these extra line of codes?
- // Well, let's break it down.
- // int x = 10;
- // x is the variable name. A variable name is a name that you
- // use to label any variable. It can be x, y, hotdog, pizza, anything you want.
- // int is short for integer.
- // An integer is a number that is whole; -200, 5, 75.
- // int is the datatype that you decided for the variable.
- // Example:
- // When I tell you that I have the letter X in my hand and it means something,
- // that doesn't really help much. However, when I tell you that this letter X is an integer,
- // now it brings a lot more info to the table. Oh, so I see that the X in my hand is an integer!
- // Now afterward, we must set the value of the X, in which we add the "=" symbol and now X equals 10.
- // A datatype is used for clarification purposes and allows us to understand what type of data we are working with.
- // When declaring (creating) new variables, we must set the datatype before the variable name.
- // Declaring
- // int y;
- // Intializing (setting a value to a variable)
- // y = 10;
- // Declaring and Initializing
- // int z = 50;
- //// Else Statements ////
- // Now, what we saw an if statement, but we also saw an else too!
- // What does this mean overall?
- // In English, we would say...
- // If I am going to the park, I want to find a cheetah.
- // If I go to the park I want to find a cheetah, else I am going downtown to skateboard.
- // Mathematically...
- // If (this happens), then (do this)
- // If (this doesn't happen), else (this happens)
- // Fill in the blanks
- #include ________
- int main()
- {
- ___ hamburgers = _ ;
- if (hamburgers = 3)
- {
- std::cout __ "I am hungry";
- }
- else
- _________ << "I need money"_
- }
- //----------------------------------
- // Week 3 : While and For Statements
- //----------------------------------
- // Quick Review
- // Can you declare a variable?
- // Can you intialize a variable?
- // Can you declare and intialize a variable now?
- // After a week of trying to figure out "if and else statements", I felt like I was finally making some progress.
- // Is this really all to coding? If it is, then this is so easy! I mean, come on! If it is that easy, then I should be a pro
- // in no time! All I have to do is use these statements and mash up stuff together right? Easy as chicken pie...
- // Loop Statements
- // A statement that repeats if the conditions are true.
- // A way to repeat or a loop you may say.
- // While statements
- // In English, we would say...
- // While I am eating, I will watch TV.
- // While I am driving, I will not text.
- // Mathamatically
- // While (condition is true), do this.
- // Fill in the blank exercise
- #______ <iostream>
- int main()
- {
- ___ hamChicken = 3 ;
- while (hamChicken < 5)
- {
- _______ __ "ham ham ham";
- hamChicken = hamChicken + 1;
- }
- }
- // Bonus question: What does "hamChicken = hamChicken + 1" do?
- //// For Statements ////
- // For Statements are no different from a while loop. They are similar in every way,
- // but the only difference is the way it is structured.
- // Let's take a look at how it works.
- // Syntax:
- // for ( initization; condition; increment )
- // Example syntax:
- // for (int steak = 0; steak < 5; steak++)
- // Now, when I first saw this, I was immediately confused. This looks a bit heavy already and
- // does not makes a lot of sense for the normal person I am. I believed I spent many months just copying this structure and
- // not know exactly what it exactly does. One problem that really stood out to me was...What does initialization mean? What does
- // it really do? Um what? Which led to finally learn what a counter is.
- // Counters
- // A way to keep track of how many loops have occurred.
- // When using while loops, the counters are often found outside the while loop.
- // Here is a very clear example of how the two are structured. I believe I didn't know the exact difference until maybe now!
- // While Loop
- // int counter = 0;
- // while (counter < 3) {
- // counter++ }
- // For Loop
- // for (int counter = 0; counter < 3; counter++) {
- // }
- // Now, you may use a while loop or for loop; whichever you find more appropriate or likable for your needs.
- // They both do the exact thing. The only difference is preference and the while loop allows for more control on placement of the
- // counter.
- // Question 1
- // What if I put the counter inside the while loop?
- // Try creating your own while loop with a counter inside and explain how it works.
- // ************bow here
- // I did not know what it meant
- // Try writing your own for statement below
- // ***************
- //----------------------------------
- // Week 4 : Assessment Break
- //----------------------------------
- // Before moving on, I suggest developing a little bit and seeing if you can handle the material.
- // Problem:
- // Develop a code that solves this problem
- // Using a while or for loop, I would like to create a pizza delivery screen.
- // There are a total of 10 orders.
- // Every odd number order should be a "L Pizza + 1 Drink"
- // Every even number should be "XXL Pizza + Mystery Sauce"
- // The Output Should Look Like This
- // Pizza Order 1:
- // L Pizza + 1 Drink
- // Pizza Order 2:
- // XXL Pizza + Mystery Sauce
- // Pizza Order 3:
- // L Pizza + 1 Drink
- // Pizza Order 4:
- // XXL Pizza + Mystery Sauce
- //----------------------------------
- // Week 4 : Arrays
- //----------------------------------
- // It is now week 4. It has been nearly a month and I have barely covered over the basic syntax of coding. If this was an university
- // course, I believe they would already finished all of this by week 1! (Actually they really do. I took a real course at a university
- // and they quickly and thoroughly explained the differences in two weeks). But hey! I am just a single person learning on my own.
- // I don't want to hopping onto shiny toys, but rather I would take the time to really learn my foundation and seeing it how it all
- // work together.
- // English definition: ordered arrangement, in particular.
- // An array isn't all that complicated.
- // Syntax
- // datatype arrayName[arraysize];
- // The array size is how many elements do you want the array to have.
- // Declaration
- // int ticketNumbers[3];
- // Initization
- // ticket Numbers[3] = {0,3,4,5};
- // Declaring and initization
- // int ticketNumbers[3] = {0,3,4,5};
- // An array ic consist of elements.
- // We can access the elements of an array by calling its index.
- // Exercises
- int ticketNumber[3];
- ticketNumber[3] = {0,3,4,5};
- std::cout << ticketNumbers[1];
- // Try running this code.
- // What number do you get when you call the index at 1?
- // Try changing the index to 0, 3, 4, and 2. What numbers do you get?
- // List them below
- // What are the usages of arrays?
- // Say, I got a list of ID numbers. We can store different numbers into each list and access them based on their order.
- // int IDnumber[5] = {25,15,16,13,14}
- //----------------------------------
- // Week 5 : Functions
- //----------------------------------
- // If I was learning on my own, a year has already passed and I did not know the correct usage or meaning of a function.
- // I believe there are many ways to explain a function, but after so many online lessons and tutorials, I never did grasp
- // the meaning of a function. Is it because the material wasn't so in depth or I wasn't a great learner? When I took my first
- // programming class in university, we spent nearly a whole semester on understanding functions very throughly and
- // getting everything to work. It was very in depth and it explained a lot of things that I needed to know. Some books do
- // go into depths of breaking down a function and explaining it well and many online resources just skims it and explain
- // what is needed to be practical immediate.
- // For this section, I will do the hybrid approach of giving you the knownledge of what needs to be practical and going into
- // enough depth in what I believe is cruical for all developers.
- // Placement
- // There are two ways to place a function in C++
- // Standard Procedure
- // 1) Prototype
- // 2) Function Implementation
- // Immediate Implementation or Small Program
- // 1) Function Implementation above main
- // syntax
- // returnType functionName (datatype argument1, datatype argument2) {
- // };
- // function example
- // int formulaMath ( int input1, int input2){
- // }
- // A prototype (or function declaration) tells
- // the compiler the name, return type, number and type of parameters to expect
- // What is a function and what is it's purpose?
- // When I first learned this, it took me a while to figure out what a function really is.
- // There were many explanations about functions and what it did, but I never really understood it
- // until it was compared to an actual real-life example. In fact, a function works exactly like it
- // does in math.
- // If you recall Algebra I or II, a programming function is
- // exactly like the math function F(x). If you don't recall this concept, don't worry
- // instead here is a better metaphor to explain it.
- // A function is simply a set of instructions that accepts inputs, performs on it, and outputs it.
- // Still confused? Here is a diagram that I found really helpful.
- // This is a function -> [ ]
- // Now I am going to input some numbers into it and it is going to output a new number. Just watch.
- // 5 ---> [ ] --- > 10
- // Now, why did this happen?
- // A function is a set of operation. If we look inside at the diagram and see more of it.
- // 5 ---> [ x * 2 ] ---> 10
- // Hmm. Does this make sense now?
- // How about explaining it in this box
- // *******
- // Basically, this is what a function is except, it not only deals with numbers, but it could be any set of instructions.
- // We can create words and then use a function to alter the words too!
- ////// Parameters
- // Now that we understand what functions are, we can now push for the syntax understanding of a function.
- // int functionMath (int input1, int input2);
- // Looking at this prototype, we can break it down into pieces.
- // ( ) is considered the parameters, and we pass arguments, which would be the individual inputs.
- // Now, looking at the arguments, they are all integers. We are using integers inputs to insert into our function.
- // Next, do you notice the int before functionMath? That specific datatype is considered the return type. The return type
- // is the datatype that is returned by the function.
- // Take a look at the diagram again.
- // arguments (int) ---> [ functions] ----> returntype (int)
- // Basically, we have inputs that are integers and we are asking for an output that is also an integer.
- // And that is the returntype!
- //// Try explaining this concept down to a duck and see if it works.
- //
- // Is an Oreo cookie still an Oreo cookie without the filling inside?
- // Empty Functions - Be able to recognize them
- // A function that is empty doesn't accept or returns any information.
- // What is the use? Treat it as a skeleton for a function and be able to recognize it for the moment.
- //Section 1
- void emptyChickens();
- void noBeef( void );
- int main()
- {
- emptyChickens();
- noBeef();
- system("pause");
- }
- void emptyChickens()
- {
- std::cout << "This function has no arguments" << std::endl;
- }
- void noBeef ( void )
- {
- std::cout << "This function accept no arguments either" << std::endl;
- }
- // By now I guessing you may or may not know what void means and its usages
- // Can you explain what you think it means and its practical usages?
- // You may find more information on the web
- //----------------------------------
- // Week 6 : Pointers
- //----------------------------------
- // I remembered when I was studying object oriented at the university level and had visit the student tutor.
- // I had asked him to explain what is a pointer and can you explain it to me?
- // The only thing I recalled from that particular lesson was "follow the pointer". Yeah...That wasn't really that helpful.
- // To be honest, it took me a while to figure out what a pointer truly meant. Even today, I think my grasp of pointers is pretty good,
- // but my mastery of advance level of pointer still needs working. Let's start with the fundamentals first.
- // What is a pointer?
- // The best metaphor that I came up with is, a pointer is a finger and nothing more.
- // A finger can point at things and tell you what's at that specific location.
- // When it comes to development, a pointer is meant to "point" at a specific address and tell you what's at that address.
- // Is it an integer, is it a character, or is it a string? Who knows.
- // What is the purpose of a pointer?
- // To conserve memory and make efficient programs.
- // Instead of working with actual data, wouldn't it be easier just to point at what you need instead?
- // What I didn't know until recently is that a pointer can only point to three things.
- // A pointer can only point at another address, another pointer, or a null value. You can't have a pointer point at something else
- // besides these three.
- // So, let's start.
- // Declaring a pointer
- // There are three ways to declare a pointer, but they all mean the same thing.
- // int* pointer1;
- // int * pointer1;
- // int *pointer1;
- // I generally like the first declaration of the pointer.
- // What you see here is a "*" symbol, correct?
- // That just means that you have declared a pointer that is pointing to an int dataspace.
- // So, you must be dealing with integer only.
- // Intializing a pointer
- // int* pointer1 = 5;
- // pointer1 is pointing to the value of 5.
- // pointer1 is not the value of 5, but rather just points to it.
- // std::cout << pointer1;
- // When we perform this, we can see that pointer1 is the address of the value 5.
- // std::cout << *pointer1;
- // When we dereference pointer1 with *, we can now go to the address of pointer1 and see that there is a value of 5 at that address.
- // Exercises
- //
- // How to move a pointer
- // Now, we see that pointers can be used to point at a single object.
- // How about we see how pointers are used on a larger scale.
- int main()
- {
- // declare out first array
- int array[5] = {0,1,3,4,5};
- // declare our pointer and have intialize it to our array.
- // pointer1 is now equals to array.
- int* pointer1 = array;
- // This should output the first element of the array
- std::cout << *pointer1;
- // Now can you guess what these numbers are?
- std::cout << *(pointer1 + 2);
- std::cout << pointer1[3];
- }
- // Exercises Math Pointers****
- // How to use a pointer in a function
- // Pointer Math Exercises
- //----------------------------------
- // Week 7 : Dynamic Data with Pointers
- //----------------------------------
- //
- //----------------------------------
- // Week 8 : Classes 1 : Setting Up
- //----------------------------------
- //----------------------------------
- // Week 9 : Classes 2 : Inheritance
- //----------------------------------
- //----------------------------------
- // Week 10 : Classes 3 : Polymorphism
- //----------------------------------
Add Comment
Please, Sign In to add comment