Create a step by step process for the following problems Sta

Create a step by step process for the following problems.

State the purpose in your own words, specify input that is needed, expected output, and the step by step process that will obtain the output from the input (the algorithm) for each or the problems below. Also specify test data that can be used to all the scenarios described for each problem.

Problem 1:

Write a process (do not create a program) that will allow the user to enter the total rainfall for each the 12 months of the year. Calculate the average monthly total, yearly total, the lowest monthly total, and the highest monthly total.

Problem 2:

Write a process (do not create a program) that will allow the user to enter the values for 2 arrays that are in parallel. The first array will contain the names of 5 salsas: mild, medium, sweet, hot, and zesty. The second array will contain the number of jars that were sold of each type of salsa. Determine the name of the salsa which had the highest sales and the name of the salsa which had the lowest sales.

Program 3:

Write a process (do not create a program) that would create a function that accepts an array of integer values, a whole number n, and the number of elements in the array. The function should then determine how many values are evenly divisible by whole number n, and return the number of values greater than n to the function call.

Program 4:

Write a process (do not create a program) analyze the data in a two-dimensional array. The array will be a 4 by 7 array containing the daily intake of food for 4 dogs each day for a week. Determine the overall daily average intake, the minimum daily intake for each dog, and the maximum daily intake for each dog.

Solution

1.
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;


int main ()
{
const int MONTHS = 12;
string name[MONTHS]= {\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"};
int count= 0;
double rain[MONTHS];
double avg;
double year=0;
double highest;
string highMonth;
double lowest;
string lowMonth;


for(count = 0; count < MONTHS; count++) // ask user to enter amount of rainfall for each month
{
cout <<\"How many inches of rain does \"<< name[count];
cout<< \" have? \ \";
cin >> rain[count];
while (rain[count] < 0)
{
cout << \"Please enter a number greater than 0.\"<< endl;
cin >> rain[count];
}
}
for(int count=0; count<MONTHS; count++) // totals up all the rainfall
year += rain[count];

avg = year / MONTHS;

for( int count = 0; count < MONTHS; count++) //spits out each month with its amount of rain
{
cout << name[count];
cout<< \" has \";
cout<< rain[count] << \" inches of rainfall.\ \";
}


highest = rain[0]; // finds month with the highest amount of rain

for (count = 1 ;count < MONTHS; count++)
{
if (rain[count] > highest)
{
highMonth = name[count];
highest = rain[count];
}
}


lowest = rain[0]; // finds month with the least amount of rain

for (count = 1 ;count < MONTHS; count++)
{
if (rain[count] < lowest)
{
lowMonth = name[count];
lowest = rain[count];
}
}


cout << endl;

cout << setprecision(2) << fixed;

cout <<\"Total Rainfall throughout the year is \" <<year << \" inches\" << endl;

cout <<\"The average monthly rainfall is \" << avg << \" inches\"<< endl;

cout <<\"The month with the highest amount of rainfall is \" << highMonth << \" with \" << highest<< \" inches.\"<< endl;

cout <<\"The month with the lowest amount of rainfall is \" << lowMonth << \" with \" << lowest<< \" inches.\"<< endl;

return 0;
}


2.
# include <stdio.h>
# define bool int

void quickSort(int *, int, int);

bool hasArrayTwoCandidates(int A[], int arr_size, int sum)
{
int l, r;

/* Sort the elements */
quickSort(A, 0, arr_size-1);

/* Now look for the two candidates in the sorted
array*/
l = 0;
r = arr_size-1;
while (l < r)
{
if(A[l] + A[r] == sum)
return 1;
else if(A[l] + A[r] < sum)
l++;
else // A[i] + A[j] > sum
r--;
}
return 0;
}

/* Driver program to test above function */
int main()
{
int A[] = {1, 4, 45, 6, 10, -8};
int n = 16;
int arr_size = 6;
  
if( hasArrayTwoCandidates(A, arr_size, n))
printf(\"Array has two elements with sum 16\");
else
printf(\"Array doesn\'t have two elements with sum 16 \");

getchar();
return 0;
}

/* FOLLOWING FUNCTIONS ARE ONLY FOR SORTING
PURPOSE */
void exchange(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

int partition(int A[], int si, int ei)
{
int x = A[ei];
int i = (si - 1);
int j;

for (j = si; j <= ei - 1; j++)
{
if(A[j] <= x)
{
i++;
exchange(&A[i], &A[j]);
}
}
exchange (&A[i + 1], &A[ei]);
return (i + 1);
}

/* Implementation of Quick Sort
A[] --> Array to be sorted
si --> Starting index
ei --> Ending index
*/
void quickSort(int A[], int si, int ei)
{
int pi; /* Partitioning index */
if(si < ei)
{
pi = partition(A, si, ei);
quickSort(A, si, pi - 1);
quickSort(A, pi + 1, ei);
}
}

Create a step by step process for the following problems. State the purpose in your own words, specify input that is needed, expected output, and the step by st
Create a step by step process for the following problems. State the purpose in your own words, specify input that is needed, expected output, and the step by st
Create a step by step process for the following problems. State the purpose in your own words, specify input that is needed, expected output, and the step by st
Create a step by step process for the following problems. State the purpose in your own words, specify input that is needed, expected output, and the step by st

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site