Ruby Course – Worldwideasy – 04

Ruby lesson 4. I will focus on Getting Control Statements (IF statement, Case Expressions, loops), Comments, and File Control. It can provide extensive knowledge.

Control Statements

A control statement is a statement that determines whether other statements are active. If a statement decides whether another statement should be executed, or one of the two statements to be executed. A loop determines the number of times another expression should be executed.

Basically have 3 control statement

  • IF
  • Switch
  • Loops

IF Statement in Ruby

If a statement is used to check the condition, it can be a condition or more. The special feature of it is that you can check any gap. The following example will make it clear to you.

ismale = false 
if ismale
   puts "you are male"
else
   puts "you are not male"
end

This Code output is you are not male.

Case Expressions

The Case Expressions is used to check several non-gap conditions. This works very fast and gets the idea below

def get_day_name(day)
day_name=" "

case day
when "mon"
day_name = "Monday"
when "tue"
day_name = "Tuesday"
when "wed"
day_name = "Wednesday"
when "tur"
day_name = "Thursday"
when "fri"
day_name = "Friday"
when "sat"
day_name = "Saturday"
when "sun"
day_name = "Sunday"
else
day_name = "Invalid"
end
return day_name
end
puts get_day_name("wed")

This code output is Wednesday.

Loops

Loops have main 3 loops in php

  • For loop
  • While loop

Now I show the First 3 loops using Code. See Below all code output is the same. output is : 1,2,3,4,5,6,7,8,9,10.

For Loop with Arry

num = [1,2,3,4,5,6,7,8,9,10]
for num in num 
puts num
end

While Loop

index = 1
while index < 8
puts index 
index + = 1
end

Ruby Comment

Comments are a special character in programming.

# single line comment
= multiline
  comment =

File Control using Ruby

Here we show you how to handle files without opening them. see below

Reading File
file.open("test.txt",r) do |tile|
puts file.read
end
Write File
File.open("employee.txt","a") do |file|
file.write ("sanka")
end
Create File
File.open ("index.html","w") do |file|
file.write("<h1>Hello</h1>")
end
Read and Write
File.open ("employee.txt","rt") do |file|
file.readline()
file.write ("overridden")
end

Class & Object

Class is collection of objects and functions. In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

This is the mining of the object and class. now we can try to add it ruby. look below example.

class Book
attr_accessor :title, :author, :pages
end

book1 = Book.new()
book1.title = "Harry Potter"
book1.auther = "JK"
book1.pages = 400
puts book1.pages

Output is 4000.

Method

See the below example. that use code reuses it easy for developing softwares.

Class
attr_accessor:name, :major, :gpa
def initialize (name,major,gpa)
@ name = name
@ major = major
@ gpa = gpa
end
end
student1 = student.new ("harry","bio","3.6")
student2 = student.new ("jhone","chem","2.1")

puts.student1.name

Output is harried.

Create a Ruby 2D Game

First, install ruby 2d gem. open cmd

gem install ruby2d

Click Here to get the Source code.

you can see the below output in-game.

Now over the Ruby basic course. you go to this link and answer the question and get a Ruby certificate. Get Certificate

Thank you for all!

More Ruby ClickHere!

See you Next Lesson Soon!

C# Course – Worldwideasy – 05

C# lesson 5. I will focus on 2D Arrays, Class, Object. Finally, Interface design. It can provide extensive knowledge.

2D Arrays in C#

A two-dimensional array has a type like an int [ ] [ ] or string [ ] [ ], with two pairs of square brackets. The element of a 2D array is arranged in rows and columns, and the new operator for the 2D array specifies both the number of rows and the number of columns.

You can get an Idea Using the Example Below about 2d arrays.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] cat =
            {
                {1,2},
                {4,6},
                {8,9}
            };
            Console.WriteLine(cat[0,1]);
            Console.ReadLine();
        }
    }
}

This code Answer is 2.

Object & Class in C#

Class is collection of objects and functions.

programming class

In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

Object in programming

He is a simple miner to the class. In object-oriented programming, we find a class. The use of this concept revolutionized the software development industry. This made it possible to create very fast software with a small amount of code. What makes it special is the ability to reuse the code. Let’s see how to use it for C #. The following example shows how to publish and execute a class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        class book{                    // Create Class
            public String title;
            public String Author; 
            public int pages;
        }
        static void Main(string[] args)
        {
            book book1 = new book();     // Call Class
            book1.title = "Harry Potter";
            book1.Author = "JK";
            book1.pages = 450;

            Console.WriteLine(book1.pages);
            Console.ReadLine();
        }
    }
}

You can see this code do create class and call class.

Now show you how to work class using method look below example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        public  Book (String name, int pages)
        {
            name = aname;
            pages = apages;
        }
        public bool hash()
        {
            if (pages > 200)
            {
                return true;
            }
            false{
                return false;
            }
        }
        static void Main(string[] args)
        {
            Book Book1 = new Book("magic", 280);
            Console.WriteLine(Book1.hash());
            Console.ReadLine();
        }
    }
}

This code output is True.

Work with interface in C#

Now over the php basic course. now let’s try to work with the interface. following this stape.

  • File –> New Project.
  • Select Windows Forms Application.
  • OK -> you can see empty form.
  • Now you can See Left side in toolbox.
  • Drag and Drop label.
  • Go Label properties go appearance. See Right (Clear field);
  • Drag and Drop Text Box.
  • Drag and Drop Button.
  • Double Click Button.
  • Type this code. label1.Text ="Hello" + textBox1.Text;

Now over the C# basic course. you go to this link and answer the question and get C# certificate. Get Certificate

Thank you for all!

More C# ClickHere!

See you Next Lesson Soon!

Php Course – Worldwideasy – 05

php lesson 5. I will focus on Class, Construct, Object, getter, setters, and Inheritance. Finally, we can complete today’s php basic course.

Php Class

Class is collection of objects and functions.

This is simple mining for the class. We find a class in object-oriented programming. The use of this concept revolutionized the software development industry. This made it possible to create very fast software with a small amount of code. The specialty here is the ability to reuse code. Let’s see how to use it for php. The following example shows how to declare and execute a class.

<?php
class Book {
var $name;
var $author;
var $price;               //class assing
}
$book1 = new book;
$book1 = name = "Harry Potter";
$book1 = price = "1700";          //make objects
$book1 = author = "JK";

echo $book1 -> name;
echo $book1 -> price;
?>

This code output is Harry Potter 1700.

Constructor

In class-based object-oriented programming, a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables

You can get a good idea using the following example about php constructor.

<?php
class Book{
var $name;
var $price;
var $author;
function__construct(){
echo"this is book<br>";
}
}
$book1 = new Book;
$book2 = new Book;
?>

This code output is is book two-time print.

Object and Functions

In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

This is the mining of the object and functions. now we can try to add it php. look below example.

<?php
class student {
var $name;
var $stream;
var $gpa;
 function__construct ($name,$stream,$gpa){
$this->name = $name;
$this->stream = $stream;
$this->gpa = $gpa;
}
function hasHonors(){
if ($this->gpa>2.5){
return "true";
}
else{
return "false";
}
}
}
$student1 = new student ("jane","Maths","3.2");
$student2 = new student ("mick","Biology","2.4");

echo $student1 -> hasHonors();
echo $student2 -> hasHonors();
?>

This code answer is truly false.

Getters and Setters

get create a function function getRating(){}

using if statement function setRating($rating)

Private can not be changed. The public can be change.

Inheritance

Object-oriented programming, inheritance, is the mechanism by which an object or class retains a similar function based on another object or class. Also defined as taking new classes from existing classes, such as the superclass or the basic class, and converting them into a hierarchy of classes.

see below you can get an idea for inheritance.

<?php
class chef{
function makechicken(){
echo "make chicken";
}
function make salad(){
echo "make salad";
}
function make bbq(){
echo "make bbq";
}
}
$italianchef = new italianchef;
echo $italiancheff->makechicken();
echo $italiancheff->makebbq();
?>

output is made chicken and makes bbq.

Now over the php basic course. you go to this link and answer the question and get PHP certificate. Get Certificate

Thank you for all!

More php ClickHere!

See you Next Lesson Soon!