Posts

Showing posts from October, 2020

get and set method in c++ with example. Basic program of c++ using get and set method

 C++ program using get and set method Program to print age, first name, last name and standard of a student #include   < iostream > #include   < sstream > using   namespace  std; class  Student {      private :         int  age,standard;        string first_name, last_name;      public :         void  set_age( int  a)        {            age=a;        }            int  get_age()        {             return  age;        }         void  ...

write a c++ program to input two strings and print their lengths, concatenate them and print the result and also print both the strings by swapping their first element

write a c++ program to input two strings and print their lengths, concatenate them and print the result and also print both the strings by swapping their first element #include <iostream> #include <string> using namespace std; int main()  {     int l,m;     string a,b,c,d;     cin>>a>>b;     l=a.size();     m=b.size();     cout<<l<<" "<<m<<endl;     c=a+b;     cout<<c<<endl;     d[0]=a[0];     a[0]=b[0];     b[0]=d[0];     cout<<a<<" "<<b;     return 0; }  

Write a program to print area of 2 rectangles having sides(4,5) and (5,8) respectively by creating a class named Rectangle.

Write a program to print area of 2 rectangles having sides(4,5) and (5,8) respectively by creating a class named 'Rectangle' with a function which returns the area. Length and breadth are passed as parameters to its constructor. #include <iostream> using namespace std; class Rectangle {     public:       int a;      Rectangle(int l, int b)          {                           a=l*b;              cout<<a<<endl;          } }; int main() {     cout<<"area of R1 is ";     Rectangle R1(4,5);     cout<<"area of R2 is ";     Rectangle R2(5,8);          return 0; }  

C++ Program to sort negative and positive numbers

 #include <iostream> using namespace std; int main() {     int a[50],l,i,n,s=0,j;     cin>>n;         for(i=0;i<n;i++)                     cin>>a[i];         j=n-1;     for(i=0;i<j;)                     {                          if(a[i]<0)                      {                                  i++;                                 continue;                       }                         if(a[j]...