Skip to main content

Program in c++1

 #include <iostream>

using namespace std;


const int MAX_SIZE = 100;


class List {

private:

    int arr[MAX_SIZE];

    int size;

public:

    List() {

        size = 0;

    }


    void insert(int element) {

        if (size < MAX_SIZE) {

            arr[size++] = element;

            cout << "Element inserted" << endl;

        } else {

            cout << "List is full" << endl;

        }

    }


    void display() {

        if (size == 0) {

            cout << "List is empty" << endl;

        } else {

            for (int i = 0; i < size; ++i) {

                cout << arr[i] << " ";

            }

            cout << endl;

        }

    }


    void remove(int element) {

        int index = -1;

        for (int i = 0; i < size; ++i) {

            if (arr[i] == element) {

                index = i;

                break;

            }

        }

        if (index != -1) {

            for (int i = index; i < size - 1; ++i) {

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

            }

            size--;

            cout << "Element deleted" << endl;

        } else {

            cout << element << " not found" << endl;

        }

    }

};


int main() {

    List list;

    int choice, element;


    do {

        cout << "1. Insert" << endl;

        cout << "2. Display" << endl;

        cout << "3. Delete" << endl;

        cout << "4. Exit" << endl;

        cout << "Enter your choice: ";

        cin >> choice;


        switch (choice) {

            case 1:

                cout << "Element to insert: ";

                cin >> element;

                list.insert(element);

                break;

            case 2:

                list.display();

                break;

            case 3:

                cout << "Element to delete: ";

                cin >> element;

                list.remove(element);

                break;

            case 4:

                cout << "Exiting..." << endl;

                break;

            default:

                cout << "Invalid choice" << endl;

        }

    } while (choice != 4);


    return 0;

}


Comments

Popular posts from this blog

IMPORTANT C PROGRAMMING

  1) PROGRAM TO FIND SUM OF INDIVIDUAL DIGITS // Online C compiler to run C program online #include <stdio.h> int main() {    int num,sum=0,digit;    scanf("%d",&num);    while(num!=0)    {        digit=num%10;        num=num/10;        sum=sum+digit;      }    printf("%d",sum);  return 0; } OUTPUT 45 9 2) PROGRAM TO FIND REVERSE OF A GIVEN NUMBER #include <stdio.h> int main()  {    int num,sum=0,digit;    scanf("%d",&num);    while(num!=0)    {        digit=num%10;        num=num/10;        sum=sum*10+digit;      }    printf("%d",sum);  return 0; } OUTPUT 45 54 3) PROGRAM TO CHECK GIVEN NUMBER IS PALINDROME OR NOT #include <stdio.h> int main() {    int num,sum=0,digit,temp; ...

FIBONACCI SERIES

   PROGRAM TO  PRINT FIBONACCI SERIES #include <stdio.h> int main() { int i,n,a=0,b=1,c; printf("Enter value of n"); scanf("%d",&n); printf("%d\t",a); for(i=3;i<=n;i++) {     c=a+b;     a=b;     b=c;     printf("%d\t",c); } return 0; } OUTPUT: Enter value of n 10 0 1 2 3 5 8 13 21 34

TO FIND CHARACTERSITIC EQUATION OF A GIVEN MATRIX IN C LANGUAGE

                                  FIND S1,S2,S3 #include <stdio.h> int main()  {     int a,b,c,d,e,f,g,h,i,r,k,s;     printf("Enter 1");     scanf("%d",&a);      scanf("%d",&b);        scanf("%d",&c);     scanf("%d",&d);       scanf("%d",&e);          scanf("%d",&f);            scanf("%d",&g);             scanf("%d",&h);              scanf("%d",&i);             r=a+e+i;             k=((e*i)-(h*f))+((a*i)-(c*g))+((a*e)-(b*d));             s=((e*i)-(h*f))*a-((d*i)-(g*f))*b+((d*h)-(e*g))*c;             printf("S1 VALUE IS %d\n",r); ...