Month: April 2016

Multicore Programming – using posix_spawn() to create processes (C++)

/* Using multicore programming implement posix_spawn() function to create a process. */ /*Execution: oct@CCOMPL08-10:~$ g++ templ.cpp -o mat.o oct@CCOMPL08-10:~$ g++ multicore.cpp -lpthread oct@CCOMPL08-10:~$ ./a.out */ #include<iostream> #include<spawn.h> #include<sys/types.h> #include<sys/wait.h> using namespace std; int main(int argc, char *argv[], char *env[]){ pid_t pid, pid1; int status, status1; status = posix_spawn(&pid, "/bin/ls", NULL, NULL, argv, env); cout<<"------------------------ \n"; if(status == 0) cout<<"Process created successfully... \n"; cout<<"------------------------ \n"; wait(&pid); status1 = posix_spawn(&pid1, "mat.o", NULL, NULL, argv, env); cout<<"------------------------ \n"; if(status1 == 0) cout<<"Process created successfully... \n"; cout<<"------------------------ \n"; wait(&pid1); return 0; } View Article Page Download

Standard Template Library – Lists (C++)

Google standard template library to use list container and using C++ implement following member functions of list class: empty, insert,merge,reverse,sort

Bubble Sort – using Function Template (C++)

<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>/* Implement C++/Java/Python program for bubble sort using function template */ #include<iostream> using namespace std; template <typename X> void show(int n,X arr[]); template <typename T> void bubblesort(int n,T arr[]) { T temp; cout<<"\n Before sorting elements are:"; show(n,arr); for(int i=0;i<n-1;i++) { for(int j=0;j<n-i-1;j++) { if(arr[j]>arr[j+1]) { temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } cout<<"after sorting: \n"; show(n,arr); } template <class X> void show(int n,X arr[]) { cout<<endl; for(int k=0;k<n;k++) { cout<<arr[k]<<"\t"; } } int main() { int iarr[100],ch,n; float farr[100]; do { cout<<"\n \t BUBBLE SORT"; cout<<"\n ———————————"; cout<<"\n 1.Integer elements\n ... Read more

Exception Handling (C++)

  /* Create a c++ class named Television that has data members to hold the model no., screen size and price. Member functions include overloaded insertion and extraction operators. If more than 4 digits are entered call the model if screen size is smaller than 12 and greater than 70 inches or if price is negative or over $5000 then provide the . Write a main function that instantiates a television object which allows users to enter data and display data members. If an exception is caught then replace all data members with 0. */ #include<iostream> using namespace std; class ... Read more

File Operations, Derived Class & Virtual Class illustration (C++)

Design a C++ base class consisting of the data members. The derived class consists of the data members. Construct a virtual base class. The program should have the facilities. i) Build a master table ii) List a table iii) Insert a new entry iv) Delete old entry v) Edit an entry vi) Search for a record

Matrix Operations using Function Template (C++)

Write a program in C++ using function template to read two matrices of different data types such as integers and floating point values and perform simple arithmetic operations on these matrices separately and display it.

String Operations using Operator Overloading (C++)

String operations include: equality, copy, reverse, display, substrings and palindrome check using operator overloading.

Complex Number operations using operator overloading & friend function (C++)

Design a C++ class complex with data members for real and imaginery parts provide default and parameterized constructors. Write a program to perform arithmetic operations of two complex numbers using operator overloading. Use either member function or friend function.

Personal Database using types of constructors, friend, inline and dynamic memory concepts (C++)

Personal Database using types of constructors, friend, inline and dynamic memory concepts (C++)

Book Shop – using dynamic memory allocation (C++)

Book Shop - using dynamic memory allocation (C++)