C programming
C programming

Write a c++ program to sort a given input array elements make use of below mentioned class definition

Write a c++ program to sort a given input array elements make use of below mentioned class definition

C programming
C programming

 

Write a c++ program to sort a given input array elements make use of below mentioned class definition

 

//

//  main.cpp

//  SortByClass

//

//  Created by SHIVAM SINGH on 21/07/22.

//

#include <iostream>

using namespace std;

class demoArr

{

    int arr[5];

    public:

    void input( )

    {

        for(int i = 0; i<5 ; i++)

        {

            cout<<“Input the array : “<<endl;

            cin>>arr[i];

        }

    }

    void show( )

    {

        for(int i = 0; i<5 ; i++)

        {

            cout<<arr[i]<<endl;

        }

    }

    void sort( )

    {

        int count = 1;

        while (count<5)

        {

            for (int i = 0 ; i<5 -count ; i++)

            {

                if(arr[i]>arr[i+1])

                {

                    int temp = arr[i];

                    arr[i] = arr[i+1];

                    arr[i+1] = temp;

                }

            }

            count++;

        }

    }

};

int main() {

    

    demoArr obj;

    obj.input();

    cout<<“Display before sort”<<endl;

    obj.show();

    obj.sort();

    cout<<“Display after sort”<<endl;

    obj.show();

    

    

    return 0;

}

 

 

Topics Covered in this blog :

  • c (programming language)
  • arrays
  • computer programming (conference subject)
  • tutorial
  • lesson
  • language
  • pointers
  • array data structure
  • structures
  • for
  • learn
  • class
  • youtube
  • lectures
  • functions
  • education
  • beginners

 

 


 

Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.

Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.

 

🧑‍💻🧑‍💻 Social Media Links of Tech DCode :

👉🏻 YouTube : https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
👉🏻 Instagram : https://www.instagram.com/thetechdcode/
👉🏻 Facebook Page : https://www.facebook.com/thetechdcode
👉🏻 Twitter : https://twitter.com/thetechdcode
👉🏻 Telegram Channel : https://t.me/thetechdcode
👉🏻 Tech DCode Linktree : https://linktr.ee/thetechdcode
👉🏻 My Personal Handles : https://linktr.ee/virtualshivamin

🧑‍💻🧑‍💻 Social Media Links of SHIVAM SINGH (OWNER) :

👉🏻 Instagram : https://www.instagram.com/virtualshivamin/
👉🏻 Facebook Page : https://www.facebook.com/virtualshivamin/
👉🏻 Twitter : https://twitter.com/virtualshivamin/
👉🏻 Personal Linktree : https://linktr.ee/virtualshivamin 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *