Showing posts with label Assignment. Show all posts
Showing posts with label Assignment. Show all posts

Saturday, 8 October 2016

C++ program to implement Stack Using Vector in STL


/*
Problem Statement: C++ program to implement Stack Using Vector in STL
Author: Pavan R Jaiswal

Options: 
  1: Push Element to Stack
  2: Pop element from stack
  3. Display stack

Note:  We can't traverse (iterate) through stack. Stacks are a type of container adaptor, specifically designed to operate in a LIFO 
 context (last-in first-out), where elements are inserted and extracted only from one end of the container. Elements 
 are pushed/popped from the "back" of the specific container, which is known as the top of the stack. It is not 
 intended for stack to show this behavior, for this we have other containers like vector. In case of vector use push_back()
 and pop_back() functions.

 reverser_iterator class is called in below code to traverse the vector in reverse orde. 
*/

#include "iostream"
#include "vector"
#include "stdlib.h" // used for exit(0)

using namespace std;

class StackUsingVectorSTL{
 public:
  vector<int> pushToStack(vector<int>);
  vector<int> popFromStack(vector<int>);
  void displayStack(vector<int>);
};

Thursday, 6 October 2016

C++ program to implement Sorting Container in STL


/*
Problem Statement: C++ program to implement Sorting Container in STL
Author: Pavan R Jaiswal

Options: 
  1: Add Element to List
  2: Display Sorted List
*/

#include "iostream"
#include "list"
#include "stdlib.h" // used for exit(0)

using namespace std;

class SortingContainerSTL{
 public:
  list<int> addElementToList(list<int>);
  void displaySortedList(list<int>);
};

Wednesday, 5 October 2016

C++ program to implement Map using STL


/*
Problem Statement: C++ program to implement Map using STL
Author: Pavan R Jaiswal

Options: 
  1: Add Element
  2: Delete Element
  3: Display Map
*/

#include "iostream"
#include "map"


using namespace std;

class MapSTL{
 public:
  map<int, string> addElement(map<int,string>);
  map<int, string> deleteElement(map<int,string>); 
  void displayMap(map<int, string>);
};

C++ program to implement List using STL


/*
Problem Statement: C++ program to implement List using STL
Author: Pavan R Jaiswal

Options: 
  1: Add Element At Front
  2: Add Element At Back
  3: Delete Element From Front
  4: Delete Element From Back
  5: Display List
*/

#include "iostream"
#include "list"

using namespace std;

class ListSTL{
 public:
  list<int> addElementAtFront(list<int>);
  list<int> addElementAtBack(list<int>);
  list<int> deleteElementFromFront(list<int>);
  list<int> deleteElementFromBack(list<int>);
  void displayList(list<int>);
};

Tuesday, 4 October 2016

Function template to perform selection sort on integer and float array in C++

/*
Problem Statement: Function template to perform selection sort on integer and float array in C++ 
Author: Pavan R Jaiswal
*/
#include "iostream"
using namespace std;

class SelectionSort{
 public:
 template <typename type> //keyword "typename" can be replaced by keyword "class" 
  type selectionSort(type tarr[5]){
//   cout<<tarr[4];
   int min;
   float temp;
   for(int i=0;i<5;i++){
    min=i;
    for(int j=i+1;j<5;j++){
     if(tarr[min] > tarr[j]){
      min=j;
     }
    }
    temp = tarr[min];
    tarr[min] = tarr[i];
    tarr[i] = temp;
   }
   cout<<"\nSorted array: "<<endl;
   for(int cnt=0; cnt<5; cnt++) 
    cout<<tarr[cnt]<<endl;
  }
};

Function Template in C++


/*
Title: Function template in C++
Author: Pavan R Jaiswal
 
In C++, function templates are functions that serve as a pattern for creating other similar functions. \
The basic idea behind function templates is to create a function without having to specify the exact type(s) 
of some or all of the variables. Instead, we define the function using placeholder types, called template type
parameters.

Problem Statement: Use function template to check greater number from given two numbers
*/
#include "iostream"
using namespace std;

class FunctionTemplate{
 public:
 template <typename type> //keyword "typename" can be replaced by keyword "class" 
  type greaterNumber(type tNum1, type tNum2){
   return (tNum1>tNum2)?tNum1:tNum2;
  }
};

Thursday, 18 August 2016

Doubly LinkedList Operations in C++

/*
Title: C++ program to demonstrate doubly linked list.
Author: Pavan Jaiswal
Operations: 
 1. Add nodes to linkedlist at the begining and at the end.
 2. Display the linkedlist.
 All rest operations can be made as per your choice.
 
*/

#include "iostream"
#include "stdlib.h"
using namespace std;

/* structure to hold list */
struct list{
 string name;
 int rollno;
 struct list *next, *prev;
}*first=NULL, *last=NULL, *node=NULL, *start=NULL;

/* class to perform operations */
class LinkedList{
 public:
 /* member function declaration */
  void insertAtBegining(); 
  void insertAtEnd();
  void displayList();
};

Singly LinkedList Operations in C++

/*
Title: Singly linkedlist demonstration in C++
Author: Pavan Jaiswal
Operations: 1. Add node to list
  2. Display list
  Rest operations can added as per your choice. 
*/

#include "iostream"
#include "stdlib.h"

using namespace std;

struct list{
 string name;
 struct list *next;
}*head=NULL, *tail=NULL, *node=NULL;

class SinlgyLinkedList{
 public:
  void addNodeToList();
  void displayList();
};

Monday, 18 July 2016

C++ program to perform addition on complex numbers using operator overloading and friend function

/*
Title:    C++ program to perform addition on complex numbers using operator overloading and friend function
Author: Pavan Jaiswal
FileName: 1ComplexNos.cpp

Description:
    --> Below C++ source code demonstrates addition on complex nos
    --> Here we have used two features of C++ language. That is "Operator Overloading" & "Friend Function"
    --> Operators overloaded are "+", "<<" and ">>"

*/

#include "iostream"
using namespace std;

class ComplexNos{
    private:
        int real, img; // private data members to accept real and imaginary parts of complex nos

    public:
        friend istream & operator >>(istream &, ComplexNos &); // Declaration of friend function >>
        friend ostream & operator <<(ostream &, ComplexNos &); // Declaration of friend function <<

        ComplexNos operator +(ComplexNos); // Declaration of function +
   
};

C++ program to implement calculator functionality

/*

Title: C++ program to implement calculator functionality
Author: Pavan Jaiswal
FileName: 5Calculator.cpp

Description:
    --> Below C++ source code demonstrates calculator to perform basic arithmetic operations
    --> Idea is user will provide expression as in input. Say for eg. 1 + 3.
    --> So depending on operator inputted, respective switch case will be called.
    --> Four different member functions are defined outside the class definition. 

*/

#include "iostream"
using namespace std;

class Calculator{
   
    public:
        /* public member functions of class. Each one of them taking two operands as an input */
        float addition(float num1, float num2);
        float subtraction(float num1, float num2);
        float multiplication(float num1, float num2);
        float division(float num1, float num2);

};

Tuesday, 12 July 2016

C++ program to demonstrate friend funtion

/*
Title:     C++ Program to demonstrate friend funtion
Author: Pavan Jaiswal
FileName: 3Friendfunction.cpp

Description:
    --> There would be a requirement sometime where you are suppose to access private data member outside the class scope.
    --> Friend function is a one of the solutions. It allows to access private data members of a class.
    --> In the below source code we have one class which have one private data member, one member function and one friend function.
    --> Idea is to set value to class data member through a member function and to print value of it through a friend function.
*/


Wednesday, 23 September 2015

Create ISO Boot Image Using ISOLinux and MKISOFS Uitility on Linux Box

Dear Viewers

This post will help you to create ISO boot image using ISOLinux and mkisofs utility on Linux box.

Prerequisite:
1. Syslinux archive.
2. Binary files, source code files and other required configuration file of any preferable  Linux flavor.
3. mkisofs utility installed.


Friday, 7 August 2015

Data analysis using Hive script

Dear Viewers,

This post will help you to run hive script on hive table. Hive script is made for below given title.

Hive script can be saved with the extension '.hql' or '.sql' . Copy paste the below code in a file "HiveScript.hql". In hive script, single line comment is given by '--'.


Sunday, 31 August 2014

Create ISO boot image using open source tools

Problem statement
Create ISO boot image using open source tool

Solution
Various open source tools are available to create ISO boot image starting with Linux platform, Windows platform and many more. We are interested here to use tools that are used for Linux distribution. Here we used ISOLINUX and SteamOSInstaller. Detailed information about them is as below.

Note: Screen shots provided below in this post will help you to create .iso file of Fedora 20. If you wish to create .iso file of Ubuntu, you may follow the another link -
http://www.pavanjaiswal.com/2015/09/create-iso-boot-image-using-isolinux.html

   1.     ISOLINUX
ISOLINUX is a boot loader for Linux/i386 that operates off ISO 9660/El Torito CD-ROMs in "no emulation" mode. This avoids the need to create an "emulation disk image" with limited space (for "floppy emulation") or compatibility problems (for "hard disk emulation".)


Detecting computer is booted with BIOS or UEFI

Problem statement
Write a program in Python / C++ to test that computer is booted with legacy boot ROM-BIOS or UEFI 


Solution
   A.    Introduction to booting
When we start our computer then there is an operation which is performed automatically by the Computer which is also called as Booting. In the Booting, System will check all the hardware’s and Software’s those are installed or Attached with the System and this will also load all the Files those are needed for running a system.
In the Booting Process all the Files those are Stored into the ROM Chip will also be Loaded for Running the System. In the Booting Process the System will read all the information from the Files those are Stored into the ROM Chip and the ROM chip will read all the instructions those are Stored into these Files. After the Booting of the System this will automatically display all the information on the System. The Instructions those are necessary to Start the System will be read at the Time of Booting.


Saturday, 30 August 2014

Socket programming in Linux

Problem statement
Use python for socket programming to connect two or more PCs to share a text file

Solution
   A.     Introduction
Sockets allow communication between two different processes on the same or different machines. To be more precise, it's a way to talk to other computers using standard Unix file descriptors. In Unix, every I/O actions are done by writing or reading to a file descriptor. A file descriptor is just an integer associated with an open file and it can be a network connection, a text file, a terminal, or something else.
To a programmer a socket looks and behaves much like a low level file descriptor. This is because commands such as read() and write() work with sockets in the same way they do with files and pipes. The difference between sockets and normal file descriptors occurs in the creation of a socket and through a variety of special operations to control a socket.
Sockets were first introduced in 2.1BSD and subsequently refined into their current form with 4.2BSD. The sockets feature is now available with most current UNIX system releases.

Create Linux Virtual File System

Problem statement
Write a python program for creating Virtual File System on Linux environment 

Solution
   A.    History of Linux filesystem
Linux is a Unix-like operating system, which runs on PC-386 computers. It was implemented first as extension to the Minix operating system [Tanenbaum 1987] and its first versions included support for the Minix filesystem only. The Minix filesystem contains two serious limitations: block addresses are stored in 16 bit integers, thus the maximal filesystem size is restricted to 64 mega bytes, and directories contain fixed-size entries and the maximal file name is 14 characters.


Tuesday, 29 July 2014

Create RAMDisk on Linux platform

Problem statement: 
Write a program in C++ to create a RAMDRIVE and associate an a cyclic directory structure to it. Use this RAMDRIVE to store input, out files to run a calculator program.

Solution:

   A.    Basics of RAMDisk
As name suggest, RAMDisk is basically hard disk portion which is used / treated as RAM portion. It means, from actual RAM, we utilize few size to be used as RAMDisk. For e.g out of 2GB RAM size, you may allocate 512 MB size to newly created portion. Ramdisk or ramdrive is part of system memory that applications/user can use just like normal disk space — e.g. to create folders and files in it and manipulate them with dramatically better performance rather if they were stored on the hard drive. This is because Ram memory is much faster than other forms of storage.
By default Ubuntu has ramdisk mounted into /dev/shm/ directory so you can just copy/move files into that dir and be sure they’ll be stored in RAM memory. That could be useful for, say, video conversion when both input and output files are stored in ramdisk — resulting performance will be better as read and write speeds are higher for ram than for hdd or any other storage. This is due to the fact CPU cannot access to HDD directly while it can do it with RAM. There are two types of RAMDisk: 1. ramfs (not much used now a days) and 2. tmpfs (mostly used).

Thursday, 24 July 2014

Use pipe to perform Inter-Process Communication (IPC)

Problem statement: Write an IPC program using pipe. Process A accepts a character string and Process B inverses the string. Pipe is used to establish communication between A and B processes using Python or C++.

Solution: 
   A.    Basics of Inter-Process Communication (IPC)
Inter-Process-Communication (or IPC for short) are mechanisms provided by the kernel to allow processes to communicate with each other. On modern systems, IPCs form the web that binds together each process within large scale software architecture. 
The Linux kernel provides the following IPC mechanisms:


Wednesday, 23 July 2014

Display i-node information of given file

Problem statement: Display i-node information of given file using C++ or Python language

Solution:
    A.     Introduction
The inode (also known as Index Node) is a very basic concept related to Linux and UNIX filesystem. Each and every object/element in the filesystem is associated with an inode.
You must be aware of the fact that, most of the countries have given a unique identity to their citizens in the form of a unique identification number ('Aadhar Card' in India and 'SSN' in the USA) to identify an individual easily and uniquely. This also leads to make all the paper work corresponding to any citizen easier to be handled.
Just like these identification numbers for people, there is a unique identity of every member of a Linux filesystem which is known as Inode number and it uniquely exists for each and every individual file on Linux or Unix filesystem.