首页 > > 详细

C辅导 CSCE 155E:Homework 5辅导留学生asp

Introduction
C,,,,,。
,,mallocfree,。
Requirement
CSCE 155E Fall 2016
Homework 5
Due Date: 11/13/2015, 2.30 PM
Instructions Follow instructions carefully, failure to do so may result in points being de-
ducted. Make sure your programs compile and run by using the web grader interface. You
do not need to printout your source code for the programs. Print a copy of the rubric for
this assignment and hand in a hard copy by the due date.
Partner policy: You are not allowed to work with a partner for this assignment.
Program 1. String Utilities In this exercise you will implement several utility functions
involving strings. You will place all of your function prototypes in a header file named
string_utils.h and all of your function definitions in a source file, string_utils.c. As before,
you should implement your own main test driver program to test your functions, but you
need not hand it in.
(a) void addChar(char str, char c, int n)
- this function should add a char c at index n in string str. The following characters
should be shifted up to make room for the inserted character. For example, a call to
this function on the string “Hello World”, ‘p’, ‘4’, would result in the string “Hellpo
World”
(b) int numChar(const char src, char c)
- this example determines the number of character c appears in the string. It does
not matter if the letter in the string is capitalized or not. For example, a call to this
function on the string “HellO World”, ‘o’, would return 2
(c) int isPalindrome(const char src)
- this example determines if the string src is a palindrome or not. Return 1 if the string
is a palindrome and 0 if not. For example, a call to this function on the string “testset”,
will return 1
(d) int strCompare(const char str, const char str2)
- Write your own string comparison function that compares two strings for equality.
You cannot use the string comparison functions. Make sure the compare
function is case insensitive. Return 0 if the two strings are equal and 1 if they are not.
For example, a call to this function on the string “Hello world”, and “Hello World” will
return 0
1
(e) char strCat(char str, char str2)
- Concatenate the two strings “str” and “str2” and store that in a newly created dynamic
string. The function should return this dynamic string. You cannot use the
concatenation functions. For example, a call to this function on the string “Hello”, and
“ World” will return a dynamically created string that contains “Hello World”
(f) void consonantVowel(char str)
- This function will print out the number of consonantes and vowels in the string. Note:
printing should be done in the function (notice the return type is void). For example, a
call to this function on the string “Hello”, will print Consonants: 3, Vowels 2
Program 2. Array In this exercise you will write several functions that operate on arrays.
You will place all the function prototypes in a header file named array_utils.h with their
definitions in a source file named array_utils.c. You should test your functions by writing a
driver program, but you need not hand it in.
(a) The dot product of two arrays are a = [a 1 ,a 2 ,a 3 ,..,a n ] and b = [b 1 ,b 2 ,b 3 ,..,b n ] is
a · b =
n
X
i=1
a i b i = a 1 b 1 + a 2 b 2 + ··· + a n b n
Write a function that computes the dot product of the two arrays
int dotProduct(const int a, int size, const int b, int size2);
(b) Write a function that takes an integer array and returns the number of integers that
are prime in the array
int numPrime(const int a, int size);
(c) Write the following function:
int arrayDifference(const int a, const int b, int sizeOfA, int sizeOfB);
which dynamically creates an array and fills it with all integers that can be found in
a , but not b . The values in the returned array should be unique; that is, there should
not be any duplicates. Furthermore, the size of the allocated arrays should not waste
memory.
(d) Write the following function:
int arrayIntersect(const int a, const int b, int sizeOfA, int sizeOfB);
which dynamically creates an array and fills it with all integers that can be found in a
and b . The values in the returned array should be unique; that is, there should not be
any duplicates. Furthermore, the size of the allocated arrays should not waste memory.
Program 3. Matrices In this exercise you will write several functions that operate on
matrices or two-dimensional arrays. For this exercise, we will restrict our attention to square
matrices-collections of numbers with the same number of columns and rows. You will place
2
all the function prototypes in a header file named matrix.h with their definitions in a source
file named matrix.c. You should test your functions by writing a driver program, but you
need not hand it in.
(a) Write a function that takes two matrices and determines if the sum of all of the
elements in matrix A is equal to the sum of all the elements in matrix B. Return 0 if
the summation is equal and 1 if they are not equal.
int sumEqual(int A, int B, int n);
(b) Write a function that takes two matrices and determines if they are equal (all of their
elements are the same). If the matrices are equal, return 0. Return 1 if they are not
equal.
int isEqual(int A, int B, int n);
(c) Write a function to compute the sum of the elements along the diagonal of the matrix.
Return the sum of the elements along the diagonal.
int diagonal(int A, int n);
(d) Write a function to compute the summation of matrix A and B.
int sumMatrix(int A, int B, int n);
(e) The product of two square n × n matrices:
C = A × B
The entries for C are:
c ij =
n
X
k=1
a ik b kj
where 1 ≤ i,j ≤ n and c ij is the ( i , j )-th entry of the matrix C . Write the following
function to compute the product of two n × n square matrices:
int product(int A, int *B, int n);
Bonus
Name the files, bonus.c and bonus.h
char highestFreq(char str)
- this function should return the highest frequency character c in the string. For example, a
call to this function with the string “Hello World”, would return “l”,

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!