1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
cricket20 [7]
3 years ago
5

/* ELEN 1301 Programming Assignment #5. Name : Your name. Student ID : Your student ID #. Due date : Due date Purpose of the pro

gram : 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

Computers and Technology
1 answer:
cestrela7 [59]3 years ago
3 0

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.

You might be interested in
Within an event-driven program a component from which an event is generated is the ____
mojhsa [17]
The answer is: <span>Source of the Event</span>
7 0
3 years ago
before donating a computer you should use a program to wipe the hardest to remove all of his data true or false
Katarina [22]
True or they could get into your stuff. 
6 0
3 years ago
A company develops a gaming application that it intends to sell. One of the scenarios that the sales team is concerned about is
Deffense [45]

Answer:

A. Registration technique

7 0
3 years ago
Given a vector of students, the function FinalAvg is supposed to return the average final exam score across all the students in
alexandr1967 [171]

Answer:

The C++ code is given below with appropriate comments

Explanation:

#define CATCH_CONFIG_MAIN //This tells Catch to provide a main()

#include"catch.hpp" //Header for Catch Framework

double FinalAvg( vector <int> students) // Function to calculate average.

{

double sum =0;

int i;

for( i=0;i<v.size();i++) sum+= v[i];

return v.empty() ? 0.0 : (double(sum)/ v.size());

}

vector<int> func(int argvq[ ]) // This function is made because we can not provide vector in command line argument that's why we used array which is then conerted into vector.

{

vector<int> v;

int j;

int l= sizeof(argvq)/sizeof(argvq[0]);

for(j=0;j<l;j++)

v.push_back(argq[j]);

return v;

}

TEST_CASE(" Final Average marks are computed","[func]") // TEST_ CASE macro to take one or more arguments

{

REQUIRE( func(9,5,-7) == 7); // We write our individual test assertions using the REQUIRE macro.

REQUIRE(func(2,4,6,-2) ==4);

}

Explanation Using different IDE:

#include<bits/stdc++.h>

using namespace std;

double FinalAvg(vector<int> students)

{

double sum=0;

for(int i=0;i<v.size();i++) sum+= v[i];

return v.empty() ? 0.0 : (double(sum)/v.size());

}

int main()

{

vector<int> v;

int i;

while(cin>>i&&i>0) v.push_back(i);

cout<<Final Avg(v);

return 0;

}

8 0
3 years ago
Which of the following would an A/V technician NOT typically do? (Select all that apply).
nydimaria [60]
Where is the options?
7 0
2 years ago
Other questions:
  • Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the us
    15·1 answer
  • Browsing the web is one of the most common activities performed by individuals who use computers.
    12·1 answer
  • (3.01 MC)
    11·1 answer
  • What is a computer dedicated to a single function, such as a calculator or computer game? A. TabletB. PDAC.ApplianceD. Minicompu
    6·1 answer
  • A program is run line by line to determine the source of a logic error. Which best describes the specific tool being used?
    11·2 answers
  • If the tax percent is 15% and tax is $36 and percent discount is 10, what is the cost price?​
    12·1 answer
  • What is your favorite anime ( All movies and episodes related to them count )
    8·2 answers
  • Question 1 (1 point)
    9·1 answer
  • When working in outline mode, press __________ and click the eye icon to change only one layer back to preview mode.
    10·1 answer
  • A server is handling thousands of simultaneous connections, and proxying requests to another service. Which concurrency model is
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!