CSE 1320: Intermediate Programming Assignment 4 solution

$29.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

1. Create a function swap_values which takes two pointers-to-double as formal parameters and returns void. The function should swap the values pointed to by each
pointer inside the function.
In main, prompt the user to enter two inputs. Swap the values using the required
function and print the output of each value to 4 decimal places as show in the
example run.
• You may only use stdio.h.
• Save your code as prob1.c.
Example Run
> 3.212456 8.521423
8.5214 3.2124
2. Create a function mult_arr which accepts two pointers-to-double as input along
with an integer reflecting the length of each array. The function should return void.
Using pointer arithmetic to access the array elements, compute the element-wise
product of the two arrays in-place (the result is stored in the first array). The
function should return void.
In main, read in two arrays of 10 values from the user following the I/O format seen
in the example run below. On a new line, print the output following the format
shown below.
Save your code as prob2.c.
Example Run
> 1 1 1 1 1 1 1 1 1 1
> 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2
3. Implement a substring search function which searches a string for a given keyword.
The function should return a pointer to the address of the first character of the
substring within the original string, if it exists. If the substring is not found within
the string, return NULL.
If the input is found, print “Key found.” otherwise print “Key not found.”
Your program’s input and output should match what is seen in the example run.
CSE 1320: Assignment 4 Dillhoff
• You may only use stdio.h.
• Save your code as prob3.c.
Example Run
Enter string: this is a test string.
Enter key: is
Key found.
4. Write a program that accepts an input string from the user and converts it into an
array of words using an array of pointers. Each pointer in the array should point to
the location of the first letter of each word.
Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the
sentence, convert the spaces to NULL characters.
You can assume the input string has 1 space between each word and starts with an
alphanumeric character.
Your program’s input and output format should match the example run
below.
• You may only use stdio.h
• Save your code as prob4.c.
Example Run
> This is a string.
4 word(s) found.
5. Write a program that reads in a continuous stream of strings representing a line of
CSV data in the format “NAME,AGE,EMAIL,DOB”.
Implement a function check_csv which verifies that each input string matches this
format by ensuring that:
• There are 4 tokens in the string corresponding to the 4 properties above.
• The second token MUST be a number.
• The fourth token should be in the format MM-DD-YYYY (hint: tokenize this as
well).
The function should return 0 if the CSV string is valid, and 1 otherwise.
Your program should read CSV strings until the string “END” is entered as input.
Print all valid strings to stdout followed by a line indicating how many invalid
strings were entered.
• You can use a character array with a buffer size of 1024 for reading each line
using fgets.
• You may not use any library specifically for parsing CSV.
2
CSE 1320: Assignment 4 Dillhoff
• Test your code using the file csv_test_data.txt, available through Canvas.
You should be able to input it to your program using redirection.
• Save your code as prob5.c.
Create a zip file using the name template LASTNAME_ID_A4.zip which includes the all
required code files. Submit the zip file through Canvas.
3