Question

In: Computer Science

c++ Write a program that print stars, Max and Min values. It should use the following...

c++

Write a program that print stars, Max and Min values. It should use the following functions:

  1. (2 pts) int getNum ( ) should ask the user for a number and return the number. This function should be called by main once for each number to be entered. Input Validation: Do not accept numbers less than -100.
  2. (2 pts) void printStars ( int n ) should print n number of stars. If n is less than 0, display "Invalid" message instead.
  3. (5 pts) main ( ) should call getNum ( ) function each time to read the user input. Pass each user input into printStars ( ) function to print stars. This function will loop to process series of integers.
    • (2 pts) When the user input is -99, that's a signal to terminate the loop (end of the user inputs (sentinel value)). Remember, sentinel value should not be processed as part of user inputs.
    • (2 pts) main ( ) should also display overall Min and Max values of user inputs.
  4. (1 pt) Write the function prototypes for getNum ( ) and printStars ( ) functions.

Sample runs :

(Bold underlined numbers below are sample user inputs. Your program should display the exact output given the same user inputs)

Please enter a number : -99
Exiting the program....

// restart the program here and the output is as follows: 
Please enter a number : 1
*
Please enter a number : 2
**
Please enter a number : 3
***
Please enter a number : -99

Min = 1, Max = 3
Exiting the program....

// restart the program here and the output is as follows: 
Please enter a number : -1
Invalid
Please enter a number : 10
**********
Please enter a number : -33
Invalid
Please enter a number : 5
*****
Please enter a number : -99

Min = -33, Max = 10
Exiting the program....

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<iostream>
using namespace std;

int getNum(){
   int num;
   do{
       cout<<"Please enter a number: ";
       cin >> num;
   }while(num<-100);
   return num;
}

void printStars ( int n ){
    if(n<0) cout<<"Invalid\n";
    else{
        for(int i=1;i<=n;i++)cout<<"*";
   }
   cout<<endl;
}

int main(){

   int n;
   int max, min;
   bool first = true;
   while(true){
       n = getNum();
       if(n==-99)break;
       printStars(n);
       if(first){
           max = min = n;
           first = false;
       }
       else if(max<n)max= n;
       else if(min>n)min=n;
   }
  
   cout<<endl;
   if(!first)
   cout<<"Min = "<<min<<", Max = "<<max<<endl;
   cout<<"Exiting the program...";

   return 0;
}


Related Solutions

Get values for min and max using assignment statements and the input function. Print min and...
Get values for min and max using assignment statements and the input function. Print min and max. Run the script. fix any errors you find. Remove the print statements you wrote above. Print the labels "Kelvin" and "Fahrenheit". Print a line of dashes under the labels. Run the script. fix any errors you find. Write a for loop that will give the loop variable kelvin values between min and max. Inside the code block print the value of kelvin Run...
Write a Python program that computes certain values such as sum, product, max, min and average...
Write a Python program that computes certain values such as sum, product, max, min and average of any 5 given numbers along with the following requirements. Define a function that takes 5 numbers, calculates and returns the sum of the numbers. Define a function that takes 5 numbers, calculates and returns the product of the numbers. Define a function that takes 5 numbers, calculates and returns the average of the numbers. Must use the function you defined earlier to find...
Write a C program/code that prompts the user for a minimum min and a maximum max....
Write a C program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
Exercise 9.2 (c++) (max, min, average, and median code) Write a program that asks users to...
Exercise 9.2 (c++) (max, min, average, and median code) Write a program that asks users to input up to 20 integers, and then finds the maximum, minimum, average, and median of the numbers that were entered. Use the following information to write your program. The median is the number that appears in the middle of the sorted list of numbers. If the array has an odd number of elements, median is a single number in the middle of the list...
Write a program/code that prompts the user for a minimum min and a maximum max. Then...
Write a program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. (WRITTEN IN C) For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
Write a C++ program to multiply two matrices a and b and print the result. Use...
Write a C++ program to multiply two matrices a and b and print the result. Use two-dimensional arrays to represent the matrices.
this should be written in Java- Problem: Min/Max Search by Index Develop a program that, given...
this should be written in Java- Problem: Min/Max Search by Index Develop a program that, given a sequence S of integers as input, produces as output two sequences of positive integers, the first of which indicates all those positions in S at which S's minimum value occurs and the second of which indicates all those positions at which S's maximum value occurs. Positions are numbered starting at zero (0). Facts ● Scanner has a method that returns a boolean indicating...
Write a program to read in a collection of integer values, and find and print the...
Write a program to read in a collection of integer values, and find and print the index of the first occurrence and last occurence of the number 12. The program should print an index value of 0 if the number 12 is not found. The index is the sequence number of the data item 12. For example if the eighth data item is the only 12, then the index value 8 should be printed for the first and last occurrence....
Write a C++ program for the following problem: Calculate and print the area and volume of...
Write a C++ program for the following problem: Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Don't worry about...
PLEASE USE PTHON SPYDER Given a data file, find the max, min, and average values of...
PLEASE USE PTHON SPYDER Given a data file, find the max, min, and average values of columns. Also, create an addition column that is based on the other columns. There will be no error checking required for this lab. You are provided with a data file named (surprise!) data.txt. Data is arranged in columns where each item of data is twelve columns wide (so it is easy to extract data items using slicing): Name Height(m) Weight(kg) Joe 1.82 72.57 Mary...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT