Question


Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a string entered from the keyboard (in lower case letters). The program will then provide 6 options about operations performed on the input string in the form of a menu, as shown in the following sample Input/Output. The 6 operations are given below: 1. print the string 2 reverse the string 3. print the length of the string 4. convert the lower letters to upper and the upper to lower in the string 5. count the lower and upper letters 6. to end the program Note: It is not allowed to use the string library functions for the 5 operations Sample Input/Output nter a string of size 1ee (maximum): This is a Test samPle Enter 1: Enter 2: Enter 3: Enter 4: Enter 5: Enter 9: To print the string To reverse the string To print the length of the string To convert the string case To count the lower and upper case letters To stop the program nter your choice: 2 1Pmas tseT a si sihT Enter 1: Enter 2: nter 3: nter 4: Enter 5: Enter 9: To print the string To reverse the string To print the length of the string To convert the string case To count the lower and upper case letters To stop the program nter your choice: 5 are 14 lower case letters and 3 upper case letters Enter 1: Enter 2: Enter 3: Enter 4: Enter S: Enter 9: To print the string To reverse the string To print the length of the string To convert the string case To count the lower and upper case letters To stop the program nter your choice: 9
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program code in C++


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char a[100], b[100];
int n;
cout<<"Enter a string of size 100(maximum): ";
cin.getline(a,100);
strcpy(b,a);
jump:
strcpy(a,b);
cout<<endl;
cout<<"Enter 1: To print the string"<<endl;
cout<<"Enter 2: To reverse the string"<<endl;
cout<<"Enter 3: To print the length of the string"<<endl;
cout<<"Enter 4: To convert the string case"<<endl;
cout<<"Enter 5: To count the lower and upper case letters"<<endl;
cout<<"Enter 9: To stop the program"<<endl;
cout<<endl<<"Enter your choice: ";
cin>>n;
cout<<endl;
switch(n)
{
case 1: cout<<a<<endl;
goto jump;
case 2:
{
char temp;
int i=0, j;
j=strlen(a)-1;
while(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
i++;
j--;
}
cout<<a<<endl;
goto jump;
}
case 3: cout<<strlen(a)<<endl;
goto jump;
case 4:
for(int i=0;i<strlen(a);i++)
{
if (65<=int(a[i]) && int(a[i])<=90)
{
a[i]=char(int(a[i])+32);
}
else if(int(a[i])>=97 && int(a[i])<=122)
{
a[i]=char(int(a[i])-32);
}
}
cout<<a<<endl;
goto jump;
case 5:
{ int u=0, l=0;
for(int i=0; i<strlen(a); i++)
{
if(int(a[i])>64 && int(a[i])<91)
u++;
else if(int(a[i])>96 && int(a[i])<123)
l++;
}
cout<<"There are "<<l<<" lower case letters and "<<u<<" upper case letters"<<endl;
}
goto jump;
case 9: return 0;
}
}

Input

# include<iostream» # include <cstring? using namespace std,; int main char a[100), b[100]: int n coutくくEnterよ5tring of 3ize 100 (maximum); ; cin.getline (a, 100) strcpy(D, a) jump: strcpy (a,b) cout<cendi: coutくくEnter 1; coutくくEnter 2: cout<<Enter 3: coutくくEnter 4: cout<<Enter 5 cont<<Enter 9: cout<cendl<<Enter your choice: cin>>n cout<cendl; To print the string<endl: To reverse the string<<endl; To print the length of the string<cendi; To convert the string case<<endl: To count the lower and upper case letters<<endl; To stop the program<cendii switch (n) 1: coutくくaくくendl ; goto jump; case case 2: char temp; int i#0, j; i-strlen (a)-1: while (i<j) temp-a [il a[1]=a(j); a [1 temp: coutくく くくendl ; goto jump case 3: cout<<scrlen (a) <<endl; goto jump: case 4 forint i=0;i<strlen (a) ;i++) if (65-int ali])&int(ali])<-90) a [11-har (int (a[1])+32) clse if(int (ali])-97&& int (ai)<-122) a [i]-char (int (a[i])-32) cout<<a<cendl: goto jump: case S: fint u-o, 1-0 1-0; for ( int ǐ<strlen (a); İ++) if(int (a[i])6 int (a[i)<91) u+t: else if (int(a[i])>96 && int (a[i])<123) coutくくThere are <<1<< lower case letters and <<u<< upper case lettersくくendl; goto iarm case 9: return 0

Output



Add a comment
Know the answer?
Add Answer to:
Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use C++ language, keep it simple Exercise #2: Strings' operations Write a C++ program that prompts...

    Use C++ language, keep it simple Exercise #2: Strings' operations Write a C++ program that prompts the user to enter a sentence, the program then does the following: 1. Prints the total characters in the sentence. 2. Prints the word count of the sentence, assuming only one space between each tow words. 3. Prints total vowel (a, e, i, o, u) in the sentence. 4. Prints the vowel frequency as shown in the sample below. 5. Prints the sentence in...

  • C++ Lab Quiz #3-B Upper Case Letters Write a main() program that reads a string and...

    C++ Lab Quiz #3-B Upper Case Letters Write a main() program that reads a string and calls the function int countUpper(string) which counts and returns the number of upper case letters in the string. The main) prints the result Sample inputs/outputs: nter a string: This is a C++ quIz numBer 4 This is a C++ quIz numBer 4" has 5 upper letters

  • Python: Write a program that lets the user enter a string and displays the letter that...

    Python: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string, ignore spaces, punctuation, and Upper vs Lower case. Create a list to hold letters based on the length of the user input Convert all letters to the same case Use a loop to check for each letter in the alphabet Have a variable to hold the largest number of times a letter appears, and replace the value when...

  • Write a program that reads a string from the keyboard and computes the two arrays of...

    Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...

  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • Must be in JAVA. Write a program that uses a Scanner to read in a String....

    Must be in JAVA. Write a program that uses a Scanner to read in a String. The program will then output a new String with all the vowels (upper and lower case) removed. See output for example output. Details Input A string composed of non-numeric characters Output The input string with the vowels removed Sample input: Welcome to Dalhousie Sample output: Dlhs nvrsty

  • PYTHON You are to write a program that will analyze the frequency of letters in a...

    PYTHON You are to write a program that will analyze the frequency of letters in a string. The user will enter a string, your program will output the number of times the letters of the alphabet appear in that string. The user is to enter a string that has upper or lower case letters only, no spaces or other characters. You should convert the string entered to all lowercase letters before you conduct your analysis.

  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • In this problem, you will write an assembly program (LC-3 assembly language) to process a string ...

    In this problem, you will write an assembly program (LC-3 assembly language) to process a string starting at memory location x5000, and is terminated by a ‘\0’ character (ASCII value = 0). For a given string beginning atmemory location x5000, convert all the upper-case English letters (A-Z) to lower-case, and all the lower case (a-z) to upper case. For example, if the string is “iLOVEComputerScience252”, the string after the processing should be: “IlovecOMPUTERsCIENCE252”. Store the string after the processing to...

  • In this problem, you will write an assembly program (LC-3 assembly language) to process a string...

    In this problem, you will write an assembly program (LC-3 assembly language) to process a string starting at memory location x5000, and is terminated by a ‘\0’ character (ASCII value = 0). For a given string beginning at memory location x5000, convert all the upper-case English letters (A-Z) to lower-case, and all the lower case (a-z) to upper case. For example, if the string is “iLOVEComputerScience252”, the string after the processing should be: “IlovecOMPUTERsCIENCE252”. Store the string after the processing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT