Posts

String Class in C++

 //Use of String class in CPP #include<iostream> #include<string> using namespace std; int main() {     string str1="compuhelp";//using = operator     cout<<endl<<"String is "<<str1;     cout<<endl<<"size of string is "<<str1.size();     cout<<endl<<"Element access "<<str1[0];//displays first char     cout<<endl<<"Element at "<<str1.at(1);//displays second char   cout<<endl<<endl<<"Display String character by character"<<endl;   for(int i=0;i<str1.size();i++)     cout<<str1[i]<<" ";   cout<<endl<<"second method to display string char by char"<<endl;   for(int i=0;i<str1.length();i++)     cout<<str1.at(i)<<" ";     cout<<endl<<"use of substr function of string ";     cout<<endl<<str1.substr(4);//di...

Vector class in C++ (Part of STL)

 //Use of vector template in cpp #include<iostream> #include<vector> using namespace std; int main() {     vector<int> v;     cout<<v.size();//will display size of vector     v.push_back(10);//to add value to vector     v.push_back(20);     cout<<v.size();//will display size after adding values     cout<<endl<<"values of vector"<<endl;     cout<<v[0];//to display first value     cout<<v[1];      cout<<endl<<"values of vector through iterator";    vector<int>::iterator it = v.begin();    while( it != v.end()) {       cout <<endl<<"value of it = " << *it;       it++;    }//end of while    v.push_back(30);    v.push_back(40);    cout<<endl<<"now the size of vector is "<<v.size();   ...

JavaScript Timer Example

  <!DOCTYPE html > <html lang = "en" > <head>     <meta charset = "UTF-8" >     <meta http-equiv = "X-UA-Compatible" content = "IE=edge" >     <meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     <title> Use of JavaScript </title>     <script>         var ctr = 0 ; //initializing ctr         var timer1 = null ;         function msg ( str1 )         {             // alert("hello" + str1);             head1 . innerHTML = "Hello " + str1 ;         }         function increment ()         {             //alert("hello");             ctr = ctr + 1 ;             hea...

Arrow Functions in Javascript

  < html > < head >   < title > Arrow functions </ title >   < script >       var fun = function (){           return "Hello Compuhelp" ;       } //end of function       function test ( f )       {             return f ();       }             function useArrow ()       {         // div1.innerHTML= div1.innerHTML +  fun();         //div1.innerHTML= div1.innerHTML+ test(fun);         const x =( nm ) => "I am arrow function" + nm ;         head3 . innerHTML = x ( "compu" );         //return "hello compu";       }         </ script > </ head > < body > < div id = "div1" > < h2 id = "head2" > Use ...

Java Script Classes

  <! DOCTYPE html > < html lang = "en" > < head >     < title > javascript classes </ title >     < script >         class GMaths         {           constructor ()             {                 this . num1 = 100 ;                 this . num2 = 20 ;             }             /* constructor(n1,n2)             {                 this.num1=n1;                 this.num2=n2;             }*/             setData ( n1 , n2 )             {                 this . num1 ...

First Object Oriented CPP Program

 //my first object oriented cpp program #include<iostream> using namespace std; int x;//variable class Maths {     int num1;//Data member     int num2;     int res;     public:    void getData()//member function     {     cout<<"Enter first number";     cin>>num1;     cout<<"\n Enter second number";     cin>>num2;     }//end of function getData     //num1=10;     //num2=20;     void sum()     {     res=num1+num2;     cout<<"\n The sum of "<<num1<<" and "<<num2<<" is: "<<res;     }//end of function sum }; int main()//non member funtion {     Maths mt;     mt.getData();     mt.sum(); }//end of main

Using Functions in JavaScript

  <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta http-equiv = "X-UA-Compatible" content = "IE=edge" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > use of functions </ title >         < script >     var arr =[ 10 , 20 , 30 ];             function displayValue ( curObj )         {             // alert(value);             curObj . value = "new Text" ;             ans = sum ( 10 , 20 );             alert ( "The value of ans is " + ans );             addValues ( arr );         }         function sum ( n1 , n2 )     ...