Paper 2


class StackY
{
          private:
                      int maxSize;
                      int *stackArray;
                      int top;
           public:
                       StackY(int s);
                       ~StackY();
                       void push(int j);
                       int pop();
                       int peek();
                       bool isEmpty();
                       bool isFull();
}

StackY::StackY(int s)
{
          maxSize=s;
          stackArray = new int[maxSize];
          top=-1;
}

void StackY::push(int j)
{
           if(isFull())
                cout<<"Stack is full cannot insert";
            else
                 stackArray[++top]=j;
}

int StackY::pop()
{
          if (isEmpty())
          {
                cout<<"The Stack is empty";
                return -999;
           }
            else
                  return stackArray[top--];
}

int StackY::peek()
{
          if(top==-1)
          {
                 cout<<"The stack is empty";
                 return stackArray[top];
           }
            else
                  return stackArray[top];
}

bool StackY::isEmpty()
{
           if( top==-1) return 1; else return 0;
}

bool StackY::isFull
{
       
            if (top == maxSize) return 1; else return 0;
}

int StackY::peek()
{
          if (top==-1)
          {
                cout<<"The stack is empty";
                return -999;
           }
           else
                 return stackArray[top];
}

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];
}

C++ Operators

 

   :) Hello Reader..  Good  Day!/Morning!/Evening! to you. (According to the time you are reading this post). You are welcome to "The inspirational blog for programming", inspire++. Today we are going to make some cool , amazing & simple programs and spend some good time together. :) So.. Come with me for the next 20 minutes.

     We know how to create variables. Can you remember? Yes it is really simple. All you have to do is just three things.


  1. Decide what type of variable we want. (ex: It may be int , float , string , char or boolean)
  2. Leave a Space & Decide a name for our variable. (ex: name , age , height , etc)
  3. Finally, Assign a value to it. 
ex: int age;
     age = 25;
     Here first we decided the type of the variable ( int ), secondly we gave it a name ( age ), and finally we assigned a value to it. ( 25 ).

     Though we did this in 2 lines we could do this in a single line too.
ex: int age=25;     float height = 6.1; string name = "shehan"; 

     Now if we want to print those values , we can do that by using   cout   function,
ex: cout<< "My name is "<< name<<" and I'm "<<height<<" ft tall "<<endl;

     Ok. As you can see in above example , you can assign values to your variables. But I feel it is not enough. Don't you feel the same? If the only thing we can do with variables is just assigning values and that's all? I'm not happy with that..!! We want to do things with variables. Right?!

     So is it possible? If so.., then what  else we can do with variables? How can we do that?.. Well! that's where we need operators...

     " C++ Operators " are the bad guys in the language, who can get things done. They are really cool. They can easily manipulate any variable or values to do different operations.

     C++ has different types of operators to do different different things to our variables. 



  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Misc Operators


     Let's think we want to add the values of  two variables. We can use + addition , which is an Arithmetic operator.

ex: int a=5; int b=10; int c;
       c=a+b;
       cout<<c<<endl;
     There are specific operator for each Arithmetic operation in C++.

  • +     -     Addition.
  • -      -     Substraction.
  • *     -     Multiplication.
  • /      -     Devision. 
  • %    -    Modulas operator
  • ++  -    Increment Operator
  • --     -    Decrement Operator
     Ok...   Now I want you to turn on your Code Blocks and Start to Code with me Some Programs..

Ok..!! 
Now... Let's do a cool exercise using operators. Now what I want you to do is create a simple calculator program. How to do that? Use the practice you have..

Here's what you need to do.

     In your program, you should take two integer numbers as inputs. You can do this using cin function. Then your program should return the addition, subtraction, multiplication, devision of those two numbers.

If you find that hard please follow this video.




Great.. :)  Now you know how to use arithmetic operators. In our next post we can discuss about other 4 types of operators. 

     Before I go, Here's a challenge for you, 
          create two integer variables in a program int a , b ; , Assign two different values to them,  now type a code to assign the value of  b to variable a and value of a to variable b, without using third variable.  If you can comment your answer down comments section. If  you couldn't I will reveal you the answer in next post. Until then bye bye. :)

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..  :)

C++ Data Types..

     

     Helllooo... Readers.... :) Welcome to inspire++. The blog that gives you sophisticated jokes about programming every week.!! ;)
     Hello people.. Did you guys do the homework I gave you in last post. Here I give you the answers.. Please check
 your answers with mine and try to find anything new to you.. 



     Right!! With the lesson from the last post we realized how to create variables. Today lets talk about types of variables which is more generally data types in c++. 
     Last time we learned how to store integer data in variables . Remember the int keyword.. There we talked about integer variables. There are several more data types in c++.Just  Like integers. 




2. Floating Point.

     So, what if we want to store a decimal number in a variable.. we can't store them in integer variables. So for that we have floating point variables. Floating point variables are used to store decimal point values. How to create them? Easy..!! Just like the way we create integers what we have to do is first, type keyword float, and then leave a space and then type a suitable name for your variable. For example float num1 ; . Don't forget the semicolon..!!!
     Right.. after that you can store any decimal value in it. num1 = 75.8262; . Easy!!  Try it your self.. 

3. Character Variables.
     Ok... after that we can talk about other data types. So.. instead of numbers what if we want to store any character value in a variable. There you have character variable. How to create them. Easy.. char space variable name. Ex:- char Letter;. Now you can store any character like A,B,C ... a,b,c... 1,2,3... But remember when you assign any character to your variable remember to use single quotes '.  Ex:-  Letter='A'; 

4. Boolean Variables.
     This data type might be a little bit confusing to you.. Specially , Why we want such data type. 
     In this Data type we store true and false values. Why we want to store true or false value.? Believe me there are so many times we want to use true or false as output in programming. So how to create this?? Type bool , and then a space and the name you want to give to your variable. now in simple letters you can assign either true OR false to your variable.  

5. Void.
     Void is a data type which is not used to create variables. Really!! Yes.. At this point I have to remind you that Data types are used not only to create variables, but also they are used to create arrays , functions etc. So this data type "void" is use in function defining. 

      So above 5 are known as the primitive data types. You can use them to create certain variables. 
     Now I'm going to tell about another important non primitive data type. string...

6. string
     Imaging you want to store a word , or a sentence as the data. What are the options u have.? you type string And then a space and a name for your string variable, finally semi colon. And you can store data in them by variable name assignment operator and the word or the sentence you want. Remember here when assigning data use double quotation marks " ".




     Ok.. now you know something about variables. Now what I want you to do is to make a program to store several data in suitable types of variables  and print them. This is what you have to do.

     Store these data about a student named  Lio ,who is 20 years old , height about 1.8288 , lives in colombo got Grade A for his Mathematics exam.
     Create suitable variables to store his name , age , city , height in meters city and grade for maths. And get them as the output.

     Do this Exercise and I will give you the answers in my next post. :)
     Bye.. C U Soon.. 
Start from the First post <<<

C++ Variables


     Helloo.. My favorite blog readers.. Welcome to the newest post from ispire++ blog. This post is the next post of our fundamental of programming post series . So don't get confused this with our new post series OOP.
     I gave you some homeworks in my last post. Did you do those. Well if you did here are the answers for them.

Last posts Homework answers ;)









So... last week I promised you to start to talk about c++ variables. Here lets start it. Variables are a kind of structure we use to hold data in a program. 
     We know that when we run a program, it runs on our RAM.(Random Access Memory) . In a program, when we want to store some data(Temporarily, Not on hard disk), We create variables. 
      For example, let say we want to store the age of a person. What we have to do is create a variable to hold that data age of a person. Age is measured by years, so it is we can consider as an integer value. So what exactly we want to do here is, create a variable to hold an integer data. And store our data (age) in it. 
How do we do this.
     We want an integer variable, so we type int first,
     Then we put a space, and then we type a suitable name for the variable, ie:- age.
Ok, and finally as always we type semicolon ; . Right! We now have officially created the first variable we ever created in c++. Weldone guys.. :) 



     
     Ok.. now after we created the variable, lets store something in it. In this example age. Let say the age of the person is 23. So what we do is , in a new line we type the name of our variable, age , and then we type equal sign(in c++ it is known as assignment operator) after that we type the value we want 23 and finally semicolon;. 
     Congratulations you have assigned a value to your variable. Now let's check the variable. In a new line let's start a code to print the value. Type, cout<<age; and build and run your program.




     See the output! It says 23 right!! That's the value we assigned to our variable. See how easy to create variables, assign values to them and use them!! 

     Now I want you to create 5 variables about 5 subjects of a student naming English, Programming, Drawing, Electrical, Fluid. And assign the marks values as follows 80, 83, 75, 80, 60. And then in your program write a code to take them as output. Do this as a homework I'll give you the answers in our next post. 
     Ok.. here I end up this post. Hoping to see you in my next post soon.. Bye..!! :)

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...