Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. (25pts) Given the string variables str1 and str2 contain \"you ought to start

ID: 3726378 • Letter: 6

Question

6. (25pts) Given the string variables str1 and str2 contain "you ought to start with logic" and ou respectively, what is the result of each of the following expressions? a. stri,length() b. str1.find(str2) c. str1.substr(4, 25) d. str1.substr(4, 25).find(str2) e. strl.substr.(str1.find("logic"),3) 7. (8 pts) Given the input data January 25, 2005 and the input statement cin>>string1 >>string2; What is contained in each of the string variables after the statement is executed? 8. (12 pts) Write a C++ program that computes and outputs the area of a circle, given the diameter of the circle. Be sure to use proper formatting and appropriate comments in your code. The output should be labeled clearly

Explanation / Answer

6

a. 29 (29 characters in str1)

b. 1 (find() returns the first occurance of str2 in str1 which is 1 here as it starts from 0)

c. ought to start with logic (starting from 4 character it displays the 25 characters in the string)

d. 0 (returns the first first occurance of ou in string 1 which is at index 0)

e. log ( str1.find("logic") will return 24 as it is the position of "logic" in str1, substr function will display 24 character upto 3 characters which is log)

2.

string1 = January

string2 = 25,

3.

#include <iostream>
#include <iomanip>
using namespace std;

int main() {

double diameter,area;

cout<<"Enter the diameter of the circle : ";
cin>>diameter;

area = 3.14 *(diameter/2) * (diameter/2) ;

cout<<fixed<<setprecision(2);// 2 decimal places

cout<<" Area of the circle : "<<area<<" square units";
return 0;
}

Output:

Enter the diameter of the circle :4.5
Area of the circle : 15.90 square units

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote