NOTE : Using C-string. Functions that accept POINTER, not array. make sure you f
ID: 3554938 • Letter: N
Question
NOTE : Using C-string. Functions that accept POINTER, not array. make sure you free all the dynamic memories and no memory leak.
only can include Iostream, cctype, cstring, string, cstdlib, iomanip.
This is a question 9,10,12 in the book ISBN: 9780132576253 . Which I can find the solution in this chegg book solution. But This has a little bit edition.
Write the following functions in a single source code file named Write a function that accepts a pointer to a C-string as its argument. The function should verity that the string meets the following criteria for a valid password: The password length should be at least eight characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. The function should return true if the password is valid, or false otherwise. Write a function that accepts a pointer to a C-string as its argument The function should return the character that appeal's most frequently in the string. Document how your function responds if multiple characters share the same frequency. For example, given the string "zzaapp", which character will your function return as having the highest frequency? Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string1 for all occurrences of string2. When it finds an occurrence of string2, it should replace it with string3. For example, suppose the three arguments have the following values: string1: "the dog jumped over the fence" string2: "the" string3: "that" With these three arguments, the function would return a string object with the value "that dog jumped over that fence." Write a program to test each function using a menu-driven interface. String Function Tester. 1 - Password verifier 2 - Most frequent letter 3 - Replace substring 0 - Quit Enter choice? The user should be able to select a test, provide input, and view' the result. Remember to consider boundary conditions (e.g. empty strings, null pointers, etc.) in your functions. Write helper functions as necessary for your implementation.Explanation / Answer
#include <stdio.h>
#include <string.h>
int passwordverifier(char s[])
{
int i=0,flag1=0,flag2=0,flag3=0;
printf("str=%s ",s);
int len;
len=strlen(s);
if(len>=8)
{
flag1=1;
}
for(i=0;i<len;i++)
{
if(s[i]>=65&&s[i]<=90||s[i]>=97&&s[i]<=122||s[i]>=48&&s[i]<=57)
{
flag2=1;
}
}
printf("flag1=%d flag2=%d ",flag1,flag2);
if(flag1==1 && flag2==1)
return 1;
else
return 0;
}
void replace_substr()
{
char str1[20],str2[20],str3[20],temp[20];
int l1,i,j,n,k,l2,m;
printf("enter 3 strings ");
gets(str1);
gets(str2);
gets(str3);
l1=strlen(str1);
l2=strlen(str2);
for(i=0;i<l1;i++)
{
printf("test ");
for(j=i,k=0;j<l2;j++,k++)
{
temp[k]=str1[j];
}
temp[k]='';
printf("temp=%s ",temp);
n=strcmp(temp,str2);
if(n=0)
{
for(m=i;m<strlen(temp);m++)
{
str1[m]=str3[m];
}
}
}
return;
}
int main()
{
int ch,n;
char str[]="the dog jumped over the fence";
while(1)
{
printf("string function tester: ");
printf("1-passsword verifyer ");
printf("2-Most frequency leter ");
printf("3-Replace substring ");
printf("0-exit ");
printf("enter ur choice ");
scanf("%d",&ch);
if(ch==1)
{
n=passwordverifier(str);
if(n==1)
printf("password is valid ");
else
printf("password is invalid ");
break;
}
else if(ch==3)
{
replace_substr();
break;
}
else if(n==0)
{
exit(0);
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.