Posts

Showing posts from December 26, 2012

Write a program to solve the problem of tower of Hanoi with 3 pegs and N discs

#include #include class hanoi { int n; char peg_a, peg_b, peg_c; public: void towers_hanoi(int n, char peg_a, char peg_b, char peg_c); }; void hanoi::towers_hanoi(int n, char peg_a, char peg_b, char peg_c) { if (n<=0) { cout << "\nIllegal operation" ; } else if (n==1) { cout << "\nMove disk from :\t" << peg_a << "\tto\t" << peg_c; } else { towers_hanoi(n-1, peg_a, peg_c, peg_b); towers_hanoi(1, peg_a, peg_b, peg_c); towers_hanoi(n-1, peg_b, peg_a, peg_c); } } void main() { hanoi obj; int n; clrscr(); cout << "\nEnter numbers of disk :\t" ; cin >> n; obj.towers_hanoi(n, 'A', 'B', 'C'); getch(); }

Write a menu driven program to a) Find the length of a string b) concatenate two strings c) to extract a substring from a given string d) Finding and replacing a string by another string in a text (Use pointers and user-defined functions)

#include #include #include #include #include class string_manipulation { public: void lenstr(char *); void concatenate(char *, char *, char *); int str_rep(char *, char *, int c[]); void extract(); }; void string_manipulation::lenstr(char *p) { int len = 0; while (*p++) { len ++; } cout << "The length of the string is : " < }

Write a program to convert the given infix expression into its postfix form

#include #include #include #include int TOP = -1, rank = 0; char STACK[50]; class infix_exp { public: void PUSH(char item); char POP(); int F(char symbol); int G(char symbol); int RANK(char symbol); int infix_postfix(char infix[ ], char postfix[ ]); };