Skip to main content

Posts

Linked List using C

Linked List program using C language Operations :- Create list, insertion (beg, mid, end), deletion (beg, mid, end) #include<stdio.h> #include<conio.h>  void inst_beg();  void inst_mid();  void inst_end();  void del_beg();  void del_mid();  void del_end();  void traverse();  int count();  struct node  { int num;    struct node *next;  }*start=NULL;  typedef struct node node;  typedef struct node* nptr;  void main()  { char choice;    while(1)    {    clrscr();    printf("-------LINKED LIST-------\n\n");    printf(" 1.Insertion at begining\n");    printf(" 2.Insertion at mid\n");    printf(" 3.Insertion at end\n");    printf(" 4.Deletion from begining\n");    printf(" 5.Deletion from mid\n");    printf(" 6.Deletion from end\n");    printf(" 7.Traverse\n");    printf(" 8....

Virtual Base Class / Diamond Problem in C++

Virtual Base Class / Diamond Problem in C++ Ø   When we try to implement multiple inheritance or multipath inheritance multiple base classes are inherited that are also inherited from same super-base class. §   An element of ambiguity can be introduced into a C++ program when multiple base classes are inherited. Ø   For example: - #include<iostream> using namespace std; class Base {       public:              int a; }; class D1:public Base    // D1 inherits Base {       public:               int b; }; class D2:public Base    // D2 inherits Base {       public:              int c; }; class D3:public D1, public D2  ...

Object Slicing in C++

What is object slicing in c++ ? When a Derived Class object is assigned to Base class, the base class' contents in the derived object are copied to the base class leaving behind the derived class specific contents. This is referred as Object Slicing. Class Base { public: int i; }; class Derived : public Base { public: int j; }; int main() { Base Bobj; Derived Dobj; Bobj = Dobj; //Here Dobj contains both i and j. //But only i is copied to Bobj. } Object slicing is a concept where additional attributes of a derived class object is sliced to form a base class object. Object slicing doesn't occur when pointers or references to objects are passed as function arguments since both the pointers are of the same size. Object slicing will be noticed when pass by value is done for a derived class object for a function accepting base class object. Object slicing could be prevented by making the base class function pure virtual there by disallowing objec...

UNIX Shell & History Feature

Operating System Project Implementation of  UNIX Shell & History Feature in C language Note: - Implement this code on Linux platform How to Compile?       cc -o exec_name source_name.c  Source Code: - /* press ctrl-c to show history & press ctrl-d to exit from command prompt */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <signal.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 80 /* 80 chars per line, per command, should be enough. */ #define BUFFER_SIZE 50 #define buffer "\n\nCommand History:\n" char history[10][BUFFER_SIZE]; int count = 0; int caught = 0; void printHistory() { int i; int j = 0; int hcount = count; for (i = 0; i<10;i++) { printf("%d.  ", hcount); while (history[i][j] != '\n' && history[i][j] != '\0') { printf("%c", history[i][j]); j++; } printf("\n"); j =...

Stack operations using Linked List implementation

#include<iostream> using namespace std;  void push();  void pop();  void traverse();  struct node  { int num;    struct node *next;  }*top=NULL;  typedef struct node node;  typedef struct node* nptr;  void main()  { char choice;    while(1)    {    system("cls");    cout<<"-----STACK USING LINKED LIST-----\n\n";    cout<<" 1.PUSH\n";    cout<<" 2.POP\n";    cout<<" 3.TRAVERSE\n";    cout<<" 4.EXIT\n";    cout<<" Enter your choice: ";    cin>>choice;    switch(choice)    { case '1': push();       break;      case '2': pop();       break;      case '3': traverse();       break;      case '4': exit(0);      default: cout...

Create Simple Class

        Define a class to represent a bank account. Include the following members: Data Members: Name of the depositor Account Number Type of account Balance amount in the account. Member functions: To assign initial values To deposit an amount To withdraw an amount after checking the balance. To display name and balance. #include<iostream> #include<string> using namespace std; class bank { string name; int ac_no; string ac_type; int bal; public: bank() { //name[]="Default"; name="Default"; ac_no=0; //ac_type[]="Default"; ac_type="Default"; bal=0; } void get_data() { cout<<"Enter Name: "; cin>>name; cout<<"\nEnter Account No: "; cin>>ac_no; cout<<"\nEnter Account Type: "; cin>>ac_type; cout<<"\nEnter Initial Balance:"; cin>>bal; } void deposit() { int d_bal=0; ...

Copy the contents of one file to another

WAP to copy the contents of one file to another. Use command line arguments. #include <iostream> #include <fstream>                                                     #include <cstdlib> using namespace std;                                                   void print_error(const char*, const char* = " ");                     void main(int argc, char* argv[])                                       {      if (3 != argc)          print_error("usage: copy source file to destination file");      ifstream in( arg...