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

CS 539 Lab 4B and 5B NOTE: No library funcions may be used in these programs exc

ID: 3699056 • Letter: C

Question

CS 539 Lab 4B and 5B NOTE: No library funcions may be used in these programs except input and output functions such as getchar, putchar, gets, puts. LAB 4B Obiective: To gain experience in using arrays, strings, and functions. Plan, code, and execute a C program to a a) code a function to generate a string,sl,coutaining a random pattern of upper case lettersA Problem definition dength 40 characters) b) code a function to allow the user to enter a sting.s2 (minimum length 2 characters,maximum length is 20 characters, actual length is user's choice) containing a random patterm o upper case letters A-Zand then a replacement character, c. N Va code a user defined function, strfilterisl.2c) thatsearchessl and replaces any occurrences of any ) of the characters contained in s2 with the character c. d output the generated string, the user entered string, and the fitered string from the main program filtered sl - rEJK SIOEFN KIVOIUP WENFK KYUFGIOE PVNO 1 ."J Code-? Allow the user to enter muloiple stings s2 if desired. Us and string for all comparisons. To create the generated pattern use the library function RAND which generates pseudorandom numbers 0-32767. The modulus operator can be used to change the range to 0-25. This should be done in from a function. Generate the random string only once. Remember: STRINGS MUST TERMINATE WITH 10 DO NOT USE POINTER NOTATION OR GLOBALS IN THIS LAB (4B). LAB 5B Obiective To gain experience in the use of pointers. Modify lab 4 by replacing all array notation with pointers notation. No subscripts in functions. USE PURE POINTER NOTATION Problem definition However arrays must sill be defined.

Explanation / Answer


#include <stdio.h>
#include <stdlib.h>
#include<time.h>
// Function to generate random uppercase characters
char generateRandomCharacter(){
return (char) 65 + (rand() % 25);
}

void createRandomArray(char s1[], int size){
// char s1[40];
int i;
for(i = 0; i<size-1; i++)
s1[i] = generateRandomCharacter();
s1[i] = ''; // Null character to terminate the string
return s1;
}

void getUserInput(char[40] s2){
gets(s2);
}

int main()
{
// Use current time as seed for random generator
srand(time(0));
// Generate s1 array
char s1[40];
createRandomArray(s1,40);
// Print s1 array
printf("S1: [");
for(int i = 0; i<40; i++)
printf(" %c ", s1[i]);
printf("]");
  
// Get s2 array from user
int size;
char s2[20];
printf(" Enter size of array (minimum 2 and maximum is 20): ");
scanf("%d",&size);
printf("Enter the string: ");
  
getUserInput(s2);
puts(s2);
  
return 0;
}