# include <iostream> # include <cstdlib> using namespace std; struct nod//node declaration { int info; struct nod *l; struct nod *r; }*r; class BST { public://functions declaration void search(nod *, int); void find(int, nod **, nod **); void insert(nod *, nod *); void del(int); void casea(nod *,nod *); void caseb(nod *,nod *); void casec(nod *,nod... Continue Reading →
Binary Heap
#include <iostream> #include <cstdlib> #include <vector> #include <iterator> using namespace std; class BHeap { private: vector <int> heap; int l(int parent); int r(int parent); int par(int child); void heapifyup(int index); void heapifydown(int index); public: BHeap() {} void Insert(int element); void DeleteMin(); int ExtractMin(); void showHeap(); int Size(); }; int main() { BHeap h; while (1)... Continue Reading →
Programming Principles
•Problem specification –our approach must be to determine overall goals, but precise ones, and then slowly divide the work into smaller problems until they become of manageable size. •Program design –Each part of a large program must be well organized, clearly written, and thoroughly understood, •Choice of data structures –How they are arranged in relation... Continue Reading →
Finding the remainder of array multiplication divided n
#include <iostream> using namespace std; int findrem(int arr[], int len, int n) { int mul = 1; for (int i = 0; i < len; i++) mul = (mul * (arr[i] % n)) % n; return mul % n; } int main() { int arr[] = { 10, 18, 45, 7, 12, 20 }; int... Continue Reading →
Splitting the array and adding the first part at the end
#include <bits/stdc++.h> using namespace std; void splitArr(int arr[], int n, int k) { for (int i = 0; i < k; i++) { int x = arr[0]; for (int j = 0; j < n - 1; ++j) arr[j] = arr[j + 1]; arr[n - 1] = x; } } int main() { int arr[]... Continue Reading →
Sum of elements of array
#include <iostream> using namespace std; int main (){ int arr[] = {6,12,4,7,9 }; int n = 7, sum = 0; for(int i = 0; i<n ; i++){ sum+=arr[i]; } cout<<"The array sum is "<<sum; return 0; }
Store and display information using structure in CPP
#include <iostream> using namespace std; struct student { char name[50]; int roll; float marks; } s[6]; int main() { cout << "Enter information of students: " << endl; for(int i = 0; i < 6; ++i) { s[i].roll = i+1; cout << "Roll number " << s[i].roll << ":" << endl; cout << "Enter name:... Continue Reading →
Sorting in Lexicographical Order
#include <iostream> using namespace std; int main() { string str[10], temp; cout << "Enter words (<=10): " << endl; for(int i = 0; i < 10; ++i) { getline(cin, str[i]); } for (int i = 0; i < 9; ++i) { for (int j = 0; j < 9 - i; ++j) { if (str[j]... Continue Reading →
Tower of Hanoi
Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time.2) Each move consists of taking the upper disk from one of... Continue Reading →
Linked Lists
Menu Driven Program For All Operations #include <stdio.h> #include <iostream> #include <limits.h> #include <stdlib.h> #include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; struct header { float avg; int max1,min1,max2,min2,totalnode; struct node *next; }; void headerfunc(struct header *); void insertf(struct header *); void deletef(struct header *); void bubble_sort(struct header *);... Continue Reading →
Arrays
Menu Driven Program For All Operations #include <stdio.h> #include <iostream> #include <limits.h> #include <stdlib.h> using namespace std; void insert(int *ar,int*n); void deletef(int *ar,int*n); void bubble_sort(int *ar,int*n); void display(int *ar,int*n); void avg(int *ar,int*n); void max_min(int *ar,int*n); void max2_min2(int *ar,int*n); void disp_odd(int *ar,int*n); void disp_even(int *ar,int*n); int main(void) { int n=0,ar[1000],i=0,c=0; cout<<"Enter size of array(max. 999) :... Continue Reading →
Book class 2
Imagine a publishing company that markets both books and audio- cassette version of its works. Create a class Publication in C++ that stores the title (a string) and price (type float) of a publication. From this class derive two classes: Book, which adds a page count and Tape, which adds playing time in minutes. These... Continue Reading →
Distance Measure
Define two classes Distance1 and Distance2 in C++. Distance1 stores distance in miles and Distance2 in kmeters & meters. Reads values of the class objects and adds one object of Distance1 with the object of Distance2 class. The display should be in the format of miles or kmeters & meters depending on the type of... Continue Reading →
Volume of box 1
Design a class named Box whose dimensions are integers and private to the class. The dimensions are labelled: length l, breadth b, and height h. The default constructor of the class should initialize l, b, h and to 0. The parameterized constructor Box(int length, int breadth, int height) should initialize Box's l, b and h... Continue Reading →
ComputerUserAccess 1
Users of the computer have profile which consists of Name, Password, and Access Rights. Access rights take on values X, R, W, and A. It is possible to have default values for Password and Access rights which are the first three letters of the Name and ALL respectively. Users can change their password and access... Continue Reading →
Class and Objects 3
Create a class Employees which have a number, rank, and salary. When an employee is first recruited then all these are given values of 0. Upon confirmation, the actual values of these are entered for the employee. At the time of promotion their rank can be incremented by 1 and an employee gets an increment... Continue Reading →
BankAccountClass 2
Define a class in C++ to represent a bank account. Include the following members: Data members: a) Name of the depositor containing charecters and space only b) Account number as of integer type of 4 digit c) Type of account as either saving or current d) Balance amount in the account positive integer Member functions:... Continue Reading →
You have been given a set of complex number. It is desired to add and substract the complex number.
Input Format First line contains one integer representing the real part of first complex number. Second line contains one integer representing the imaginary part of first complex number. Third line contains one integer representing the real part of second complex number. Fourth line contains one integer representing the imaginary part of second complex number. Constraints... Continue Reading →
Write a C++ program to represent call by value.
#include<iostream> using namespace std; void change(int data); int main() { int data=3; change(data); cout<<“value “<<data<<endl; return 0; } void change(int data) { data =5; } OUTPUT
Write a C++ program to represent the function overriding using AVERAGE() function.
#include <iostream> #include <string> using namespace std; int avrg( int , int ); int avrg( int , int, int); float avrg( float, int); int avrg(char, char); int main() { int average; cin >> average; int averageI; cin >> averageI; float x; cin >>x; float y; cin >>y; float averageF = avrg(x,y); char averageC = avrg('x','y');... Continue Reading →
Write a program in C++ to read and write the values in different variables using cascading of >> and <<
#include <bits/stdc++.h> using namespace std; int main(void) { int a; float b; char c; char str[50] ; cin>>a>>b>>c>>str; cout <<“integer – “<<a<<“\n”<<“float – “<<b<<“\n”<<“character- “<<c<<“\n”<<“string- “<<str; return 0; } OUTPUT
Write a C++ program to read and write the values in different types of variables using cin and cout.
#include <iostream> using namespace std; int main() { int i; cout<< "Enter an integer value: "; cin >>i; cout<< "Number entered is"<<i; cout<< " double of the number is"<<i*2<<"\n"; return 0; } OUTPUT
C++ & Object Oriented Programming
“C++: where friends have access to your private members.” — Gavin Russell Baker. C++ is an object oriented computer language created by extraordinary computer scientist Bjorne Stroustrop as part of the evolution of the C family of languages. It is a general purpose programming language and is widely used these days for competitive programming. It has... Continue Reading →