Saturday, 14 November 2015

Deletion in an Array using Class

#include <iostream>
using namespace std;


class Deletion
{
private: int arr[10];

public:
    void input()
    {
        for (int i = 0; i < 10; i++)
        {
            cout << "Enter Number for Location: " << i << " = ";
            cin >> arr[i];
        }

    }

    void del(int loc)
    {
        for (int i = loc; i < 10; i++)
            arr[i] = arr[i + 1];
        arr[10 - 1] = NULL;
    }
    void print(int n)
    {
        for (int i = 0; i < n; i++)
            cout << arr[i];
    }
};


int main()
{
    int loc;

    Deletion obj;
    obj.input();
    cout << "Enter Location to Delete";
    cin >> loc;
    obj.del(loc);
    obj.print(9);

}

No comments:

Post a Comment

Tree Insertion

#include <iostream> using namespace std; struct node {     int data;     node*left;     node* right; }; class tree { priva...