Posts

Showing posts from June, 2024

SORTING PROGRAM

 #include <iostream> using namespace std; int main() {     int n[5], i, num_elements;     cout << "Enter the number of elements (up to 3): ";     cin >> num_elements;     if (num_elements > 3) {         cout << "Number of elements exceeds the limit of 3." << end;         return 1;     }     cout << "Enter " << num_elements << " elements:" << endl;     for (i = 0; i < num_elements; i++) {         cin >> n[i];     }     int temp, j;     for (i = 1; i < num_elements; i++) {         j = i;         while (j > 0 && n[j] < n[j - 1]) {             temp = n[j];             n[j] = n[j - 1];             n[j - 1] = temp;  ...

TREE ORDER TRAVERSAL

 #include <iostream> using namespace std; class Tree {     struct Node {         string data; // Changed 'type' to 'string' to match the data being inserted         Node* left;         Node* right;                  Node(string d) : data(d), left(nullptr), right(nullptr) {}     }; public:     Node* root = nullptr;     Tree() {         Node* f = new Node("F");         Node* g = new Node("G");         Node* h = new Node("H");         f->left = g;         f->right = h;         root = f; // Corrected 'Root' to 'root'     }     void preorder(Node* ptr) {         if (ptr != nullptr) {             cout << ptr->data << " ";   ...

CONSTRUCTOR PROGRAM

 #include <iostream> using namespace std; class mark { public: int a,b,c; int total; mark() {     total=0; } void getdata() {     cout<<"enter the marks";     cin>>a;     cin>>b;     cin>>c; } void putdata() {     total=a+b+c;     cout<<total;     } }; int main() {     mark obj;     obj.getdata();     obj.putdata();     return 0; }

INHERITANCE PROGRAMMING

 #include <iostream> using namespace std; class input {     public:     int m1,m2,m3;     public:     void getdata()     {         cout<<"eneter the marks";         cin>>m1;         cin>>m2;         cin>>m3;     }     }; class output:public input {     int b;     public:     void putdata()     {         b=m1+m2+m3;     cout<<b;     }     }; int main() {     output obj;     obj.getdata();     obj.putdata();     return 0; }

OPERATOR OVERLOADING

 // Online C++ compiler to run C++ program online #include <iostream> using namespace std; int operation(int a,int b) {     return (a*b);      } float operation(float c,float d) {     return(c*d); } int main() {     int s=10,r=2;     float x=9,y=78;     cout<<operation(s,r);     cout<<"\n"<<operation(x,y); int nit=operation(s,r);     float iit=operation(x,y);    float vit=nit+iit;     cout<<"\n"<<vit; }

FUNCTION OVERLOADING

 #include <iostream> using namespace std; int operation(int a,int b) {     return (a*b); } float operation(float c,float d) {     return(c*d); } int main() {     int s=10,r=2;     float x=9,y=78;     cout<<operation(s,r);     cout<<"\n"<<operation(x,y); }

classes and objects for lab

 #include <iostream> using namespace std; class average {     public:     int a,b,c,d,e;     void getdata()     {     cout<<"Enter the 5 elements";     cout<<"\n";     cin>>a;     cout<<"\n";     cin>>b;     cout<<"\n";     cin>>c;     cout<<"\n";     cin>>d;     cout<<"\n";     cin>>e;     }     void putdata()     {         cout<<"the average is"<<a+b+c+d+e/5;     } }; int main() { average obj; obj.getdata(); obj.putdata(); return 0; }

LIST ADT USING LINKED LIST

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; Node* head = nullptr; void insert() {     int value;     cout << "\nEnter the element to insert: ";     cin >> value;     Node* newNode = new Node{value, nullptr};     if (!head) {         head = newNode;     } else {         newNode->next = head;         head = newNode;     } } void display() {     if (!head) {         cout << "\nList is empty\n";         return;     }     Node* temp = head;     cout << "\nList elements:\n";     while (temp) {         cout << temp->data << " ";         temp = temp->next;     }     cout << "\n"; } int main() { ...

linked list using array final final

 #include <iostream>  using namespace std;  void create();  void insert();  void deletion();  void search();  void display();  int a,b[100],c,d,e,f,i;  int main()  {      int s;      cout<<"\nMAIN MENU";      cout<<"\n\t1-CREATE\n\t2-INSERT\n\t3-DELETION\n\t4-SEARCH\n\t5-DISPLAY";      do      {          cout<<"\nenter ur choice";          cin>>s;          switch(s)          {            case 1:create();break;            case 2:insert();break;            case 3:deletion();break;            case 4:search();break;            case 5:display();break;            de...

Link

 https://www.mycompiler.io/recent https://saravanaultimatepds1lab.blogspot.com/?m=1

STACK ADT USING ARRAY

 #include <iostream> using namespace std; #define MAX 100  // Maximum size of the stack class Stack { private:     int top;     int arr[MAX]; public:     Stack() : top(-1) {}     void push();     void pop();     void display(); }; void Stack::push() {     if (top >= MAX - 1) {         cout << "Stack Overflow\n";         return;     }     int value;     cout << "Enter the value to push: ";     cin >> value;     arr[++top] = value;     cout << value << " pushed onto stack\n"; } void Stack::pop() {     if (top < 0) {         cout << "Stack Underflow\n";         return;     }     int value = arr[top--];     cout << value << " popped from stack\n"; } void Stack::display() { ...

LIST ADT USING LINKED LIST

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; Node* head = nullptr; void create(); void insert(); void deletion(); void search(); void display(); int main() {     int choice;     cout << "\n Main Menu";     cout << "\n 1.Create \n 2.Delete \n 3.Search \n 4.Insert \n 5.Display \n 6.Exit";     do {         cout << "\nEnter your choice: ";         cin >> choice;         switch (choice) {             case 1: create(); break;             case 2: deletion(); break;             case 3: search(); break;             case 4: insert(); break;             case 5: display(); break;             case 6: exit(0);     ...

LIST ADT USING ARRAY

 #include<iostream> using namespace std; void create(); void insert(); void deletion(); void search(); void display(); int a,b[20],n,d,e,f,i; int main() { int c; cout<<"\n Main Menu"; cout<<"\n 1.Create \n 2.Delete \n 3.Search \n 4.insert \n 5.Display \n 6.Exit"; do { cout<<"\n enter your choice:"; cin>>c; switch(c) { case 1: create(); break; case 2: deletion(); break; case 3: search(); break; case 4: insert(); break; case 5: display(); break; case 6: exit(0); break; default: cout<<"The given number is not between 1-5\n"; } } while(c<=6); return 0; } void create() { cout<<"\n Enter the number of elements you want to create: "; cin>>n; cout<<"\nenter the elements\n"; for(i=0;i<n;i++) { cin>>b[i]; } } void deletion() { cout<<"Enter the number u want to delete \n"; cin>>d; for(i=0;i<n;i++) { if(b[i]==d) { b[i]=0; cout<<d<<"...

OBJECT CREATION PROGRAM

 #include <iostream> using namespace std; class Sample { public:     int a;     // Constructor to initialize member variable     Sample() {         a = 10;     }     // Member function     void data() const {         cout << "adharsh" <<"\n";     } }; int main() {     // Create an instance of the class     Sample a1;     // Access the member variable and function     cout << a1.a << std::endl;     a1.data();     return 0; }

CLASSES CREATION

  #include <iostream> using namespace std; class sample   //class creation { public: static int a; // datatype static void data() { cout<<"i am the best"; } //function }; int sample::a=10; //declaring datatype int main() { cout<<sample::a<<"\n";    //printing data sample::data();    //printing function without return type return 0; }

COMPARISON TABLE

 COMPARISON TABLE NO RETURN TYPE - NO USE OF PRINT , USE VOID WITH RETURN TYPE - USE PRINT, NO USE OF VOID,USE INT

FUNCTIONS PART-4 WITH ARGUMENT AND NO RETURN TYPE

 #include <iostream> using namespace std; void adharsh(int a,int c) {     cout<<a+c; } int main() {    adharsh(20,30);     return 0; }

FUNCTIONS PART 3 WITH ARGUMENT AND WITH RETURN TYPE

 #include <iostream> using namespace std; int adharsh(int a,int c) {     return(a+c); } int main() {    cout<<adharsh(20,30);     return 0; }

FUNCTIONS PART-2 NO ARGUMENT AND WITH RETURN TYPE

 #include <iostream> using namespace std; int name() {     int a=90;     int b=90;     return a+b; } int main() {     cout<<name();     return 0; }

FUNCTIONS PART-1 NO ARGUMENT AND NO RETURN TYPE

 #include <iostream> using namespace std; void name() { int a=3; int c=9; cout<<a+c; } int main() {  name();  return 0; }