Skip to main content

DSL

5: Problem Statement:
Write C++ program for string operations- copy, concatenate, check substring, equal, reverse and length
#include<iostream>

#include<cstdio>

using namespace std;

int Length(char str[50])

{

int count=0,i=0;

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

{

count++;

i++;

}

return count;

}

void Palindrome(char str[50])

{

int k=Length(str)-1;

int i,p=0;

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

{

if(str[i++]==str[k--]){

p=1;

break;

}

}

if(p==1)

{

printf("Entered string is Palindrome\n");

}

else{

printf("Entered string is not palindrome\n");

}

}

void copy_string(char str[50])

{

char ch[50];

printf("Enter second string which you want to copy!!\n");

scanf("%s",ch);

int i=0;

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

{

str[i]=ch[i];

i++;

}

printf("copied string is : %s \n",str);

}

void Reverse(char str[50])

{

int k=Length(str)-1;



printf("\nReversal of string is : ");

for(int i=k;i>=0;--i){

cout<<str[i];

}

cout<<endl;

}

void string_comparison(char str[50])

{

char ch[30];

printf("Enter string which you want to compare!\n");

scanf("%s",ch);

int i = 0;

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

i++;

if (str[i] > ch[i])

printf("String first is greater than second.\n");

else if (str[i] < ch[i])

printf("String second is greater than first.\n");

else

printf("str1 and str2 are equal.\n");

}

void sub_string(char str[50])

{

char search[10];

int count1 = 0, count2 = 0, i, j, flag;

printf("Enter search substring:");

cin>>search;

count1=Length(str);

count2=Length(search);

for (i = 0; i <= count1 - count2; i++)

{

for (j = i; j < i + count2; j++)

{

flag = 1;

if (str[j] != search[j - i])

{

flag = 0;

break;

}

}

if (flag == 1)

break;

}

if (flag == 1)

printf("String Found!\n");

else

printf("String not Found");

}

int main()

{

int ch;

char str[50];

printf("Enter string \n");

scanf("%s",str);

do{

cout<<"\n******MENU******\n";

cout<<" 1.Length of string\n 2.Palindrome\n 3.Copy_String\n 4.Reverse string\n";

printf(" 5.String Comparison\n 6.Substring\n");

cout<<"Enter your choice\n";

cin>>ch;

switch(ch)

{

case 1:

cout<<"Length of entered string is = "<<Length(str)<<" \n";

break;

case 2:

Palindrome(str);

break;

case 3:

copy_string(str);

break;

case 4:

Reverse(str);

break;

case 5:

string_comparison(str);

break;

case 6:

sub_string(str);

break;

}



}

while(ch>=0&&ch<=6);

}

Comments

Popular posts from this blog

DSL

9: Program Setatement 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 functions- 1. to check whether given string is palindrome or not that uses a stack to determine whether a string is a palindrome. 2. to remove spaces and punctuation in string, convert all the Characters to lowercase, and then call above Palindrome checking function to check for a palindrome 3. to print string in reverse order using stack Program: #include<iostream> #include<string.h> #define MAX 100 using namespace std;  struct stack ...

DSL

4: Problem Statement: Write C/C++ program for storing matrix. Write functions for  a) Check whether given matrix is upper triangular or not  b) Compute summation of diagonal elements  c) Compute transpose of matrix  d) Add, subtract and multiply two matrices #include<iostream> #include<cstdio> void Upper_Triangular(int a[10][10],int n,int m) { for(int i=0;i<n;i++){ printf("\n"); for(int j=0;j<m;j++) if(i>=j) printf(" %d ",a[i][j]); else printf(" %d ",0); } } void Addition(int a[10][10],int b[10][10],int m,int n) { int c[10][10],i,j; for(i=0;i<m;++i) { for(j=0;j<n;++j) { c[i][j]=0; c[i][j]+=a[i][j]+b[i][j]; } } printf("\nAddition Of two Matrix is : \n"); for(i=0;i<m;++i) { for(j=0;j<n;++j) { printf(" %d ",c[i][j]); } printf("\n"); } } void Dif...

OOP

6.Problem statement Develop an object oriented program in C++ to create a database of student  information system containing the following information: Name, Roll number, Class, division, Date of Birth, Blood group, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, Copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete. Program #include<iostream> #include<stdio.h> #include<cstring> using namespace std; class personal; static int count; class person {       char *name;       int *rollno,*classno;       char *bloodgroup,*div;                   public:person()              {     ...