Question

In: Computer Science

17.9 Worksheet 7 Follow the instructions commented into the given template. There will be no partial...

17.9 Worksheet 7

Follow the instructions commented into the given template. There will be no partial credit given.

#include <iostream>
using namespace std
int main()
{
int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17};
int numElements = 11;

cout << "Part 1" << endl;
// Part 1
// Enter the statement to print the numbers in index 4 and index 9
// put a space in between the two numbers

cout << endl;
// Enter the statement to print the numbers 3 and 80 from the array above
// put a space in between the two numbers

cout << endl;
// Enter the statement to change the number 1 in the array to be 12
// then write the statement to print out that number in the array

cout << "\nPart 2" << endl;
// Part 2
// Write a function called printAll. It takes in an array
// and an integer that has the number of values in the array.
// The function should print all the numbers in the array with
// a space between each one.
// Call the function on the line below.

cout << "\nPart 3" << endl;
// Part 3
// Write a function called printEven. It takes in an array and
// an integer that has the number of values in the array. It prints
// all the even numbers in the array with a space between each one.
// This function returns the count of evens.
  
int evens;
  
// Call the function you just wrote and store the
// answer in the variable evens declared above.
  
// This will print the number of evens in the array.
cout << endl << evens;
  
cout << "\nPart 4" << endl;
  
// Part 4
// Write a function called computeTotalOdds. It takes in an array and
// an integer that has the number of values in the array. It will return
// the total of all of the odd numbers in the array
  
int total;
  
// Call the function you just wrote and store the answer
// in the variable total declared above

// This will print the total out
cout << endl << total;
  
return 0;
}

Solutions

Expert Solution

//rate my solution and comment if any doubts

Note:

//please do observe the comments that i mentioned you can change your code to your convenience. I wrote 'or' in my solution

Code:

#include <iostream>
using namespace std;
int printAll(int array1[],int numElements)
{
   for(int i=0;i<numElements;i++)
       cout<<array1[i]<<" ";
}
int printEven(int array1[],int numElements)
{
   int c=0; //store count
   for(int i=0;i<numElements;i++)
   {
       if(array1[i]%2==0) //to check if even

{
           c++;
           cout<<array1[i]<<" ";
       }
   }
   return c;
}
int computeTotalOdds(int array1[],int numElements)
{
   int c=0; //to store count
   for(int i=0;i<numElements;i++)
   {
       if(array1[i]%2!=0) // to check if odd
       {
           c++;
           //cout<<array1[i]<<" ";//to print odd numbers if you want to
       }
   }
   return c;
}
int main()
{
int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17};
int numElements = 11;

cout << "Part 1" << endl;
// Part 1
// Enter the statement to print the numbers in index 4 and index 9
// put a space in between the two numbers
cout << array1[4] <<" "<<array1[9];

cout << endl;
// Enter the statement to print the numbers 3 and 80 from the array above
// put a space in between the two numbers
for(int i=0;i<11;i++)
{
   if(array1[i]==3 or array1[i]==80)
       cout<<array1[i]<<" ";
}
/*or you can also use
cout<<array1[0]<<" "<<array1[8];
*/
cout << endl;
// Enter the statement to change the number 1 in the array to be 12
// then write the statement to print out that number in the array
int i;
for(i=0;i<11;i++)
   if(array1[i]==1)
   {
       array1[i]=12;
       break;
   }
cout<<array1[i];
/*or you can also use
array1[2]=12;
cout<<array1[2];
*/
cout << "\nPart 2" << endl;
// Part 2
// Write a function called printAll. It takes in an array
// and an integer that has the number of values in the array.
// The function should print all the numbers in the array with
// a space between each one.
// Call the function on the line below.
printAll(array1,numElements);

cout << "\nPart 3" << endl;
// Part 3
// Write a function called printEven. It takes in an array and
// an integer that has the number of values in the array. It prints
// all the even numbers in the array with a space between each one.
// This function returns the count of evens.
  
int evens;
evens=printEven(array1,numElements);
// Call the function you just wrote and store the
// answer in the variable evens declared above.
  
// This will print the number of evens in the array.
cout << endl << evens;
  
cout << "\nPart 4" << endl;
  
// Part 4
// Write a function called computeTotalOdds. It takes in an array and
// an integer that has the number of values in the array. It will return
// the total of all of the odd numbers in the array
  
int total;
total=computeTotalOdds(array1,numElements);
// Call the function you just wrote and store the answer
// in the variable total declared above

// This will print the total out
cout << endl << total;
  
return 0;
}

Output:

Code(Screen shots):


Related Solutions

PART II — WORKSHEET COMPLETION Instructions: Complete the partial worksheet presented below, inserting additional labels as...
PART II — WORKSHEET COMPLETION Instructions: Complete the partial worksheet presented below, inserting additional labels as needed AUBREY SERVICES AGENCY Partial Worksheet For the Month Ended April 30, 2012 Account Titles Adjusted Trial Balance Income Statement Balance Sheet Dr. Cr. Dr. Cr. Dr. Cr. Cash      6,500.00 Accounts Receivable      2,000.00 Supplies      3,075.00 Prepaid Insurance      2,000.00 Prepaid Rent         500.00 Equipment    35,000.00 Accum. Depreciation      4,000.00 Notes Payable    14,000.00 Account Payable    12,000.00 Unearned Service Revenue      2,000.00 Salaries and Wages Payable      1,300.00 Interest Payable           50.00...
(C++) Follow the template given to calculate and print the monthly salary of an employee. We...
(C++) Follow the template given to calculate and print the monthly salary of an employee. We assume the employee works for 50 weeks during the year with an hourly rate of $25. Your program should ask the user the workHoursPerWeek. If it's over 40, then the excess hours (i.e., workHoursPerWeek over 40) are paid with 20% overtime rate. Note: just print out the monthly salary. Example: If I work for 45 hours with a rate of $30/hr, then my weekly...
Chapter 7 Develop a response in either Word or Excel and follow the instructions outlined in...
Chapter 7 Develop a response in either Word or Excel and follow the instructions outlined in the Assignments Menu for submission. On December 31, 2010, Palli Company finished consultation services and accepted in exchange a promissory note with a face value of $240,000, a due date of December 31, 2013, and a stated rate of 5%, with interest receivable at the end of each year. The fair value of the services is not readily determinable and the note is not...
Instructions: Show all calculations in detail. No partial credit will be given for just answers. 3....
Instructions: Show all calculations in detail. No partial credit will be given for just answers. 3. An importer of Swiss watches has an account payable of CHF750,000 due in 90 days. The following data is available: Rates and prices in US-cents/CHF.               Spot rate: 71.42 cents/CHF 90-day forward rate: 71.14 cents/CHF US –dollar 90-day interest rate: 3.75% per year Swiss franc 90-day interest rate: 5.33% per year Option Data in cents/CHF _______________________________                         Strike                     Call                  Put 70                          2.55                1.42 72                          1.55               ...
7) What SUP Partial Year Double Declining Balance Depreciation for Asset 1004 Create a new worksheet...
7) What SUP Partial Year Double Declining Balance Depreciation for Asset 1004 Create a new worksheet to calculate depreciation for a table purchased on August 1, 2017, for $95,000. It has an estimated salvage value of $2,000 and is to be depreciated over 10 years using the double declining balance method. Follow the same process used in the chapter to calculate depreciation for partial periods.
As code is given below, follow the instructions: 1. Count the number of comparisons and find...
As code is given below, follow the instructions: 1. Count the number of comparisons and find where to put that counter in the code 2. Pick a random pivot, right pivot, left pivot, middle pivot for each smaller array /sub-array import java.util.*; import java.util.List; public class QuickSort { public static void main(String[] args) { int[] values = { 6, 5, 4, 3, 1, 7, 8 }; System.out.println("Original order: "); for (int element : values) System.out.print(element + " "); IntQuickSorter.quickSort(values); System.out.println("\nFirst...
                           Apps and Privacy - An Ethics Case Study Now follow the instructions given below to...
                           Apps and Privacy - An Ethics Case Study Now follow the instructions given below to complete the assessment task: Use the title of the article/case study as the title of your argument visualisation so that the lecturer knows which article you are analysing. Undertake further research about your chosen case and the ethical issue involved, to assist you in analysing it in your argument visualisation Identify some logical arguments based on the four classical ethical theories including utilitarianism, deontology,...
Instructions: In this section, please show all calculations. Partial credit will be given wherever possible, when...
Instructions: In this section, please show all calculations. Partial credit will be given wherever possible, when your calculations are shown and they are completed correctly. 33. – 35. Corporate Income Taxes Corporate Tax Schedule If Corporation's Taxable It Pays This Amount on the Plus this Percentage on the Income is: Base of the Bracket: Excess Over the Base: Up to $50,000 0 15% $50,000 -- $75,000 $7,500 25% $75,000 -- $100,000 $13,750 34% $100,000 -- $335,000 $22,250 39% $335,000 --...
Question 1 Follow the instructions on page 7, using your Pie Plate Demonstrator to answer the...
Question 1 Follow the instructions on page 7, using your Pie Plate Demonstrator to answer the following questions. In this experiment, we assume the foam plate has a positive charge when rubbed with paper towels. Lift the pan away from the charged plate using the styrofoam cup. Briefly touch the rim of the pan to neutralize it. Place the neutralized pan on the plate and observe the tape rise. When the pan is on the plate, the rim of the...
Please use Minitab and follow instructions given with the problem A contractor has recorded the number...
Please use Minitab and follow instructions given with the problem A contractor has recorded the number of jobs performed in the last seven months. Last year’s performance evaluation score For each of the following methods, develop a forecast for the number of jobs for the 8th month. A three-period moving average Exponential smoothing (use Minitab default smoothing parameters) A linear trend equation Using the mean squared difference (MSD), explain which of the methods you believe results in the best forecast...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT