Posts

Showing posts from February, 2022

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