Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Paper Discussion


class Print{

          private:
                    int maxsize;
                    int *pIDArray;
                    int front;
                    int rear;                    int nItems;
           public:
                     Print(int s);
                    ~Print();
                    void insert(int printJobID);
                     int remove();
                     int peekFront();
                     int isEmpty();
                     int isFull();
                     int size();}

Print::Print(int s)
{
          maxSize=s;
          pIDArray=new int[maxSize];
          front=0;
          rear=-1;
          nItems=0;
}

bool Print::isEmpty()
{
           return (nItems==0);
}

bool Print::isFull
{
            return (rear==maxSize-1);
}

int Print::size()
{
              return nItems;
}

void Print::insert(int printJobID)
{        if(isFull())
                 cout<<"The queue is full";
           else
             {
                pIDArray[++rear]=printJobID;
                nItems++;
             }
}

int Print::remove()
{
             if(isEmpty())
             {
                 cout<<"Print Queue is empty";
                 return -999;
              }
              else{
                       nItems--;
                       return pIDArray[front++];
              }
}

int Print::peekFront()
{
                if(isEmpty())
                {
                   cout<<"Queue is empty";
                   return -999;
                 }
                 else
                       return pIDArray[front];
}

OUR PROGRAMMING WORKSHOP :) -Part 2(2016-10-11)

    

        Hey guys.. This is the 2nd Part of our "Kuppi" in PDF format. If you miss the 1st part, I've put the link down below, Go and check.
     Actually there is a missing part in our workshop , that we couldn't discuss last time. It is at the end of this PDF. I'm hoping to do a video tutorial about that very soon. I'll manage you to receive that ASAP.
     In our next Kuppi I'm going to discuss some past papers of OOP. Hope you all will join that too. Bye.
Thank you :)
-Ravindu Shehan



OUR PROGRAMMING WORKSHOP :) -Part 1(2016-09-30)

          

       Hey Guys.. This post is created in purpose of sharing you the Notes of the KUPPI we had on last Friday.. Everybody who came that day..   I really enjoyed the time we spent together.. It was amazing...!!

          For the people who were there and also for the people who weren't , Here I post the link to download the PDF version of that KUPPI.(I thought it will be important for you guys)
          
          I am hoping to do the 2nd part of this KUPPI on next Tuesday Evening. If you are coming please inform me. And also if there is anything you think I should improve in my KUPPI please Inform me by commenting down here Thanks..


Thank you :)
-Ravindu Shehan

C++ Classes.






     Helllooo.... Readers... Welcome to inspire++. How are you my technical nerdy followers. The week before Last week was awesome. Thanks to the seniors from mechatronics.. We had a awesome workshop on robotics.. All the circuits, cool robots, drones you presented, the actual circuits we created using arduino boards most importantly the programming challenges you gave us !!! Truly seniors!! You did great. That was a day to remember.. :) 
That been said.. Owkayy!! Lets Jump in to the lesson today!!

Classes.
     The main purpose of C++ programming is to add object orientation to the C programming language and classes are the central feature of C++ that supports object-oriented programming and are often called user-defined types.

     Last week we talked what are objects. An object is an entity (Real world thing). In programming , an object is a thing either from the perspective of the user of the software or the programmer. 

     * Object has two components, Properties and Behaviors.

     Classes on the other hand known as blueprints (Plans) of objects. It's just like house planing. You build a house according to the plan. You can build as many houses as you want using the same plan, if you want to. For each house, you don't want to make a new plan. 

     In a program when you want to create an object, first what you have to do is create a class of that object. Then use the name of that class to create objects.

     For example , think you have to make a software to a company to record the details about their customers. So a customer has a name , company gives him a customer ID, From when this person is a customer of the company..etc, And the customer buy things , customer may be given a discount by company. 

     Ok.. When you look at this scene what you have to keep in mind is that there are more than one customer in a company (more than 1000 maybe). So you have to see that there is a pattern. The best thing to do is take all the common factors of each customer and make it an object. Means, Create a object to the customer.

     Right! , to create an object what we have to do is, as I mentioned earlier , create a class. Ok.. Now what I'm going to do is , create a class called customer. Let's see how to do that.

First Create the class.






     Then type the keyword public inside the class.


Look!! There is a Colon : after public!! (Not a semi Colon!! ; ) 




     Under public , define all the variables you want.
Ok! We have finished creating the class. Now it's time to create an object using that class (plan). Here's how you do it. 
     In main function, type the class name and leave a space ,and give a new name to your object (C1). 

Then here's how you use the properties of that object.


Did you got the idea. Ok! Just like that we can create any amount of objects we want.


See how simple the idea is. OK.. Now I want you to practice this concept. So here are some examples. I will give you the answers in the next post.

Practice:
     Create a Class named Box. Add variables Height , width , breadth. Create three Box objects in main function using that class. Give different values to the each object. Write a program to print the volumes of each box.

See you guys soon. Bye bye..!! :)






Introduction to OOP in c++


     Hey... Welcome to another episode of OOP with c++ post series. Today we are going to talk about very important topic in OOP. That is objects. What are objects? Why we want them.

Objects

     What are objects? Well objects are the real world things. Vehicles (Cars , bikes..etc) , Tools or instruments , humans , animals all those things we can consider as objects in OOP. 

     How objects are described or what are the components of objects? Well if we take car as the example, It has wheels, engine, seats,... etc. And it can be move or drive. If we take human as object he or she has a name, body parts, age, .... etc, and he or she can talk , walk, eat...etc.

     So the list goes on. What we can take from above examples is that objects have two major components.
An object has,
     1. Properties (State , Attributes)&
     2. Behaviors (Methods) .

For a car, wheels, number of seats,engine are it's properties. Driving is a behavior which belongs to car object. For humans, name,age,body parts are the properties and walking talking eating are the behaviors. I think you get the idea right! Properties means the things that belongs to an objects and behaviors are the things that objects can do... easy right!!

Did you know ?
     Although most of the Programming languages can be use to OOP and also for procedural programming(Normal Programming ;) ) . Java is known as a Pure Object Oriented Programming Language....

Abstraction.
     There is another important concept which is used in OOP called abstraction. What is abstraction.? When creating objects in a program we have to consider about the properties and behaviors of objects. If we consider a certain object it has so many properties and also it has so many behaviors. This is a trouble when creating objects. So instead of considering all the properties and behaviors of object we consider only on properties and behaviors which are important to us. 



     For example If we take car as the object and imagine you are a car sale owner. What are the properties most important to you in a car. Brand , Model , Engine capacity, top speed , price...etc. List goes on with normal things to promote the car. But instead of that list of properties there might be thousands of other properties to that car. But, they are useless for us car salesman s.  So what we do is omit all the unnecessary properties and behaviors and consider only on the ones important. This scenario is called Abstraction in OOP. 

      In object-oriented programming, abstraction is one of three central principles (along with encapsulation and inheritance). Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency.

     Ok..!!! So we learned about two major concepts in OOP today. I'm hoping to talk and also use these concepts within programs.. Keep in touch.. C U in my next post.. Bye..  :)

OOP :o :o :p (What is OOP , Why we want it)


     Hello Fellow Readers..  Welcome to inspire++ :) This post is specially for the people who are doing OOP now. Don't get confuse with this post , because we are still on the VARIABLES in our fundamental programming post series. OOP is a big set of lessons, so we have to do this also as a post series. This series will be continue parallel to our fundamental post series. OK... that being said..
Lets start..  

     When you have to create a big program , I mean really really big one , big enough to call it a software , we will have to do more and more coding. Sometimes we will have to re-type the same set of code-lines again and again. 


     This seems to be a big head-aching situation. So, as smart engineers what are the options do we have to do to reduce the time for coding and to reduce the pain occur when doing the same thing again and again.? 

     Well you might have the answer already. "C n P" or AKA Copy and Paste Method Right!! You type the set of code , copy it and paste wherever you want them to be in your source code. Easy!! 


     BUT!! it is not a wise method to follow for some Reasons. Imagine if there is an error or a Bug in your code , when you copy that set of codes to 20 different places in your source code , you will have the same error in 20 times and you will have to fix it 20 times repeatedly.  And imagine how your source code will look like. It will be very very long and it'll be really hard to keep working with .



  1. Duplicate code is a Bad Thing.
  2. More codes - Hard to work with. 

     So there is a big problem that haven't answered properly. Purpose of this post is to tell you how to solve this problem by introducing you the Concept of OOP-Object Oriented Programming. By the end of this post you will have an idea about what is OOP and Why we want it.


     Can you remember the lesson functions..Well in our Fundamental post series we haven't arrived that point yet, but I guess you guys have the idea of what is a function and how to use it..


     So in short, A function is a set of codes in your source code with a given name. It exist parallel to our main function. It does not do anything until we call it. Whenever we want we simply call the function in main function. 
     
     So instead of typing or copying the same set of code again and again in main function , we can create a function and call it when we want to execute them. This method is call function calling. So if there is any error in our code we only have to fix it in the function and whole program will fixed automatically. No need to fix same error 20 different places. 

     This concept is very helpful when understanding OOP. In software developing we use a developed version of this concept. Instead of using functions we use Classes and Objects  in OOP (Object Oriented Programming.) 

     By using Classes & Objects We Can,

  1.      Reduce duplicating codes.
  2.      Reduce the number of code lines in your main       function.

     And the whole program will become a User friendly neat and logical thing and it will be easy to work with. OK I think now you have an idea about why we want OOP right!!


     In OOP we create Classes - AKA the blueprints of the objects - Classes have Properties and Behaviors. And we create Objects (Real world things) using codes, and to make those objects feel real we encapsulate them, use inheritance and polymorphism to use them in advance. So as a terminology you can refer those red color words , those words will be the topics of our next posts. So stay with inspire++ to get a fully understand about OOP. Thank you guys..!! C U.. :) 
Next post>>>

Life of a Systems Engineer

  Hello, my dear readers. ✌😀✋ I'm talking to you after a very long time. And I am thrilled to talk-to and hear-from you after all thi...