(6 pts total) Design First (3 pts), Then Write Code (3 pts)!!! To help you pract
ID: 3605318 • Letter: #
Question
(6 pts total) Design First (3 pts), Then Write Code (3 pts)!!! To help you practice functions for Assignment #4, you will write a short program that asks the user to enter a string (get string)), makes a copy of the string, takes the copy and changes all non-space letters to dashes (set replace_string)), and gets a letter from the user to search and replace returning the number of letters found (get search_replace(). 8 5 You should design first... You can have more functions, but you must have at least the three below with the EXACT function prototypes Each of your functions should have the proper function headers/descriptions void get string(string ") void set replace_string(string, string" int get_search_replace(string, string &) Write the function headers/descriptions for each of the functions above, as well as all the functions you create! This includes information about parameters, returrn values, and pre/post conditions Design - Give as much detail as possible for the main function and all the functions above. o Why do the function prototypes have the specific parameter types on them? o Why do the functions have void or a return value? o How do all the functions interact together? Testing-Provide testing values with expected results. o o What do you plan to use as bad values? Good values? What do you expect to happen with bad values? Good values?Explanation / Answer
PLEASE GO THROUGH THE PROGRAM AND GIVE US UR FEEDBACK...
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
// This the functionto take input of string from the user.
// It has return type void as we dont wants any return value from here.
// it has one parameter which is a pointer of string type, it is used to point to the string
// memory location where we will save the original string.
// it takes inout of string from the user and assign that string value to the str pointer
// usint ->operator.
void get_string(string * str)
{ string in;
cout<<"input the string ";
getline(cin,in);
str->assign(in);
}
// this fuction is used to replace all the non-space letters to dashes.
// it also has void return type.
// it has two parameters. first is a string which store the cpy of the string.
// second is a pointer to the string which assign the changes made to the copy string to the variable
// in the main().
// this function scans all the string characters and replace it with '-' if it is non-space.
void set_replace_string(string a,string* b)
{
for(int i=0;i<a.length();i++)
{
if(a[i]!=' ')
a[i]='-';
}
b->assign(a);
}
// this function asks user to input a character to find in the original string and a character to replace those previous characaters in the original string.
// it has return type int as it returns the number of occurences of the searched characters in the oringinal string.
// it has two parametrs.
// first is a copy of the original string.
// second is a reference variable to the original string.
// this program scans each letter of the original string and if it is equal to 'ch' then change that to the 's'
// here 'ch' --> letter to be searched
// and 's'---> letter to rreplace searched letter 'ch'
int get_search_replace(string a, string &b)
{
int i=0;int cnt=0;
char ch;
cout<<"enter the character to be found ";
cin>>ch;
char s;
cout<<"enter the character to be replaced with ";
cin>>s;
for(i=0;i<b.length();i++)
{
if(b[i]==ch)
{
cnt++;
b[i]=s;
}
}
return cnt;
}
int main()
{
string str;
string copy;
get_string(&str);
cout<<"input string id==>"<<str<<" ";
set_replace_string(str,©);
cout<<"copied string after '-' replace==>"<<copy<<" ";
int count=get_search_replace(str,str);
cout<<"original string after raplace is==>"<<str<<" ";
cout<<"number of letter found==>"<<count<<" ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.