0% found this document useful (0 votes)
22 views2 pages

Q#1 #Include #Include #Include Using Namespace Void

This document contains 4 code snippets that perform string operations in C++. The first snippet erases characters from a user-input string. The second snippet counts the length of a user-input string. The third snippet converts a user-input lowercase string to uppercase. The fourth snippet counts the number of alphabets, digits, and other characters in a user-input string.

Uploaded by

ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Q#1 #Include #Include #Include Using Namespace Void

This document contains 4 code snippets that perform string operations in C++. The first snippet erases characters from a user-input string. The second snippet counts the length of a user-input string. The third snippet converts a user-input lowercase string to uppercase. The fourth snippet counts the number of alphabets, digits, and other characters in a user-input string.

Uploaded by

ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q#1

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
string s;
cout<<"\n\nEnter a STRING ";
getline(cin,s);
s.erase(3,8);
cout<<"\n\nDELETED STRING "<<s;
getch();
}

Q#2
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
string s;
int i;
int n=0;
cout<<"\n\nENTER A STRING ";
getline(cin,s);
for(i=0;s[i]!=0;i++)
{
n++;
}
cout<<"\n\nDELETED STRING "<<n;
getch();
}

Q#3
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
char str[20];
int i;
cout<<"\n\nEnter First Name in lowercase : ";
gets(str);
for(i=0;i<=strlen(str);i++)
{
if(str[i]>=97 && str[i]<=122)
{
str[i]=str[i]-32;
}
}
cout<<"\nThe name in UPPERCASE = "<<str;
getch();
}

Q#4
#include <iostream>
#include<conio.h>
using namespace std;
#define MAX_SIZE 100
int main()
{
char str[MAX_SIZE];
int alphabets, digits, others, i;
alphabets = digits = others = i = 0;
cout<<"\nEnter any string : ";
gets(str);
while(str[i]!='\0')
{
if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
{
alphabets++;
}
else if(str[i]>='0' && str[i]<='9')
{
digits++;
}
else
{
others++;
}

i++;
}

cout<<"\nAlphabets = "<<alphabets;
cout<<"\nDigits = "<< digits;
cout<<"\nSpecial characters = "<<others;
getch();
}

You might also like