Skip to main content

The Fundamentals of Digital Marketing Certification

The Fundamentals of Digital Marketing Certification
Trying to make use of some spare time during these endless lockdowns. I completed The Fundamentals of Digital Marketing course on Google Digital Garage and got certified. This is not a great victory, nevertheless, I celebrate every small step towards a greater goal. #googlegarage #fundamentalsofdigitalmarketing #digitalmarketing

FDS 9

 Practical No: -9

Experiment No. 9: A palindrome is a string of character that’s the same forward and backward.

Typically, punctuation, capitalization, and spaces are ignored. For example, “Poor Dan is in a droop”

is a palindrome, as can be seen by examining the characters “poor danisina droop” and observing that

they are the same forward and backward. One way to check for a palindrome is to reverse the

characters in the string and then compare with them the original-in a palindrome, the sequence will be

identical. Write C++ program with functionsa) To print original string followed by reversed string using stack

b) To check whether given string is palindrome or not

Code:

#include<iostream>

#include<string.h>

#define max 50

using namespace std;

class STACK

{

 private:

 char a[max];

 int top;


 public:

 STACK()

 {

 top=-1;

 }


 void push(char);

 void reverse();

 void convert(char[]);

 void palindrome();

};

void STACK::push(char c)

{

 top++;

 a[top] = c;

 a[top+1]='\0';


 cout<<endl<<c<<" is pushed on stack ...";

}

void STACK::reverse()

{

 char str[max];


 cout<<"\n\nReverse string is : ";


 for(int i=top,j=0; i>=0; i--,j++)

 {

 cout<<a[i];

 str[j]=a[i];

 }


 cout<<endl;

}

void STACK::convert(char str[])

{

 int j,k,len = strlen(str);

 for(j=0, k=0; j<len; j++)

 {

 if( ( (int)str[j] >= 97 && (int)str[j] <=122 ) || ( (int)str[j] >= 65 && (int)str[j] <=90 ))

 {

 if( (int)str[j] <=90 )

 {

 str[k] = (char)( (int)str[j] + 32 );

 }else

 {

 str[k] = str[j];

 }

 k++;

 }

 }

 str[k]='\0';

 cout<<endl<<"Converted String : "<<str<<"\n";

}

void STACK::palindrome()

{

 char str[max];

 int i,j;

 for(i=top,j=0; i>=0; i--,j++)

 {

 str[j]=a[i];

 }

 str[j]='\0';



 if(strcmp(str,a) == 0)

 cout<<"\n\nString is palindrome...";

 else

 cout<<"\n\nString is not palindrome...";

}

int main()

{

 STACK stack;

 char str[max];

 int i=0;


 cout<<"\nEnter string to be reversed and check is it palindrome or not : \n\n";


 cin.getline(str , 50);


 stack.convert(str);


 while(str[i] != '\0')

 {

 stack.push(str[i]);

 i++;

 }

 stack.palindrome();

 stack.reverse();


}

Output:

Poor Dan is in a Droop

Converted String : poordanisinadroop

p is pushed on stack ...

o is pushed on stack ...

o is pushed on stack ...

r is pushed on stack ...

d is pushed on stack ...

a is pushed on stack ...

n is pushed on stack ...

i is pushed on stack ...

s is pushed on stack ...

i is pushed on stack ...

n is pushed on stack ...

a is pushed on stack ...

d is pushed on stack ...

r is pushed on stack ...

o is pushed on stack ...

o is pushed on stack ...

p is pushed on stack ...

String is palindrome...

Reverse string is : poordanisinadroop

--------------------------------

Process exited after 11.85 seconds with return value 0

Press any key to continue . . . 

GALLERY

GALLERY
photos

ABOUT

HTML CSS, VB.net Developer and Java, C programming. With Loves Problem Solving and to Unreval the Mysteries behind the Magic of Computer Programming

Followers

MY PROJECTS

Popular posts from this blog

FDS 5

 Practical No: -5 Experiment No. 6: Write a python program to store first year percentage of students in array. Write function for sorting array of floating-point numbers in ascending order using a) Selection Sort b) Bubble sort and display top five score Code: # Function for Selection Sort of elements def Selection_Sort(marks):  for i in range(len(marks)):  # Find the minimum element in remaining unsorted array  min_idx = i  for j in range(i + 1, len(marks)):  if marks[min_idx] > marks[j]:  min_idx = j  # Swap the minimum element with the first element  marks[i], marks[min_idx] = marks[min_idx], marks[i]  print("Marks of students after performing Selection Sort on the list : ")  for i in range(len(marks)):  print(marks[i]) #<---------------------------------------------------------------------------------------> # Function for Bubble Sort of elements def Bubble_Sort(marks):  n = len(marks)  # Traverse throug...

FDS 4

 Practical No: -4 Experiment No. 4: a) Write a python program to store roll numbers of student in array who attended training program in random order. Write function for searching whether particular student attended training program or not, using linear search and sentinel search. b) Write a Python program to store roll numbers of student array who attended training program in sorted order. Write function for searching whether particular student attended training program or not, using Binary search and Fibonacci search. Code: import array as arr # Accept the Roll Numbers of the students def accept_roll():  a = arr.array('I', [])  no_stud = int(input("Enter the number of Students : "))  for i in range(0, no_stud):  a.append(int(input("Enter the Roll Number : ")))  return a # Print the Roll Numbers of the Students def print_roll(a):  for i in range(0, len(a)):  print("\t", a[i], end=" ")  print() # Linear Search def linear_search(a, x):  f...

Contact us

Name

Email *

Message *