Question

a) You will write a void function to get a positive integer between 1 and 12...

a) You will write a void function to get a positive integer between 1 and 12 inclusive. The twelve numbers represent the months of the year. The user will be asked to enter an integer between 1 and 12 inclusive. If the number entered by the user is not within range, an appropriate error message will be displayed, and the user will be asked to try again until a valid number is entered. b) You will write a void function to print the month number and the month name with an appropriate message. Use a switch statement. c) You will also complete the function main by making a call to the function GetMonthNumber with an appropriate argument and by making a call to the function Display Month with an appropriate argument d) Test the functions using different test data. Show several examples to show that the program performs validation check as well. Write the documentation and include the screenshots.

this question is based on C++ programming

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

// do comment if any problem arises

// code]Using ONLY the following header functions:

#include <iostream>

using namespace std;

void GetMonthNumber(int &month)

{

    // read month

    cout << "Enter an integer between 1 and 12: ";

    cin >> month;

    // invalid month

    while (month < 1 || month > 12)

    {

        cout << "Invalid integer!\n";

        cout << "Enter an integer between 1 and 12: ";

        cin >> month;

    }

}

// b) You will write a void function to print the

void Display_Month(int month)

{

    cout << "\nMonth number: " << month;

    cout << "\nMonth name: ";

    // month number and the month name with an appropriate message.

    // Use a switch statement.

    switch (month)

    {

    case 1:

        cout << "January\n";

        break;

    case 2:

        cout << "February\n";

        break;

    case 3:

        cout << "March\n";

        break;

    case 4:

        cout << "April\n";

        break;

    case 5:

        cout << "May\n";

        break;

    case 6:

        cout << "June\n";

        break;

    case 7:

        cout << "July\n";

        break;

    case 8:

        cout << "August\n";

        break;

    case 9:

        cout << "September\n";

        break;

    case 10:

        cout << "Octuber\n";

        break;

    case 11:

        cout << "November\n";

        break;

    case 12:

        cout << "December\n";

        break;

    default:

        break;

    }

}

int main(int argc, char const *argv[])

{

    // call to the function GetMonthNumber with an appropriate argument

    int month;

    GetMonthNumber(month);

    // and by making a call to the function Display Month with an appropriate argument

    Display_Month(month);

    return 0;

}

Output:

Enter an integer between 1 and 12: 0 Invalid integer! Enter an integer between 1 and 12: 13 Invalid integer! Enter an integer

Add a comment
Know the answer?
Add Answer to:
a) You will write a void function to get a positive integer between 1 and 12...
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
  • Please answer using WHILE

    INFO1112 A11Lab 5Mar. 11, 2021  Due: Thurs. Mar. 18, 2021 using void functions 1.       Complete the program shown below. Note: do not omit the comments a)       You will write a void function to get a positive integer between 1 and 12 inclusive.  The twelve numbers represent the months of the year.  The user will be asked to enter an integer between 1 and 12 inclusive.  If the number entered by the user is not within range, an appropriate error message will be displayed,...

  • 1. Palindrome Write a program that prompts the user for a positive integer number and output whet...

    Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...

  • C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named month...

    C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...

  • Write a program that (in the main program) prompts the user for the (integer) model number...

    Write a program that (in the main program) prompts the user for the (integer) model number of their car. The main function should then call the function check defective which should • take in the model number of the car • check if the model number is 119, 179, 221, 780, or anything between 189 and 195, inclusive, which indicates the car is defective • print a message indicating whether or not the car is defective Note: this is should...

  • *********C Language******* Write a file final_main.c 4. Inside main(void): Write a loop that oops until the...

    *********C Language******* Write a file final_main.c 4. Inside main(void): Write a loop that oops until the entered number is 0 or negative 5. Ask the user to enter a positive int between 0 and 10 inclusive 6. If the number is < 1, it terminates. 7. Else: call the above four functions 8. Print the result of each function after its call. Q2. Write a program that removes the punctuations letters from a file and display the output to the...

  • Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks....

    Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks. The first function prints out the numbers from the first argument up to and including the number passed as the second argument counting by the first argument (i.e. if the arguments are 2 and 10, the information below was given: #include <iostream> using namespace std; // function definitions// // main program int main() {   int firstNumber,secondNumber;   char countType, doAgain;   // we will do this...

  • Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes...

    Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes as argument an integer corresponding to a number of seconds, computes the exact time in hours, minutes and seconds, then prints the following message to the screen: <inputseconds> seconds corresponds to: <hour> hours, <minute> minutes and <second> seconds Write another method called in Seconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total...

  • Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers,...

    Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers, multiplies them together, and prints out the sentence '____ times ____ is ____'. Ask the user for two numbers, and call multiply_and_print with their two numbers as arguments. 2.Write a function called roll_dice that rolls two six-sided dice and prints out the result of each die. Call it three times. (Remember, you can import the random module with the statement import random, and then...

  • Write a program in C++. You need everything everythihng given You will create a function that...

    Write a program in C++. You need everything everythihng given You will create a function that validates input. It should accept only non-negative integers. If the input is incorrect the function should throw an exception. The exception will not be caught in the function. You will create a function that reads in 2 integer values. One is a number that will be raised to the power of the second. So if 5 and 6 are entered the result would be...

  • Write a function named numPerfect that takes as parameters: an array of integer scores between zero...

    Write a function named numPerfect that takes as parameters: an array of integer scores between zero and 100 (inclusive) the size of the array and returns the number of perfect scores in the array. Also write a main function that creates and initializes an array of ints (in the appropriate range), calls the function with that array, and prints out the return value.

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