Question

Please answer using WHILE

INFO1112 A11

Lab 5

Mar. 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, 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.  Consider a good layout when displaying the output.

 

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 DisplayMonth with an appropriate argument

 

d)       Add a loop to allow the program to repeat, allowing the user to continue.  Consider proper indentation and alignment of the statements.

 

e)       Output your name as well before the program ends.

 

f)        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.

 

g)       Submit the files to Moodles:   .cpp, .exe, and the Word document.

 


 1.PNG

 

 

 

 

2.PNG

 3.PNG

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



 


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

#include<iostream>  // for using cin and cout


using namespace std;


// function Protoype

void GetMonthNumber(int&);

void DisplayMonth(int);



int main()

{

    // Add a loop to allow the program to repeat

    while(1){

        int monthNum;               // a number respresenting a month

        GetMonthNumber(monthNum);   //get a month number

        DisplayMonth(monthNum);     // call function to output the month number

        // and month name

        

        system("pause");

    }

    

    return 0;

}

//******************************************************************************

// Defination of function GetNumber.

// The parameter number in a reference parameter to an int.

// The function asks the user to enter an integer between 1 and 12 inclusive.

// If the number entered in not within range, an error message will be

// displayed, and the user will be asked to try again untill a valid number is

//******************************************************************************

void GetMonthNumber(int &number){

    //prompt user to enter number and read the number

    cout<<"\nEnter a number between 1 and 12 inclusive: ";

    cin>>number;

    // If the number entered in not within range, an error message will be

    while(number<1 || number>12){

        cout<<number<< " is not between 1 and 12 inclusive.\n";

        cout<<"Try again. Enter a number between 1 to 12: ";

        cin>>number;

    }

}

//****************************************************************************

// Definition of function DisplayMonth.

// The paratemer number holds an integer between 1 and 12 inclusive

// representing a month number.

// The function displays the month number ans the corresponding month name.

//****************************************************************************

void DisplayMonth(int number){

    // switch case check month number

    // displays the month number ans the corresponding month name.

    // month number: month name

    switch (number)

    {

        case 1:

            cout<<"1: Januaray";              

            break;

        case 2:

            cout<<"2: Febuarary";

            break;

        case 3:

            cout<<"3: March";

            break;

        case 4:

            cout<<"4: April";

            break;

        case 5:

            cout<<"5: May";

            break;

        case 6:

            cout<<"6: June";

            break;

        case 7:

            cout<<"7: July";

            break;

        case 8:

            cout<<"8: Auguest";

            break;

        case 9:

            cout<<"9: September";

            break;

        case 10:

            cout<<"10: October";

            break;

        case 11:

            cout<<"11: November";

            break;

        case 12:

            cout<<"12: December";

            break;

        default:

            break;

    }

    cout<<"\n";

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Please answer using WHILE
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
  • 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...

  • C++

    INFO1112 A11Lab 6March 18, 2021 Note:  It is important that you do this lab exercise properly.  Please read and follow the instructions very carefully.  You need to understand what you are required to do, and complete the program.  It uses a one-dimensional array.  You can refer to the PowerPoint slides, many of the tasks can be found there, but you need to apply them for this program. Note that the array will be filled with the integers when the user enters them. Consider...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • 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...

  • *********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...

  • c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did...

    c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did the program Except this time we modularize our program by writing functions, instead of writing the entire code in main. The program must have the following functions (names and purposes given below). Fot o tentoutefill datere nedefremfite You will have to decide as to what arguments must be passed to the functions and whether such passing must be by value or by reference or...

  • Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to...

    Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to calculate the summation of a five-digit number. This function receives one integer parameter 'a', then returns the sum of 5 digits of the number. [2.5 marks] b. Write a function, called Armstrong that prints all Armstrong numbers in the range of 0 and 500. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • 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...

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