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

Pre-lab Questions: Answer the following questions before your Lab Session. 1. De

ID: 3567167 • Letter: P

Question

Pre-lab Questions: Answer the following questions before your Lab Session. 1. Define an array, nums, to have 20 int elements. Use a const variable, SIZE, to hold the value 20. 2. Write a loop that will ask the user to enter the elements in the nums array from question 1, and read in the input from the keyboard (cm) to the array. 3. Write a loop that will find the maximum number in the nums array from the previous question. 4. In C++, arrays must have a constant size that is known before the program is run. What is a strategy to use arrays if you do not know for sure how many elements the array will have before the program is executed?

Explanation / Answer

#include<iostream>
#include<stdio.h>
#include<limits.h>

using namespace std;

#define SIZE 31

int main(){
char month[15];
int no_of_days_snow;
int arr[SIZE];
cout << "Enter the month: ";
cin >> month;
cout << "Enter how many days it snowed in " << month << ": ";
cin >> no_of_days_snow;

for(int i=0; i<no_of_days_snow; i++){
cout << "Enter the amount of snowfall(in inches) on day " << i+1 << " with snow: ";
cin >> arr[i];
while(arr[i] < 0){
cout << "Snow amount must be positive on a day it snowed. Please reenter: ";
cin >> arr[i];
}
}

int max = INT_MIN;
int min = INT_MAX;
int footCount = 0;
int sum = 0;


for(int i=0; i<no_of_days_snow; i++){
if(arr[i] > max){
max = arr[i];
}
if(arr[i] < min){
min = arr[i];
}
if(arr[i] > 12){
footCount++;
}
sum += arr[i];
}
cout << " Snow report for " << month << endl << endl;
cout << "The maximum snowfall on any day in " << month << " was " << max << "" << endl;
cout << "The minimum snowfall on any day in " << month << " was " << min << ""<< endl;
cout << "There were " << footCount << " days with at least a foot of snow ";
cout << "There were " << sum << ""<< " of snow in " << month << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote