Write a function called deleteRepeats that has a partially filled array of chara
ID: 3702550 • Letter: W
Question
Write a function called deleteRepeats that has a partially filled array of characters as a formal parameter and that deletes all repeated letters from the array. Since a partially filled array requires two arguments, the function will actually have two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. When a letter is deleted, the remaining letters are moved forward to fill in the gap. This will create empty positions at the end of the array so that less of the array is used. Since the formal parameter is a partially filled array, a second formal parameter of type int will tell how many array positions are filled. This second formal parameter will be a call-by-reference parameter and wil be changed to show how much of the array is used after the repeated letters are deleted. For example, consider the following code: 1. char at10: int size 4; deleteRepeats (a, size) After this code is executed, the value of a[0] is 'a', the value of allis 'b, the value of at2] is 'e' and the value of size is 3. (The value of a[3] is no longer of any concen, since the partially filled array no longer uses this indexed variable.) You may assume that the partially filled array contains only lowercase letters. Embed your function in a suitable test program 14. You have collected tevis from sses an numbered ?. 3. Each : reviewer has tarediix monti where thie, mo its are 100105. The ratings raigefrom (b reviews are shown in dhe fiollihwing cabilt Write a program that storgs this data using 2D cay Based on this inforon your program should allow the user n enter rating for any thee movics ram should then find the reviewer whose ratings most doselymatch thc rating# pu t by the user. Itishould then predice ihe user inertother outpurzing che ratings by the reviewer for the movie the wthe use. Use the Cantesian distance as the metic to 2.Explanation / Answer
Solution:
code:
#include <iostream>
using namespace std;
void deleteRepeats(char *a,int *sizeAddr)
{
int flag[26]={0},size,tempsize; //this character array has size as 26 because it stores whether an alphabet has occurred or not//
size = *sizeAddr;
tempsize = size;
for(int i=0;i<size;i++)
{
if(flag[a[i]-'a']==0)
flag[a[i]-'a']=1;
else
{
for(int j = i;j<size;j++)
{
a[j]=a[j+1];
}
tempsize--;
}
}
*sizeAddr=tempsize;
}
int main() {
char a[100];
int size=0;
cout<<"Enter number of characters you are giving as an input : ";
cin>>size;
cout<<"Enter the elements of the array ";
for(int i=0;i<size;i++)
{
cin>>a[i];
}
deleteRepeats(a,&size);
cout<<"The new array is : ";
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"the new size is "<<size<<endl;
return 0;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.