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

Write a loop that uses methods of the string class to solve the following proble

ID: 3874861 • Letter: W

Question

Write a loop that uses methods of the string class to solve the following problem. Don't use [l or the at method in your code. 2. Problem: Replace all spaces in a string with characters. Assume you have the following declaration: string tochange = "A String with Spaces!" 3. Determine whether the following array declarations are valid. If a declaration is invalid, explain why. a) string customers b) int numArray [50]; c) const int SIZE-30 double list[20-SIZE] d) int length = 50; double list[length-401 e) int ids [-30] f) colors [301 string:

Explanation / Answer

Q2
The code will be

size_t start_pos = 0;
while((start_pos = str.find(" ", start_pos)) != string::npos) {
str.replace(start_pos,1, "-");
}


Q3
a) This is wrong as size is not defined
b) this is correct
c) This is wrong as length of array can't be negative
d)This is correct
e) wrong as the size can't be negative
f) wrong format of initialization

Q4
The values stored in the array list after the execution of code are

list[0] = 1
list[1] = 1
list[2] = 3
list[3] = 3
list[4] = 13

Q5

in the first loop change

cin>>mylist;

to

cin>>mylist[i];

Do give a thumbs up. Thanks

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