SlideShare a Scribd company logo
1 of 12
1. Program to swap two values using third variable.
2. Program to swap two values without using third variable.
3. Program to find the maximum of 10 values stored in array.
4. Program to find the smallest of 10 values stored in array.
5. Program to find the largest of two values using conditional
operator.
6.Program to find the smallest of three values using conditional
operator.
#include<iostream.h>
#include<conio.h>
void main()
{
 int a,b,temp;                                       OUTPUT
 clrscr();                                   Enter value of a: 45
cout<<“Enter value of a:”;                   Enter value of b: 56
cin>>a;                                      Original value of a is:45
cout<<“Enter value of b:”;                   Original value of b is:56
cin>>b;                                      After Swapping
 cout<<"Original value of a is:"<<a<<endl;   New value of a is:56
 cout<<"Original value of b is:"<<b<<endl;   New value of b is:45
temp=a;
 a=b;
 b=temp;
cout<<“After Swapping..”<<endl;
 cout<<“New value of a is:"<<a<<endl;
 cout<<“New value of b is:"<<b<<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
class swapping
{
 public:
 int anew,bnew,temp;
 void swap( int anew, int bnew) //function receives arguments via object of swapping class
 {
  temp=anew;
  anew=bnew;
  bnew=temp;                                                                                         Output
  cout<<“New value of a is:"<<anew<<endl;                                                    Value of a is: 10
  cout<<“New value of b is:"<<bnew<<endl;
}                                                                                            Value of b is: 15
};                                                                                           After swapping
void main()
{                                                                                            New Value of a is: 15
 int a=10,b=15; //we have set the values of a and b as 10 ,15, it can be user defined too.   New value of b is: 10
clrscr();
 swapping s1; //created object of swapping class
 cout<<“Value of a is:"<<a<<endl;
 cout<<“Value of b is:"<<b<<endl;
cout<<“After Swapping”<<endl;
 s1.swap(a,b); //called swap function using object and dot operator
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
 int a, b;                                      OUTPUT
 clrscr();                              Enter value of a: 45
cout<<“Enter value of a:”;              Enter value of b: 56
cin>>a;                                 Original value of a is:45
cout<<“Enter value of b:”;              Original value of b is:56
cin>>b;                                 After Swapping
 cout<<“Value of a is:"<<a<<endl;       New value of a is:56
 cout<<“Value of b is:"<<b<<endl;       New value of b is:45
 a=a+b;;
 b=a-b;
 a=a-b;
cout<<“After Swapping..”<<endl;
 cout<<“New value of a is:"<<a<<endl;
 cout<<“New value of b is:"<<b<<endl;
getch();
}
2.Program to swap two values without using third variable.
    #include<iostream.h>
    #include<conio.h>
    class swapping
    {
     public:
     int anew,bnew;
     void swap( int anew, int bnew);
     };
     void swapping :: swap(int anew , int bnew)
     {
      anew= anew+bnew;                                        OUTPUT
      bnew=anew-bnew;                             Enter value of a: 25
      anew=anew-bnew;                             Enter value of b: 65
      cout<<"new value of a is:"<<anew<<endl;     Value of a is: 25
      cout<<"new value of b is:"<<bnew<<endl;
                                                   Value of b is:65
     }
    void main()                                   After swapping
    {                                             Value of a is: 65
     int a,b;                                     Value of b is: 25
     clrscr();
     swapping s1,s2;
     cout<<"Enter value of a:";
     cin>>a;
     cout<<"Enter value of b:";
     cin>>b;
     cout<<“Value of a is:"<<a<<endl;
     cout<<“Value of b is:"<<b<<endl;
     s1.swap(a,b);
      getch();
    }
3.Program to find maximum of 10 values stored in array.

     #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int a[10],i,j,m,loc=0;
                                                           OUTPUT
     clrscr();                              Enter 10 elements of array:
     cout<<"enter 10 elements of array:";                                  5
     for(i=0;i<=9;i++)                                                     8
     {
      cin>>a[i];                                                           2
     }                                                                    12
     m=a[0];                                                              65
     for(j=1;j<=9;j++)
     {
                                                                           36
      if(a[j]>m)                                                          98
      {                                                                   45
       m=a[j];                                                            25
       loc=j+1;
      }                                                                   96
     }
     cout<<"max value is:"<<m;              Max value is: 98
     cout<<"its loc is:"<<loc;
     getch();
                                             Its location is: 7
     }
3.Program to find maximum of 10 values stored in array.
    #include<iostream.h>                                                                            OUTPUT
    #include<conio.h>
    class greatest
    {
      public:
      int a[10],j,max;
      int largest() //member func of greatest class that returns a value of integer type
 
 
       {
       cout<<"enter 10 elements of array:";
                                                                                            Enter 10 elements of array:
      for(int i=0;i<=9;i++)                                                                                           5
      {
       cin>>a[i];                                                                                                     8
      }
       max=a[0];                                                                                                      2
       for(j=1;j<=9;j++)
       {                                                                                                            12
 
 
         if(a[j]>max)
         {
                                                                                                                     65
          max=a[j];                                                                                                 36
        }
      }                                                                                                             98
      return max;
     }                                                                                                              45
    };
    void main()                                                                                                     25
 
 
     {
     int max1;
                                                                                                                     96
    clrscr();
    greatest g1;
    max1=g1.largest();                                                                     Max value is: 98
    cout<<"Greatest of ten values is:"<<max1;
    getch();
    }
4.Program to find smallest of 10 values stored in an array.
   #include<iostream.h>
   #include<conio.h>
   void main()
   {
    int min,a[10],I;                                   OUTPUT
   clrscr();                                 Enter 10 elements of array:
   cout<<“Enter 10 elements of array.”;                                      5
   for(i=0;i<=9;i++)                                                         8
   cin>>a[i];                                                                2
                                                                             12
   for(j=1;j<=9;j++)                                                        65
   {                                                                        36
     If(a[j]<min)                                                           98
     min=a[j];                                                              45
   }                                                                        25
   cout<<“smallest of 10 values is:”<<min;                                  96
   getch();
                                              Smallest of ten values is: 2
   }
4.program to find smallest of 10 values stored in an array.
   #include<iostream.h>
   #include<conio.h>
   class smallest
   {
     public:
     int a[10],j,min;                                                     OUTPUT
     int calculate_smallest()
     {                                                           Enter 10 elements of array:
     cout<<"enter 10 elements of array:";
     for(int i=0;i<=9;i++)                                                                 -5
     {
      cin>>a[i];                                                                            8


      }
       min=a[0];         //0th element is set as minimum values
                                                                                             2
      for(j=1;j<=9;j++)                                                                   12
      {
       if(a[j]<min)                                                                       65
       {
         min=a[j];                                                                        36
       }
     }                                                                                    98

    }
      return min;                                                                          45
   };                                                                                     25
   void main()
   {                                                                                      96
   int min1;
   clrscr();
   smallest s1;
   min1=s1.calculate_smallest();
                                                                  Smallest of ten values is: -5
   cout<<“Smallest of ten values is:"<<min1;
   getch();
   }
5.Program to find largest of two values using conditional operator.
  #include<iostream.h>
  #include<conio.h>
  void main()
 {
  int a , b, c;                           OUTPUT
                                           Enter value of a: 56
  clrscr();                               Enter value of b: 36
  cout<<“Enter value of a:”;              56 is greatest.
  cin>>a;
  cout<<“ Enter value of b:”;
  cin>>b;
  c=a>b?a:b; //using conditional operator, c stores the
  biggest of two values.
 cout<<a<<“ is greatest”;
 getch();
}
5.Program to find greatest of two values using conditional
operator.
      #include<iostream.h>
      #include<conio.h>
      class comparison
      {
         public:
          int a1,b1,max;
         int greatest (int a1,int b1)
         {
          max=a1>b1?a1:b1; //using conditional(ternary operator) to compare a and b, storing result in max.
          return max;
         }
      };
      void main()
      {
      int a, b;
      clrscr();                                                               OUTPUT
      cout<<"enter a:";
      cin>>a;
      cout<<"enter b:";
      cin>>b;                                                     Enter value of a: 62
      comparison c1;                                              Enter value of b: 36
      cout<<"Greatest of two values is:"<<c1.greatest(a,b);
      getch();
                                                                   Greatest of two values is:62
      }
6.Program to find smallest of three values using ternary operator.
     #include<iostream.h>
     #include<conio.h>
     void main()
     {                                          OUTPUT
      int a , b, c, max;           Enter value of a: 96
     clrscr();                     Enter value of b: 125
     cout<<"Enter value of a:";    Enter value of c: 36
     cin>>a;                       36 is greatest
     cout<<" Enter value of b:";
     cin>>b;
     cout<<"Enter value of c:";
     cin>>c;
      max=a<b?(a<c?a:c):(b<c?b:c); //using conditional
      operator, max stores the biggest of three values.
     cout<<max<<" is smallest";
     getch();
    }

More Related Content

What's hot

What's hot (20)

C++11
C++11C++11
C++11
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
C++ book
C++ bookC++ book
C++ book
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
C++11
C++11C++11
C++11
 
basics of c++
basics of c++basics of c++
basics of c++
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
C++
C++C++
C++
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 

Viewers also liked

Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
Effective writing, tips for Bloggers
Effective writing, tips for BloggersEffective writing, tips for Bloggers
Effective writing, tips for BloggersAhmad Idrees
 
System outputs - Computer System
System outputs - Computer SystemSystem outputs - Computer System
System outputs - Computer SystemAhmad Idrees
 
Principle of marketing
Principle of marketing Principle of marketing
Principle of marketing Ahmad Idrees
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
 
Basic characteristics of business
Basic characteristics of businessBasic characteristics of business
Basic characteristics of businessAhmad Idrees
 
What is computer Introduction to Computing
What is computer Introduction  to Computing What is computer Introduction  to Computing
What is computer Introduction to Computing Ahmad Idrees
 
Python in Computer Vision
Python in Computer VisionPython in Computer Vision
Python in Computer VisionBrian Thorne
 
Basic qualities of a good businessman
Basic qualities of a good businessmanBasic qualities of a good businessman
Basic qualities of a good businessmanAhmad Idrees
 
An overview of computers and programming languages
An overview of computers and programming languages An overview of computers and programming languages
An overview of computers and programming languages Ahmad Idrees
 
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CDWhats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CDDavid Ware
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Strategic planning and mission statement
Strategic planning and mission statement Strategic planning and mission statement
Strategic planning and mission statement Ahmad Idrees
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput Ahmad Idrees
 

Viewers also liked (20)

Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Effective writing, tips for Bloggers
Effective writing, tips for BloggersEffective writing, tips for Bloggers
Effective writing, tips for Bloggers
 
System outputs - Computer System
System outputs - Computer SystemSystem outputs - Computer System
System outputs - Computer System
 
Principle of marketing
Principle of marketing Principle of marketing
Principle of marketing
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Basic characteristics of business
Basic characteristics of businessBasic characteristics of business
Basic characteristics of business
 
What is business
What is businessWhat is business
What is business
 
What is computer Introduction to Computing
What is computer Introduction  to Computing What is computer Introduction  to Computing
What is computer Introduction to Computing
 
Python in Computer Vision
Python in Computer VisionPython in Computer Vision
Python in Computer Vision
 
Basic qualities of a good businessman
Basic qualities of a good businessmanBasic qualities of a good businessman
Basic qualities of a good businessman
 
An overview of computers and programming languages
An overview of computers and programming languages An overview of computers and programming languages
An overview of computers and programming languages
 
IBM MQ V9 Overview
IBM MQ V9 OverviewIBM MQ V9 Overview
IBM MQ V9 Overview
 
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CDWhats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Strategic planning and mission statement
Strategic planning and mission statement Strategic planning and mission statement
Strategic planning and mission statement
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 

Similar to Basic c++ programs

Similar to Basic c++ programs (20)

C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
C++ practical
C++ practicalC++ practical
C++ practical
 
C++ file
C++ fileC++ file
C++ file
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Oop1
Oop1Oop1
Oop1
 
cpp promo ppt.pptx
cpp promo ppt.pptxcpp promo ppt.pptx
cpp promo ppt.pptx
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Notes
NotesNotes
Notes
 
Array notes
Array notesArray notes
Array notes
 

More from harman kaur

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlabharman kaur
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black treeharman kaur
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlideharman kaur
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.harman kaur
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gateharman kaur
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)harman kaur
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)harman kaur
 
Rules of inference
Rules of inferenceRules of inference
Rules of inferenceharman kaur
 
Virtual function
Virtual functionVirtual function
Virtual functionharman kaur
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++harman kaur
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornicsharman kaur
 

More from harman kaur (14)

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black tree
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
Digital u1
Digital u1Digital u1
Digital u1
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
 
Msql query
Msql queryMsql query
Msql query
 
Rules of inference
Rules of inferenceRules of inference
Rules of inference
 
Virtual function
Virtual functionVirtual function
Virtual function
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornics
 

Recently uploaded

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 

Recently uploaded (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 

Basic c++ programs

  • 1. 1. Program to swap two values using third variable. 2. Program to swap two values without using third variable. 3. Program to find the maximum of 10 values stored in array. 4. Program to find the smallest of 10 values stored in array. 5. Program to find the largest of two values using conditional operator. 6.Program to find the smallest of three values using conditional operator.
  • 2. #include<iostream.h> #include<conio.h> void main() { int a,b,temp; OUTPUT clrscr(); Enter value of a: 45 cout<<“Enter value of a:”; Enter value of b: 56 cin>>a; Original value of a is:45 cout<<“Enter value of b:”; Original value of b is:56 cin>>b; After Swapping cout<<"Original value of a is:"<<a<<endl; New value of a is:56 cout<<"Original value of b is:"<<b<<endl; New value of b is:45 temp=a; a=b; b=temp; cout<<“After Swapping..”<<endl; cout<<“New value of a is:"<<a<<endl; cout<<“New value of b is:"<<b<<endl; getch(); }
  • 3. #include<iostream.h> #include<conio.h> class swapping { public: int anew,bnew,temp; void swap( int anew, int bnew) //function receives arguments via object of swapping class { temp=anew; anew=bnew; bnew=temp; Output cout<<“New value of a is:"<<anew<<endl; Value of a is: 10 cout<<“New value of b is:"<<bnew<<endl; } Value of b is: 15 }; After swapping void main() { New Value of a is: 15 int a=10,b=15; //we have set the values of a and b as 10 ,15, it can be user defined too. New value of b is: 10 clrscr(); swapping s1; //created object of swapping class cout<<“Value of a is:"<<a<<endl; cout<<“Value of b is:"<<b<<endl; cout<<“After Swapping”<<endl; s1.swap(a,b); //called swap function using object and dot operator getch(); }
  • 4. #include<iostream.h> #include<conio.h> void main() { int a, b; OUTPUT clrscr(); Enter value of a: 45 cout<<“Enter value of a:”; Enter value of b: 56 cin>>a; Original value of a is:45 cout<<“Enter value of b:”; Original value of b is:56 cin>>b; After Swapping cout<<“Value of a is:"<<a<<endl; New value of a is:56 cout<<“Value of b is:"<<b<<endl; New value of b is:45 a=a+b;; b=a-b; a=a-b; cout<<“After Swapping..”<<endl; cout<<“New value of a is:"<<a<<endl; cout<<“New value of b is:"<<b<<endl; getch(); }
  • 5. 2.Program to swap two values without using third variable.  #include<iostream.h>  #include<conio.h>  class swapping  {  public:  int anew,bnew;  void swap( int anew, int bnew);  };  void swapping :: swap(int anew , int bnew)  {  anew= anew+bnew; OUTPUT  bnew=anew-bnew; Enter value of a: 25  anew=anew-bnew; Enter value of b: 65  cout<<"new value of a is:"<<anew<<endl; Value of a is: 25  cout<<"new value of b is:"<<bnew<<endl; Value of b is:65  }  void main() After swapping  { Value of a is: 65  int a,b; Value of b is: 25  clrscr();  swapping s1,s2;  cout<<"Enter value of a:";  cin>>a;  cout<<"Enter value of b:";  cin>>b;  cout<<“Value of a is:"<<a<<endl;  cout<<“Value of b is:"<<b<<endl;  s1.swap(a,b);  getch();  }
  • 6. 3.Program to find maximum of 10 values stored in array.  #include<iostream.h>  #include<conio.h>  void main()  {  int a[10],i,j,m,loc=0; OUTPUT  clrscr(); Enter 10 elements of array:  cout<<"enter 10 elements of array:"; 5  for(i=0;i<=9;i++) 8  {  cin>>a[i]; 2  } 12  m=a[0]; 65  for(j=1;j<=9;j++)  { 36  if(a[j]>m) 98  { 45  m=a[j]; 25  loc=j+1;  } 96  }  cout<<"max value is:"<<m; Max value is: 98  cout<<"its loc is:"<<loc;  getch(); Its location is: 7  }
  • 7. 3.Program to find maximum of 10 values stored in array.  #include<iostream.h> OUTPUT  #include<conio.h>  class greatest  {  public:  int a[10],j,max;  int largest() //member func of greatest class that returns a value of integer type   { cout<<"enter 10 elements of array:"; Enter 10 elements of array:  for(int i=0;i<=9;i++) 5  {  cin>>a[i]; 8  }  max=a[0]; 2  for(j=1;j<=9;j++)  { 12   if(a[j]>max) { 65  max=a[j]; 36  }  } 98  return max;  } 45  };  void main() 25   { int max1; 96  clrscr();  greatest g1;  max1=g1.largest(); Max value is: 98  cout<<"Greatest of ten values is:"<<max1;  getch();  }
  • 8. 4.Program to find smallest of 10 values stored in an array.  #include<iostream.h>  #include<conio.h>  void main()  {  int min,a[10],I; OUTPUT  clrscr(); Enter 10 elements of array:  cout<<“Enter 10 elements of array.”; 5  for(i=0;i<=9;i++) 8  cin>>a[i]; 2 12  for(j=1;j<=9;j++) 65  { 36  If(a[j]<min) 98  min=a[j]; 45  } 25  cout<<“smallest of 10 values is:”<<min; 96  getch(); Smallest of ten values is: 2  }
  • 9. 4.program to find smallest of 10 values stored in an array.  #include<iostream.h>  #include<conio.h>  class smallest  {  public:  int a[10],j,min; OUTPUT  int calculate_smallest()  { Enter 10 elements of array:  cout<<"enter 10 elements of array:";  for(int i=0;i<=9;i++) -5  {  cin>>a[i]; 8   } min=a[0]; //0th element is set as minimum values 2  for(j=1;j<=9;j++) 12  {  if(a[j]<min) 65  {  min=a[j]; 36  }  } 98   } return min; 45  }; 25  void main()  { 96  int min1;  clrscr();  smallest s1;  min1=s1.calculate_smallest(); Smallest of ten values is: -5  cout<<“Smallest of ten values is:"<<min1;  getch();  }
  • 10. 5.Program to find largest of two values using conditional operator.  #include<iostream.h>  #include<conio.h>  void main() {  int a , b, c; OUTPUT Enter value of a: 56  clrscr(); Enter value of b: 36  cout<<“Enter value of a:”; 56 is greatest.  cin>>a;  cout<<“ Enter value of b:”;  cin>>b;  c=a>b?a:b; //using conditional operator, c stores the biggest of two values.  cout<<a<<“ is greatest”;  getch(); }
  • 11. 5.Program to find greatest of two values using conditional operator.  #include<iostream.h>  #include<conio.h>  class comparison  {  public:  int a1,b1,max;  int greatest (int a1,int b1)  {  max=a1>b1?a1:b1; //using conditional(ternary operator) to compare a and b, storing result in max.  return max;  }  };  void main()  {  int a, b;  clrscr(); OUTPUT  cout<<"enter a:";  cin>>a;  cout<<"enter b:";  cin>>b; Enter value of a: 62  comparison c1; Enter value of b: 36  cout<<"Greatest of two values is:"<<c1.greatest(a,b);  getch(); Greatest of two values is:62  }
  • 12. 6.Program to find smallest of three values using ternary operator.  #include<iostream.h>  #include<conio.h>  void main()  { OUTPUT  int a , b, c, max; Enter value of a: 96  clrscr(); Enter value of b: 125  cout<<"Enter value of a:"; Enter value of c: 36  cin>>a; 36 is greatest  cout<<" Enter value of b:";  cin>>b;  cout<<"Enter value of c:";  cin>>c;  max=a<b?(a<c?a:c):(b<c?b:c); //using conditional operator, max stores the biggest of three values.  cout<<max<<" is smallest";  getch(); }

Editor's Notes

  1. This is a program to swap two values using the third variable(temp). It does not use the class concept.The next program is same but it is done using class concept.
  2. This is same program as the previous one, but it use class structre.
  3. It is a program to swap two values without using third variable and without using class structure