/* ELEN 1301 Programming Assignment #5. Name : Your name. Student ID : Your student ID #. Due date : Due date Purpose of the program : Finding the average, minimum and maximum values of seven entered numbers. Use iomanip library to show 3 digits below decimal point. Section 1 : Enter the first number. Set min and max variables to the entered number. Section 2 : Enter the next number. If it is smaller than min, replace the min with the entered number. If it is bigger than max, replace the max with the entered number. Section 3 : Repeat section 2 five more times, so that you have seven numbers. Section 4 : Calculate the average of the seven numbers and show the result with 3 digits below decimal point. (2 points) Section 5 : Show the minimum number. (2 points) Section 6 : Show the maximum number. (2 points) */ #include #include using namespace std; int main() { int n1, n2, n3, n4, n5, n6, n7, min, max; double sum = 0; // Write the rest of the program. return 0; } // main

Answers

Answer 1
Answer:

Answer:

Here is the C++ program:

#include<iostream> //to use input output functions

#include<iomanip> //to use setprecision

using namespace std; //to identify objects cin cout

int main() { //start of main function

     int n1, n2, n3, n4, n5, n6, n7, min, max;  // declare variables for 7 numbers, minimum value and maximum value

     double sum= 0; //declare variable to hold sum of 7 numbers

     double average;  //declare variable to hold average of 7 numbers

     cout<<"Enter first number: "; //prompts user to enter 1st number

     cin>>n1; //reads first number from user

     max = n1; //sets the first number to maximum

     min=n1; //sets the first number to minimum

     cout<<"Enter second number: "; //prompts user to enter 2nd number

     cin>>n2; //reads second number from user

     if(n2<min){ //if second number is less than min

          min=n2;      } //sets min to n2

     if(n2>max){ //if n2 is greater than max

          max = n2;      } //sets max to n2

     cout<<"Enter third number: ";  //prompts user to enter 3rd number

     cin>>n3; //reads third number from user

     if(n3<min){ //checks if n3 is greater than min

          min=n3;      } //sets n3 to min

     if(n3>max){ //checks if n3 is greater than max

          max = n3;      }      //sets max to n3

    cout<<"Enter fourth number: ";//prompts user to enter 4th number

     cin>>n4; //reads fourth number from user

     if(n4<min){  //if n4 is less than min

          min=n4;      }  //sets min to n4

     if(n4>max){  //if n4 is greater than max

          max = n4;      }  //sets max to n4

     cout<<"Enter fifth number: "; //prompts user to enter 5th number

     cin>>n5; //reads fifth number from user

     if(n5<min){  //if n5 is less than min

          min=n5;     }  //sets min to n5

     if(n5>max){  //if n5 is greater than max

          max = n5;      }  //sets max to n5

     cout<<"Enter sixth number: "; //prompts user to enter 6th number

     cin>>n6; //reads sixth number from user

     if(n6<min){ // if n6 is less than min

          min=n6;      }  //sets min to n6

     if(n6>max){  //if n6 is greater than max

          max = n6;      }  //sets max to n6

     cout<<"Enter seventh number: ";//prompts user to enter 7th number

     cin>>n7; //reads seventh number from user

     if(n7<min){  //if n7 is less than minimum number

          min=n7;      }  //assigns n7 to min

     if(n7>max){  //if n7 is greater than the maximum number

          max = n7;      }  //assigns n7 to max

     sum = n1+n2+n3+n4+n5+n6+n7;  //adds 7 numbers

     average = sum/7;  //computes average of 7 numbers

     cout<<"The average is: "<<fixed<<setprecision(3)<<average<<endl; //displays average value up to show 3 digits below decimal point using setprecision method of iomanip library

     cout<<"The maximum number is: "<<max<<endl; //displays maximum number of 7 numbers

     cout<<"The minimum number is: "<<min<<endl;  //displays miimum number of 7 numbers    

     return 0; }

Explanation:

The program is well explained in the comments attached to each statement of program. For example if

n1 = 3

n2 = 9

n3 = 7

n4 = 6

n5 = 2

n6 = 5

n7 = 4

When n1 is read using cin then this number is set to max and min as:

min = 9

max = 3

Now when n2 is read, the first if condition checks if n2 is less than min and second if condition checks if n2 is greater than max. As n2 = 9 so it is not less than min so this if condition is false and n2 is greater than max i.e. 3 so this condition is true. So 9 is assigned to max.

min = 9

max = 9

Now when n3 is read the values of min and max become:

min = 7

max = 9

Now when n4 is read the values of min and max become:

min = 6

max = 9

Now when n5 is read the values of min and max become:

min = 2

max = 9

Now when n6 is read the values of min and max become:

min = 2

max = 9

Now when n7 is read the values of min and max become:

min = 2

max = 9

Now the statement       sum = n1+n2+n3+n4+n5+n6+n7;

executes which becomes:

sum = 3 + 9 + 7 + 6 + 2 + 5 + 4

sum = 36.0

Next program control moves to statement:

average = sum/7;

this becomes

average = 36/7

5.142857

Since this is to be displayed up to 3 decimal places so average = 5.143

the complete output of the program is attached.


Related Questions

What is Interface in computers
In open addressing with linear probing we must consider how to encodeA. Occupies positionsB. Available positionsC. All other answersD.empty positions
Write a function copy that takes two arrays A and B, both of size N. The function then copies all N values from A into B and then displays it.
Quicksort reaches the worst-case time complexity when:Partition is not implemented in placePicking the largest one of input or partitioned data as pivot valueMedian of input or partitioned data is expensive to calculateData is sorted already and always pick the median as pivotChoose the incorrect statement:When the median is always picked as pivot in input/partitioned data, then quicksort achieves the best-case time complexity.Mergesort has O(N(log(N)) time complexity for its worst case, average case and best caseInsertionsort reaches its best-case time complexity O(N log(N)) when the input data is pre-sortedQuicksort is practically fast and frequently used sorting algorithm.Choose the incorrect statement:In the lower bound analysis by using decision tree, each branch uses one comparison to narrow down possible casesIn the lower bound analysis by using decision tree, he number of required comparisons can be represented by height of decision treeA decision tree to sort N elements must have N^2 leavesO(N log(N)) lower bound means that comparison-based algorithm cannot achieve a time complexity better than O(N log(N))Choose the incorrect statement regarding time complexity of union-find operation:Inverse Ackermann function does not depend on N and is a constant factor.When we use arbitrary union and simple find for union-find operation, the worst-case time complexity is O(MN) for a sequence of M operations and N elementsUnion-by-size and Union-by-rank both improve the time complexity to O(M log(N)) for a sequence of M operations and N elementsTo finish the entire equivalence class computation algorithm, we need to go over each pair of elements, so if we use union-by-rank with path compression for find operation, then the overall time complexity is O(N^2 log*N), where log*N denotes the inverse Ackermann function.Choose the incorrect statement regarding Dijstraâs algorithmDijstraâs algorithm is a greedy algorithmDijstraâs algorithm requires to dynamically update distance/costs/weights of paths.To begin with, Dijstraâs algorithm initializes all distance as INFDijstraâs algorithm can be implemented by heaps, leading to O(|E|+|V| log(|V|)) time complexity, where, particularly, log(|V|) is due to "insert" operation in heaps.
Definition of letter in communication skills

Egovernment involves the use of strategies and technologies to transform government by improving the delivery of services and enhancing the quality of interaction between the citizen-consumer within all branches of government. Group of answer choices

Answers

What are you asking for

Write a program that reads in 10 numbers from the user and stores them in a 1D array of size 10. Then, write BubbleSort to sort that array – continuously pushing the largest elements to the right side

Answers

Answer:

The solution is provided in the explanation section.

Detailed explanation is provided using comments within the code

Explanation:

import java.util.*;

public class Main {

//The Bubble sort method

public static void bb_Sort(int[] arr) {  

   int n = 10; //Length of array  

   int temp = 0; // create a temporal variable  

   for(int i=0; i < n; i++){  

         for(int j=1; j < (n-i); j++){  

           if(arr[j-1] > arr[j]){  

               // The bubble sort algorithm swaps elements  

               temp = arr[j-1];  

               arr[j-1] = arr[j];  

               arr[j] = temp;  

             }  

         }            

         }  

        }

 public static void main(String[] args) {

   //declaring the array of integers

   int [] array = new int[10];

   //Prompt user to add elements into the array

   Scanner in = new Scanner(System.in);

   //Use for loop to receive all 10 elements

   for(int i = 0; i<array.length; i++){

     System.out.println("Enter the next array Element");

     array[i] = in.nextInt();

   }

   //Print the array elements before bubble sort

   System.out.println("The Array before bubble sort");

   System.out.println(Arrays.toString(array));

   //Call bubble sort method

   bb_Sort(array);  

               

   System.out.println("Array After Bubble Sort");  

   System.out.println(Arrays.toString(array));

 }

}

Create an application named ArithmeticMethods whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayNumberPlus10(), displayNumberPlus100(), and displayNumberPlus1000(). Create each method to perform the task its name implies. Save the application as ArithmeticMethods.java.

Answers

Answer:

public class ArithmeticMethods

{

public static void main(String[] args) {

    int number1 = 7;

    int number2 = 28;

 displayNumberPlus10(number1);

 displayNumberPlus10(number2);

 displayNumberPlus100(number1);

 displayNumberPlus100(number2);

 displayNumberPlus1000(number1);

 displayNumberPlus1000(number2);

}

public static void displayNumberPlus10(int number){

    System.out.println(number + 10);

}

public static void displayNumberPlus100(int number){

    System.out.println(number + 100);

}

public static void displayNumberPlus1000(int number){

    System.out.println(number + 1000);

}

}

Explanation:

Inside the main:

Initialize two integers, number1 and number2

Call the methods with each integer

Create a method called displayNumberPlus10() that displays the sum of the given number and 10

Create a method called displayNumberPlus100() that displays the sum of the given number and 100

Create a method called displayNumberPlus1000() that displays the sum of the given number and 1000

Use the STL class vector to write a C function that returns true if there are two elements of the vector for which their product is odd, and returns false otherwise. Provide a formula on the number of scalar multiplications in terms of n, the size of the vector, to solve the problem in the best and worst cases. Describe the situations of getting the best and worst cases, give the samples of the input at each case and check if your formula works. What is the classification of the algorithm in the best and worst cases in terms of the Big-O notation

Answers

Answer:

Code is provided in the attachment form

Explanation:

Vector Multiplication code:

Vector_multiplication.c file contains C code.

See attachment no 1 attached below

Classification of Algorithm: For creating elements in vector c of size n, number of scalar  multiplications is equal to n. The size of original two vectors scales directly with the number of  operations. Hence, it is classified as O(n).

Jenae helps maintain her school web site and needs to create a web site poll for students. Which tool will she use?

Answers

She needs to use a web browser

Answer:

web browser

Explanation:

the other three will not let her excess her page at all

How does abstraction help us write programs

Answers

Answer:

Abstraction refines concepts to their core values, stripping away ideas to the fundamentals of the abstract idea. It leaves the common details of an idea. Abstractions make it easier to understand code because it concentrates on core features/actions and not on the small details.

This is only to be used for studying purposes.

Hope it helps!