This is a MIPS program Prompt the user and read in a string. Make your string la
ID: 3772582 • Letter: T
Question
This is a MIPS program
Prompt the user and read in a string. Make your string large enough to hold 100 characters.
Assuming there is just one blank between each word, count the number of words in the string.
Create a new string which is a copy of the original string, except that the new string is converted to uppercase. All non-letter characters should be unchanged. Convert the letters using difference between the ASCII codes for capital letters and the ASCII codes for small letters.
Print the original string, the new string, and the word count. Make sure you print messages to label your output.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[100],str2[100];
int len,i,count=0;
cout<<"Enter String: ";
gets(str);
cout<<"String at Start: "<<str<<endl;
for(i=0;i<100;i++)
{
if(str[i]>96&&str[i]<123&&str[i]!=' ')
{
str2[i]=str[i]-32;
}
else if(str[i]==' ')
{
count=count+1;
str2[i]=' ';
}
else
{
str2[i]=str[i];
}
}
cout<<"String after Conversion: "<<str2<<endl;
cout<<"Word Count: "<<count<<endl;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.