Docsity

Computer Science Quiz 7, Quizzes of Computer Science

Toggle sidebar
bg1
CptS 121 – Program Design and Development
Date Assigned: Fri, Oct 17, 2025 Due Date: Mon, Oct 20, 2025
Take-Home Quiz 7 (15 pts) – Arrays and Strings
Using Canvas https://canvas.wsu.edu/, please submit your solution to the correct quiz
folder. Your solution should be a .pdf file with the name <your last name>_quiz7.pdf
and uploaded. To upload your solution, please navigate to your correct Canvas
lab
course space. Select the “Assignments” link in the main left menu bar. Navigate to the
correct quiz submission folder. Click the “Start Assignment” button. Click the “Upload
File” button. Choose the appropriate .pdf file with your solution. Finally, click the
“Submit Assignment” button.
NOTE: The use of gen AI is forbidden for quizzes.
1. (10 pts) Write a function called is_anagram(), that accepts two
arrays of characters (not considered a C strings) and the sizes of
each array as parameters (a total of four parameters),
determines if the two arrays are
anagrams
, and returns 1 if the
two are anagrams; 0 otherwise. Recall: an anagram is a word or
phrase that is created by rearranging the symbols in another
word or phrase. For example, “silent” and “listen” are anagrams
and “mug” and “gum” are anagrams.
Precondition
: the two character arrays must consist of lowercase
alphabetic characters only.
Hint: consider using
counting arrays
or
frequency tables
to solve
this problem.
#include <stdio.h>
int is_anagram(char arr1[], int size1, char arr2[], int size2){
if (size1 != size2)
return 0;
}
int count1[26] = {0};
int count2[26] = {0};
for (int i = 0; i < size1; i++)
count1[arr1[i] - 'a']++;
for (int i = 0; i < size2; i++)
Instructor: Andrew S. O’Fallon
pf2

Partial preview of the text

Download Computer Science Quiz 7 and more Quizzes Computer Science in PDF only on Docsity!

CptS 121 – Program Design and Development Date Assigned: Fri, Oct 17, 2025 Due Date: Mon, Oct 20, 2025 Take-Home Quiz 7 (15 pts) – Arrays and Strings Using Canvas https://canvas.wsu.edu/, please submit your solution to the correct quiz folder. Your solution should be a .pdf file with the name _quiz7.pdf and uploaded. To upload your solution, please navigate to your correct Canvas lab course space. Select the “Assignments” link in the main left menu bar. Navigate to the correct quiz submission folder. Click the “Start Assignment” button. Click the “Upload File” button. Choose the appropriate .pdf file with your solution. Finally, click the “Submit Assignment” button. NOTE: The use of gen AI is forbidden for quizzes.

  1. (10 pts) Write a function called is_anagram(), that accepts two arrays of characters (not considered a C strings) and the sizes of each array as parameters (a total of four parameters),

determines if the two arrays are anagrams, and returns 1 if the

two are anagrams; 0 otherwise. Recall: an anagram is a word or phrase that is created by rearranging the symbols in another word or phrase. For example, “silent” and “listen” are anagrams and “mug” and “gum” are anagrams.

Precondition: the two character arrays must consist of lowercase

alphabetic characters only.

Hint: consider using counting arrays or frequency tables to solve

this problem. #include <stdio.h> int is_anagram(char arr1[], int size1, char arr2[], int size2){ if (size1 != size2) return 0; } int count1[26] = {0}; int count2[26] = {0}; for (int i = 0; i < size1; i++) count1[arr1[i] - 'a']++; for (int i = 0; i < size2; i++) Instructor: Andrew S. O’Fallon

CptS 121 – Program Design and Development Date Assigned: Fri, Oct 17, 2025 Due Date: Mon, Oct 20, 2025 count2[arr2[i] - 'a']++; for (int i = 0; i < 26; i++) { if (count1[i] != count2[i]) return 0; } return 1; }

2. (5 pts) In your own words, define and describe a C string.

A C string is a sequence of characters stored in memory and terminated by a null character ('\0'). This null character marks the end of the string so that C functions (like printf, strlen, etc.) know where the string stops. Even though C strings are stored in character arrays, not all character arrays are strings—because some might not end with '\0'. Instructor: Andrew S. O’Fallon