Tuesday, October 8, 2013

fall kindle fire This is a joint AUTHOR & BLOGGER GIVEAWAY EVENT! Bloggers & Authors have joined together and each chipped in a little money towards a Kindle Fire HD 7".
The winner will have the option of receiving a 7" Kindle Fire HD (US Only)
  Or $199 Amazon.com Gift Card (International)
  Or $199 in Paypal Cash (International)
    Fall Sponsoring Authors & Bloggers
  1. I Am A Reader, Not A Writer
  2. Feed Your Reader
  3. Author Annette K. Larsen
  4. Phantasmic Reads
  5. Author Bella Street
  6. Author Bonnie Blythe
  7. Author Stacy Claflin
  8. MyLadyWeb: Women's History, Women Authors
  9. Book Mama Blog
  10. Word to Dreams
  11. Candace's Book Blog
  12. Once Upon a YA Book
  13. Author Miriam Louise
  14. Author Mary Ting
  15. Author Camelia Miron Skiba
  16. Books4Tomorrow
  17. Author Theresa McClinton
  18. Brooke Blogs
  19. Author Pauline Creeden
  20. Author MK McClintock
  21. Author Kathryn Chastain Treat
  22. Books Unhinged Book Blog
  23. Author Kelly Cozy
  24. Meredith & Jennifer's Musings
  25. These Are But Shadows
  26. My Devotional Thoughts
  27. Author Ally Shields
  28. Dark Motive's Books and More
  29. Nessarox
  30. Fae Books
  31. Author Jennie Sherwin
  32. The Real Bookshelves of Room 918
  33. Auggie Talk
  34. No BS Book Reviews
  35. BookLover Sue
  36. Gin's Book Notes
  37. Bookhounds
  38. Buku-Buku Didi
  39. Author Shelli Profitt Howells
  40. My Nook, Books and More
  41. The Late Bloomer's Book Blog
  42. Clarice's Book Nook
  43. MichaelSciFan
  44. Magical Manuscripts
  45. Author Talia Jager
  46. Every Free Chance Book Reviews
  47. Jessabella Reads
  48. Author Melissa Pearl
  49. Author Elizabeth Isaacs
  50. Bookitty Blog
  51. Author Helen Smith
  52. The (Mis)Adventures of a Twenty-Something Year Old Girl
  53. Christine's Blog
  54. Write Away Bliss
  55. Another World of Books
  56. The Reporter and The Girl MINUS The Super Man!
  57. Katie's Clean Book Collection
  58. Author Marcia Lynn McClure
  59. Author Shannon Guymon
  60. Ripple Effect Romance Series
  Sign up to Sponsor the NOVEMBER Giveaway http://www.iamareader.com/2013/09/november-kindle-fire-giveaway-sign-ups.html   Giveaway Details 1 winner will receive their choice of a Kindle Fire 7" HD (US Only), $199 Amazon Gift Card or $199 in Paypal Cash (International). There is a second separate giveaway for bloggers who post this giveaway on their blog. See details in the rafflecopter on how to enter to win the 2nd Kindle Fire. Ends 10/31/13 Open only to those who can legally enter, receive and use an Amazon.com Gift Code or Paypal Cash. Winning Entry will be verified prior to prize being awarded. No purchase necessary. You must be 18 or older to enter or have your parent enter for you. The winner will be chosen by rafflecopter and announced here as well as emailed and will have 48 hours to respond or a new winner will be chosen. This giveaway is in no way associated with Facebook, Twitter, Rafflecopter or any other entity unless otherwise specified. The number of eligible entries received determines the odds of winning. Giveaway was organized by Kathy from I Am A Reader, Not A Writer http://iamareader.com and sponsored by the participating authors & bloggers. VOID WHERE PROHIBITED BY LAW.   a Rafflecopter giveaway

Wednesday, December 21, 2011

Function


මොකද්ද මේ Function එකක් කියන්නේ. අපි Program එකක් Code කරන කොට එකම Coding එක අපේ Program එකේ විවිධ විවිධ තැන් වල භාවිතා කරන අවස්ථා මතකද? ඒ නිසා Program එකේ Code එක දික් වෙනවා වගේ ම කාලයත් ගෙඩක් වැය වෙනවා. ඉතින් මේ ප්‍රශ්ණය මග හරවා ගන්න අපිට Function එකක් භාවිතා කරන්නන පුලුවන්. ඒ කියන්නේ ඔයගොල්ලන් ගේ Program එකේ තැනින් තැන Numbers 2 ක එකතුව ගන්න තියනවා කියලා හිතන්න ! අපි Numbers 2 ක එකතු කරන කෝඩ් එක හැම තැනම Code කරන්නේ නැතිව අපේ Program එකේ එක තැනක Program එකටම පොදු වෙන්න Code කරනවා. මෙහෙම Code එකකට තමා Function එකක් කියලා කියන්නේ.
E.g.
                Max = Number1 + Number2
                Min = Number 4+Number6
                Total = Number6+Number1
                                                                විදිහට Program එකේ තියෙනවා කියලා හිතන්න!!!
දැන් අපි මේ අවස්ථාවට function එකක් ලියන හැටි බලමු.
            ඊට කලින් අපි Function එකක් හැදෙන හැටි බලමු. Function එකක මූලිකම දේ තමා Function එකේ නම නැත්තම් Function Name එක ඊට පස්සේ බලන්න ඕනේ මේ function ගන්න data මෙනවද කියලා ඒකියන්නේ අපි මොනවද මේ function එකට pass කරන data හා මොනවද function එකෙන් pass කරගන්නේ කියලා. සරළව කියනවානම්. අපි ගඩොල් හදන machine එකක් ගමු. අපි මේ යන්ත්‍රයට එක පැත්තකින් මැටි දැම්මහම අනෙක් පැත්තෙන් ගඩොල් එලියට එනවා. දැන් ගඩොල් හදන එක කොහොමද Function එකකට සමාන වෙන්නේ ???
            අපි ගඩොල් හදන මැෂින් එකට මැටි දානව වගේ තමා අපේ function එකට data pass කරන එක. එතකොට මේ මැෂින් එකෙන් ඒ මැටි හොදට press කරල ගඩොලක් බවට පත් කරල ගඩොලක් එලියට එවනවා. ඒවගේ තමා අපේ function එකෙනුත් ගත්ත data process කරල final output එක එලියට දෙනවා. ඉහත උදාහරණයට අනුව නම් අපේ function එකට numbers 2 pass කරපුවහම අපේ function එකෙන් මේ numbers 2 add කරල answer එක දෙනවා.  
 ඉතින් මෙහෙම answer එක දෙන එකට අපි කියනවා return type එකක් තියෙන function එකක් කියලා. මොකද සමහර function තියෙනවා return type එකක් නැති.
ඒනිසා අපි අපේ function එක ලියනන් කලින් බලන්න ඕනේ function එක return type එකක් තියෙනව ද නැද්ද කියලා ඊට පස්සේ අපි මේ function එකට data pass කරන්න ඕනෙද නැද්ද කියලා. මොකද සමහර function පිටින් data අවශ්‍ය නෑ.
 දැන් අපි අපේ උදාහරණයට යමු.
අපේ function එකෙන් වෙන්නඕනෙ numbers 2 ක් අරගෙන ඒ 2ක add කරල answer එක ගන්න එක. ඒ කියන්නේ අපේ function එක return type එකක් තියෙන function එකක්. දැන් අපි බලමු අපි return කරන්නේ මොන වගේ data ද කියල. අපි එකතු කරන්නේ numbers හින්ද return type එකත් number එකක්ම වෙන්න ඕනෙ. එක එක programming languages ගත්තහම function එකක් coding කරන හැටි ටිකක් විතර එකිනෙකින් වෙනස් ඒ හින්ද අපි සාමාන්‍යෙයන් code කරන හැටි බලමු.
මුලින්ම function එකේ නම එකෙ return type එකත් එක්ක ලියන්න ඕනෙ (අපි function එකේ නම දානකොට තේරුමක් ඇති නමක් දාන්න හැම වෙලාවෙම try කරන්න ඕනෙ). ඊට පස්සේ {  } වරහන් 2 ක් මැද්දෙ function එකේ coding ලියන්න ඕනෙ.
අපි කොහොම ද C++ වලින් මේක code කරන්නේ කොහොම ද කියලා බලමු
Int Summation ( int x , int y)                             return type එක, function එකේ නම හා  Function එකට pass කරන data
{                                                                           
                Int Answer = x + y;                                        
                Return Answer;                                              
}
දැන් ඕනෙම numbers 2 ක් මේ function එකට pass කරපුවහම ඒදෙකේ එකතුව අපිට ගන්න පුළුවන්.
දැන් අපි බලමු අපි කොහෙමද මේ function එක භාවිතා කරන්නේ ඒ කියන්නේ අපි කොහොමද මේ function එකට call කරන්නේ
අපේ main program එකේ අපිට ඕනෙ තැනදී අපි අපේ function එකේ නමයි අපි pass කරන data වරහනක් ඇතුලේ code කරනවා
Max = Summation (Number1, Number2)  Calling the function / function එකට කථා කිරීම              

එතකොට අපි කලින්  code කරපු function එකට මේ numbers 2 ක pass වෙලා උත්තරය Max කියන Variable එකට Return වෙනවා.

මොකද්ද මේ OOP කියන්නේ ?


OOP එහෙමත් නැත්නම් Object Oriented Programming කියන්නේ අපි ලියන Program ලේසි කරගන්න ආපු ක්‍රමයක්. අපි  Program එකක් කෝඩ් කරන විට සමහර මෙතඩ් නැත්නම් Functions නැවත නැවත භාවිතා කරන අවස්ථා තියෙනවා නේද ? නැත්නම් එකම වගේ මෙතඩ් තියෙන Program නැවත නැවත කෝඩ් කරන තැන් තියෙනවා නේ ද ? ඉතින් මේ ගැටලුව මග හරින්න තමයි අපි OOP කියන Concept එක භාවිතා කරන්නේ.
                        OOP Concept එකේ ප්‍රධාන වශයෙන් File වර්ග 2 ක් භාවිතා වෙනවා, ඒ Header File එක හා Source File. ඇයි මේ File  වර්ග 2 ක් ? අපි අපේ Program එකේ තියෙන Variables හා Methods වල නම් වෙනමත් ඒ මෙතඩ් implementation එහෙමත් නැත්නම් ඒ Methods වල කෝඩින් වෙනමත් file එකක තියා ගන්නවා. ඇයි අපි එහෙම කරන්නේ ? හිතන්න අපිට අලුත්න් Variable එකක් Add කරන්න උනා කියල, එතකොට අපේ Variables වල නම් තියෙන File එක විතරක් Edit කරල අපිට අලුත් Variable එක Add කරගන්න පුලුවන්.
            අපි Header File එකට දාන්නේ Variables වල නම් හා අපි භාවිතා කරන Methods වල නම් වතරයි. Header File එකෙන් එක එක කොටස් වලට බොදෙනවා ඒ Public, Private etc. අපි Private කියන කොටසේ Variables වල නම් ද Public කොටසේ Methods වල නම් ද භාවිතා කරනවා
පහත දැක්වෙන්නේ එලෙස Code කල C++ Header File එකක Coding
#pragma once
#include<iostream>
using namespace std;
class Student
{
private:
                int ditNo;
                char name[20];
                double marks[3];
public:
                Student (int pditNo,char name[]); //constructer
                void assignMarks (double marks1,double marks2,double marks3);  //functions
                double calcAvg();
                void print()        
};

ඊලගට Source File එකේ අපි භාවිතා කරන Methods වල Implementation
පහත දැක්වෙන් නේ ඉහත් භාවිතා කල Headers File එකේ Source File එකේ Coding

#include "StdAfx.h"
#include "Student.h"
#include <cstring>
Student :: Student(int pditNo, char pname[]) {
                ditNo = pditNo;
                strcpy(name,pname);
}
void Student :: assignMarks(double marks1,double marks2,double marks3) {
                marks[0]= marks1;
                marks[1]= marks2;
                marks[2]= marks3;
}
double Student :: calcAvg() {
                double avg;
                avg = ((marks[0]+marks[1]+marks[2])/3);
                return avg;
}
void Student :: print() {
                cout<<"DIT No : "<<ditNo<<endl;
                cout<<"Name : "<<name<<endl;
}