Question

In: Computer Science

Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation...

Write a C++ program to do the following USING ARRAYS

1) input 15 integers (input validation , all numbers must be between 0 and 100)

2) find the largest number

3) Find the Smallest Number

4) Find the Sum of all numbers in the Array

Display: as per the user's section (menu using switch or if else )

Largest Number

Smallest Number

Sum of all numbers

the original Array

DO NOT USE METHODS OR FUNCTIONS Submit: Source code (C++)

output (Word or pdf file)

Also include a while loop to repeat the program

Solutions

Expert Solution

#include<iostream>
using namespace std;

//main
int main()
{
    //array declaration
    int arr[15];
    cout<<"Enter 15 integers between 0 & 100:\n";
    //variables declaration
    int i=0,x,minn=100,maxx=0,sum=0;
    //while loop
    while(i<15)
    {
        cin>>x;
        //validate if the input is between 0 & 100
        if(x>0 && x<100)
        {
            arr[i]=x;
            if(x<minn)
                minn=x;   //smallest number
            if(x>maxx)
                maxx=x;   //largest number
            sum=sum+x;   //calculating sum
            i++;
        }
        else
        {
            cout<<"wrong input,try again...";  //in case of wrong input
        }

    }
    //printing results
    cout<<"Largest Number: "<<maxx<<endl;
    cout<<"Smallest Number: "<<minn<<endl;
    cout<<"Sum of all numbers: "<<sum<<endl;
    
    i=0;
    //printing array using while loop
    cout<<"Original Array: ";
    while(i<15)
    {
        cout<<arr[i]<<" ";
        i++;
    }




    return 0;
}

OUTPUT:


Related Solutions

Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays,...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays, the type of item, its cost, and the number in stock. The program should output this information in the form of a table. The output will look something like below. Also, assume for a finite number of item name of 3 Item Name Cost Number in Stock Widget 25.00 4 ... ... ... Wombet 47.50 9 Prelude to Programming (6th edition)
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the...
In C++, write a program that uses two identical arrays of ten randomly ordered integers. It...
In C++, write a program that uses two identical arrays of ten randomly ordered integers. It should display the contents of the first array, then call a function to sort it using the most efficient descending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using descending order selection sort, modified to print out the...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
Write a C program whose input is two integers, and whose output is the first integer...
Write a C program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers by repeatedly calling a “swap” subroutine. The original unsorted list of integers should be received from the keyboard input. Your program should first prompt the user “Please input an integer for the number of elements:”. After the user enters a number and return, your program outputs message “Now input each element and then a return:”. For example, if the user enters 5 as the...
Write a program that first gets a list of integers from input. The input begins with...
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain fewer than 20 integers. That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a space,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters,...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters, dimes, nickels, and pennies in a given amount of money. The input should be a floating-point value representing a decimal value. Example: 63.87 à 63 [dollars and 87 cents] should output 63 dollars, 3 quarters, 1 dime, 0 nickels, and 2 pennies. 2. In trigonometry the cosine function can be calculated using cos(x) = 1 – x 2 /2! + x 4 /4!- x...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT