guided exploration 02 arrays chapter 06 purpose explore 1d and 2d arra
Search for question
Question
Guided Exploration 02: Arrays Chapter 06
Purpose: Explore 1D and 2D arrays, how to define, initialize and pass.
Effort: Collaborate (Academic Integrity) Do not use Al tools such as ChatGTP except where
indicated in the assignment. First try the assignment on your own and then connect with
your group to discuss. This means you work together but each person is doing each part on
their computer and writing in their own words. Write your own code but you can discuss
approaches and problems after you have written the code. Do not use someone else's
code as yours.
Points: 20 (see rubric in canvas)
Deliverables: Upload this document with your answers and your GE04SurveyLastName.c file.
Do not upload a zip file.
I encourage collaboration on Guided Explorations. If you are not understanding some of the
concepts please look at my office hours so I can support you. Discussing concepts to
understand them better is an important skill.
If you collaborated with others include name(s):
Part 1: Explore Code
Explore book code fig06_11 from your repository. Answer the questions and update the code.
Commit and push your code using GitHub desktop when you finish.
Explain as if you are teaching someone.
verb (used with object)
1 to make plain or clear; render understandable or intelligible:
to explain an obscure point.
2 to make known in detail:
to explain how to do something.
1.1 Focus on the array: int a[SIZE] = {0, 1, 2, 3, 4};
Demonstrate that “the value of an array name” is really the address of the first element
of the array by printing out the addresses of each.
Use fig06_11 code and put your code after the array is declared and initialized.
Paste the code below
Paste the output below Explain how and where memory is allocated to store this array
1.2 What does the index value of an array really represent? Why is size_t used when
working with indexes of arrays?
Use this code to help you explain
for (size_t i = 0; i < SIZE; ++i) {
printf("%3d", a[i]);
}
1.3 Add another function called displayArray to fig06_11 that will print the elements in the
array(instead of printing the values in main) and implement the principle of least privilege.
The function should be reusable to work with different sized arrays.
Paste Code below -
Explain the principle of least privilege. Include what it means when passing an array to
a function and how it is implemented in code using the code you wrote above.
Explain how you made the function reusable for different sized arrays. Include the
parts of the code you wrote above.
Why do you not need to use the const qualifier for the parameter when passing
primitive data types?
1.4 Explain the difference between passing an array to a function and an element of an array
to a function.
Draw a picture (paper, whiteboard, tablet) of stacks to explain how an array element is
passed and what is happening on the stacks for the following
int main(void) {
int a[SIZE] = {0, 1, 2, 3, 4}; // initialize array a
modifyElement(a[3]);
void modify Element(int e) { }
e *= 2; // multiply parameter by 2
printf("Value in modifyElement is %d\n", e);
Include drawing and explanation below
Draw a picture (paper, whiteboard, tablet) of stacks to explain how an array is passed and
what is happening on the stacks for the following
int main(void) {
int a[SIZE] = {0, 1, 2, 3, 4}; // initialize array a
modifyArray(a, SIZE);
void modifyArray(int b[], size_t size) {
// multiply each array element by 2
for (size_t j = 0; j < size; ++j) {
b[j] *= 2; // actually modifies original array
}
}
Include drawing and explanation below
1.5 What secure programming is important to implement when working with arrays?
2 Write Code to Analyze Survey Data
Here you will explore 1d and 2d arrays to analyze data. For more information on analyzing data
Resources:
●
Book section 6.9 and code example fig06_17.c
Book section 6.11 and code example fig06_17.c
Read the following Requirements and then see below to create your code solution. Write your
own code but you can discuss approaches and problems after you have written
the code. Do not use someone else's code as yours. We are not looking at
whether it all works correctly. This is for you to explore and see where you have
issues. Just make sure you provide evidence you tried something for each part.
User stories
• As a rider I would like to see ratings of the rideshare to assist me in determining if I
want to use that rideshare. ●
Think about how you can implement so this information is not hard coded and can easily
change
●
As a rideshare company I want to analyze the rider ratings to see how the company
can improve the experience to get more riders.
the max and min rating
The category names
The number of categories
Acceptance Criteria
1.1 Display rideshare ratings collected so far
Example rating
"Our RideShare Ratings"
Survey Results (if none entered yet)
No Ratings Currently
Survey Results (if any entered so far)
Rating Categories: 1. Safety
Survey 1:
Survey 2:
Survey 3:
Survey 4:
Survey 5:
●
Enter your rating for
1. Safety
1
4
3
5
3
Enter your rating for
2. Cleanliness
2.Cleanliness
Enter your rating for
3. Comfort
45555
1.2 Get property ratings from the rider where the rider enters a valid rating from rating min [1] to
rating max [5] for each category in the survey [1. Safety, 2. Cleanliness, 3. Comfort]
Go back to 1.1 to display rideshare ratings collected so far.
After 5 riders go to 1.3 below to display average for each category
No need to validate rating value for this exploration. Focus on working with arrays.
5
Example
"We want to know how your experience was on your ride today. Using the rating system 1 to 5
enter your rating for each category:
1. Safety
2. Cleanliness
3. Comfort
1
324 2
3. Comfort 1.3 Display Average for each rating category
Example Output
[RideShare Organization Name] Summary Report
Rider Number of Miles
52.0
3
Category Rating Averages
1. Safety
3.2
Exiting
Number of Minutes Ride Fare Amount
70
$91.05
Paste Code Below
2.Cleanliness
4.8
Create a c file called GE04RenterSurveyLastName
Write your own code but you can discuss design ideas and issues with others.
}
3. Comfort
2.4
Create a 2D array in main called rideshareSurvey to hold 7 rows for each renter and 3
categories for each renter rating and use symbolic constants for the number of riders
the array can hold and the number of categories the array can hold
Create a 1D array in main called categoryAverages to hold the category averages
Add the following array to main. This will allow you to iterate through an array of strings to
display the survey categories.
const char *surveyCategories[SURVEY_CATEGORIES] = {"Safety", "Cleanliness",
"Comfort"};
You can iterate through the array to display the strings calling this function from main.
void printCategories(const char *categories[], size_t totalCategories)
{
//loop to display each category horizontally
printf("%s", "Rating Categories:\t");
for (size_t surveyCategory = 0; surveyCategory < totalCategories; ++surveyCategory)
{
printf("\t%zu.%s\t", surveyCategory+1, categories[surveyCategory]);
}
puts(""); // start new line of output
Create function getRatings to get rating from each renter for each category. Assume that all
entries are valid as this is to practice working with arrays.
store the information in the 2d array rentalSurvey in main
Return is void
● Think about how you would iterate to add a new riders rating