Question

using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100....

using C++

Write a program that:
a) Inputs an integer n from the keyboard where n<=100. If n is out of range then
print out an error message and ask for another input. This process repeats until a
valid value for n is obtained.
b) Inputs two 1D arrays of doubles A and B (of size n) from the keyboard.
c) Inputs an integer k (from 1 to 3) from the keyboard.
d) If k = 1 then it calculates the average value of A[i] and prints it to the screen.
e) If k = 2 then it calculates the minimum value of B[i] and prints it to the screen.
f) If k = 3 then it calculates the dot product of A and B and prints the result to the
screen.
g) If k is out of range then the program prints out an error message and terminates
the program.
h) Parts c) to g) repeat until every valid value of k (ie menu item) has been selected
at least once (or part g terminates the program). If you don’t know how to do this
part you can just assume parts c) to g) repeat indefinitely.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol.

Below is implemented according to the parts of the quetion.

#include<bits/stdc++.h>
using namespace std;

void avg(double * A, double * B, int n){
double sum=0;
for(int i=0;i<n;i++)
sum+=A[i];
cout<<"Average value of A is: "<<sum/n<<endl;
}

void mini(double * B , int n){
double *m = min_element(B, B+n);
cout<<"Minimum value of B is: "<<*m<<endl;
}

void dot(double *A, double *B, int n){
double sum=0;
for(int i=0;i<n;i++){
sum+=A[i]*B[i];
}
cout<<"Dot product is: "<<sum<<endl;
}

int main(){
int n,k,a=100;
while(a){
cout<<"Enter the value between 0 to 100: "<<endl;
cin>>n;
if(n>100 || n<0)
continue;
double A[n], B[n];
cout<<"Enter value for array A"<<endl;
for(int i=0;i<n;i++)
cin>>A[i];
cout<<"Enter value for array B"<<endl;
for(int i=0;i<n;i++)
cin>>B[i];
int k = 0;
cout<<"Enter value of k between 1 to 3"<<endl;
cin>>k;
if(k>3 || k<1){
cout<<"Entered K value was not in range"<<endl;
break;
}
if(k==1)
avg(A,B,n);
if(k==2)
mini(B,n);
if(k==3)
dot(A,B,n);
  
a--;
}

return 0;
}

upvote...plzzz

Add a comment
Know the answer?
Add Answer to:
using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that inputs up to 100 real numbers from the keyboard (one at a...

    Write a program that inputs up to 100 real numbers from the keyboard (one at a time). When a number greater than 1.0e9 is input the keyboard input will stop. Then the following statistic for the input data will be computed and printed out to the screen. a) average b) standard deviation c) minimum value d) maximum value e) range = (maximum-minimum)/2 f) the number of times zero is input **Note: this is a program in C++** 3) Write a...

  • Part A Write a Java program that reads an integer n from the keyboard and loops...

    Part A Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised. Part B Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied.   Will give thumbs up...

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • Write a Java program that inputs a list of integer values in the range of −...

    Write a Java program that inputs a list of integer values in the range of − 1 to 100 from the keyboard and computes the sum of the squares of the input values. This program must use exception handling to ensure that the input values are in range and are legal integers, to handle the error of the sum of the squares becoming larger than a standard Integer variable can store, and to detect end-of-file and use it to cause...

  • Write a program that reads a positive integer N, where N is greater than 1 and...

    Write a program that reads a positive integer N, where N is greater than 1 and prints the value of the floating-point value SUM where SUM is the results of the following series. SUM = 1/1! + 2/2! + 3/3! + 4/4! + ... N/N! Note that your program should print the message “Sorry, bad N”” if N is <=1, and keep reading user input until the user enters a valid value for N. Also, note that all division operations...

  • write a java program Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • Write a complete C program with a helper function that reads an integer from the keyboard...

    Write a complete C program with a helper function that reads an integer from the keyboard and prints its factorial to the standard output

  • Program : Write a complete C++ program that Input: Read a positive integer from the keyboard...

    Program : Write a complete C++ program that Input: Read a positive integer from the keyboard (user) with proper prompt text and save it to a variable. The integer have up to five digits. Processing: From the right most digit, extract every digit from the input integer using modular operator %then save the digit to a separate variable. Remove the right most digit from the integer using integer division operator /. Repeat above two steps till all digits have been...

  • 6. Consider a C program that reads two real numbers from the keyboard followed by a character where the character can b...

    6. Consider a C program that reads two real numbers from the keyboard followed by a character where the character can be one of the operators +,-, *, 1, or % providing the addition, subtraction, multiplication, division, or remainder respectively. Then the result is displayed on the screen For example, if the user types 2.0 3.0 % then your code will display: Note: In the above example the inputs are real numbers but the remainder only performs an integer operation....

  • Question 1: Consider the following specification for a program. The program reads two inputs from the...

    Question 1: Consider the following specification for a program. The program reads two inputs from the user: a string s and an integer number n. The program concatenates s with itself n-1 times, if the following conditions are satisfied: 1- s consists of 3 characters. 2- The first character in s is a letter. 3- s consists of letters (A-Z a-z) and digits only (0-9) 4-0< n<5 If any of these conditions is not satisfied, the program terminates and prints...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT