In: Computer Science
// Assignment06.cpp : Defines the entry point for the console application.
//
#include
#include using namespace std;
int main()
{
string s = "this is a test, this is also a test, this is yet another test";
int strLen = 0;
strLen = s.length();
// code will go here
cout << s << endl;
return 0;
}
Add code to capitalize all of the lowercase ‘t’s. The problem may be simple, but the solution may be a bit tricky.
Using the length() function is useful to traverse the string using a for loop.
We can us if(s[i]=='t') to find out the small 't's and then us toupper() to convert to upper case.
CODE :
#include<iostream>
#include <cstring>
using namespace std;
int main()
{
string s = "this is a test, this is also a test, this is
yet another test";
int strLen = 0;
strLen = s.length();
// code will go here
for(int i=0;i<strLen;i++){
if(s[i]=='t'){
s[i] = toupper(s[i]);
}
}
cout << s << endl;
return 0;
}