i want help in c++ (three functions)

timer Asked: Dec 26th, 2017

Question description


In this program you need to develop a complete C++ program that consists of a main program and three functions, StringInsert(), ‘Stringclean(),’ and ‘StringCase()’

-StringInsert() function should have the following capabilities:

  • Receives two strings S1, and S2, and an integer ‘pos’. The maximum length of string S1 and S2 should not be greater than 20 characters.
  • Decide which string is the longest among S1 and S2
  • Insert the shortest string inside the longest string at a position specified by ‘pos’ and then add an extra space right after the position of S2. For example if the function receives those values: S1= “good sir”, S2=“morning”, and ‘pos’= 6 then since S1 is longer than S2 then S1 becomes “good morning sir” (note:observe the extra space between morning and sir).
  • The function should return an integer value of either 1 or 2 indicating which string is the longer S1, or S2. If S1 is longer the return value is 1 otherwise the return value is 2 (meaning S2 is bigger).
  • In case that both strings have the same value for length then any one string can be used as the longest string.
  • The function should always check the validity of the integer ‘pos’ for a right value. The right value should be bigger than 0 and less or equal the length of the longer string (0 <pos <=length of longer string), and if it is found not to be so the function should print an error message and returns 0.
  • Stringclean() function does the task of removing all extra spaces from a string leaving only one space between the words. It should work as follows:
  • StringCase() function does the task of converting the first character of each word in a string into upper case as follows:
  • The main program works as follows:
  • Receives a string as input parameter.
  • Remove any two consecutive spaces from the received string.
  • Repeat step 2 until one space is left between the words.
  • Return the new cleaned string.
  • Receives a string as input parameter.
  • Search from the beginning of the string and locate the first word, convert the first character to upper case, then move on to the next word and do the same thing until the last word in the string. For example, if the string’s original content is “ this Is a sentence” then the output string from this function is: “This Is A Sentence”. (note the modifications in red).
  • Asks the user to input two strings and an integer.
  • The program should then call StringInsert() function with those three values as input parameters and then print the returned string.
  • The program should then call Stringclean() function passing it the resultant string from the previous call (the returned string from function StringInsert) and then prints the returned string.
  • The program then calls function ‘StringCase()’, again passing it the resultant string from the previous call, and then prints the resultant string.

Note: It is important you provide proper commentaries on the source code so that it can be clearly understood.

5.If your functions are to be used as scripts in a web page. Discuss the possible techniques that will need to be done

Tutor Answer

(Top Tutor) Studypool Tutor
School: UIUC
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors