Question

In: Computer Science

Create a strongly typed enumerator for the days of the week, and put it in a...

  1. Create a strongly typed enumerator for the days of the week, and put it in a header file enum.h

  2. Create a test program with a switch statement that has a function that prints the day word based on numeric input from the user.  

  3. Utilize the local predefined variable __func__ to display the name of the current function.

Student Learning Outcomes:

  • Create and utilize strongly typed enumerators

  • Correctly implement scope resolution for strongly typed enumerators

  • Cast variable types for proper comparisons

  • Display the current function’s name

STYLE NOTE: enumerators are constant, so many people think that the entire enumerator value (e.g. sunday) should be in all caps. Others follow the rule that since the variable type is created by the programmer, it should start with an uppercase letter. You may choose either one, but be consistent. I happen to use the first as it gives a clear visual indicator that it is a special variable.

Solutions

Expert Solution

Program for the given question:

1) Creating a header file containing strongly typed enum. Create a file enum.h and write the line below it and save it in same folder where your c program is saved which is going to use this header file

enum.h

//creating the strongly typed enum

enum class daysOfWeek{SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURADY };

---------********---------

2) Now, we write the code for main program which is going to use this header file

weeks.cpp

// Weeks.cpp : This file contains the 'main' function. Program execution begins and ends there.

//

#include <iostream>

#include "enum.h"

using namespace std;

//execution of program starts from here

int main()

{

//variable to store user input

int user_input = 0;

cout << "Days Numbering are as follow\n";

cout << "1: Sunday\n2: Monady\n3: Tuesday\n4: Wednesday\n5: Thursday\n6: Friday\n 7: Saturday\n";

count << "Enter the day number you want to print : ";

//ask for user input

cin >> user_input;

//switch statement to print date based upon user input

switch (user_input-1)

{

case (int)daysOfWeek::SUNDAY:

printf("Today is Sunday");

printf("Called function is: %s\n", __func__);

break;

case (int)daysOfWeek::MONDAY:

printf("Today is Monday\n");

printf("Called function is: %s\n", __func__);

break;

case (int)daysOfWeek::TUESDAY:

printf("Today is Tuesday\n");

printf("Called function is: %s\n", __func__);

break;

case (int)daysOfWeek::WEDNESDAY:

printf("Today is Wednesday\n");

printf("Called function is: %s\n", __func__);

break;

case (int)daysOfWeek::THURSDAY:

printf("Today is Thursday\n");

printf("Called function is: %s\n", __func__);

break;

case (int)daysOfWeek::FRIDAY:

printf("Today is Friday\n");

printf("Called function is: %s\n", __func__);

break;

case (int)daysOfWeek::SATURADY:

printf("Today is Saturday\n");

printf("Called function is: %s\n", __func__);

break;

default:

printf("Wrong Input, try agian!\n");

break;

}

}

----------******---------

Note : As there is only one function i.e "main()", the __func__ will going to print the name of this function each time.

And we have to cast the strongly typed enum to int so that it can be used for matching inside switch statement.

----------******----------

Output for the above program:


Related Solutions

Create a one week (7 days) workout Tell me why you choose these workouts or rest...
Create a one week (7 days) workout Tell me why you choose these workouts or rest activity Hit Every Muscle Group Leave adequate time for rest in between workouts or muscle groups One week workout. What you do for example if you do bicep curls you would write bicep curls 3x10 - 3 sets of 10 reps rest - why you rest or choose an active rest workout.
Create Kernel of a Strongly Connected Components using Kosaraju's Algorithm in Java. I have to create...
Create Kernel of a Strongly Connected Components using Kosaraju's Algorithm in Java. I have to create a Kernel DAG using the Strongly Connected Components found using Kosaraju's Algorithm. The input to the code is in the format. 5 \n 5 \n 1 0 \n 0 2 \n 2 1 \n 0 3 \n 3 4 The code will find the SCCs and print them to the screen, however, I need to find a way to construct a kernel based on...
TYPED ANSWER PLEASE In present COVID-19 circumstances the government put the restriction on the hiking the...
TYPED ANSWER PLEASE In present COVID-19 circumstances the government put the restriction on the hiking the prices of the medical items such as “face mask, Sanitizer and the Hand gloves). Similarly, during the “Ramadan” government put restriction on raising the prices of the essential commodities used during this festive month of “Ramadan” Considering these situation Discuss concept of (a) Price Celling and Price Floor ( support with different example) (b) Analyze the outcome of government intervention by applying these two...
Create a matrix of ingredients by customer. Put an “x” for each item ordered. Put in...
Create a matrix of ingredients by customer. Put an “x” for each item ordered. Put in the time for each ingredient in each cell. What’s the most popular ingredient? What’s the least popular ingredient? Which sandwich takes the longest? Customer number, their order: 1. Turkey, lettuce, tomato, mayo, pepper, whole wheat (4 minutes) 2. Ham, swiss, lettuce, tomato, mustard, white (3:30 minutes) 3. Turkey, ham, lettuce, mustard, rye, hot (3 minutes) 4. Turkey, ham, lettuce, provolone, tomato, salt, pepper, olive...
A firm works 5 days a week. Every employee must work exactly 2 full days and...
A firm works 5 days a week. Every employee must work exactly 2 full days and 3 half-days each week. A half-day can be either morning or afternoon, and two half-days cannot be held on the same day. How many possible different weekly schedules are there? if the firm has 374 employees, how many people must have the same work schedule for a particular week? What is the smallest number of employees needed to guarantee at least 7 workers have...
please create a tool for Gene Expression. This may be a series of drawings, well-organized typed...
please create a tool for Gene Expression. This may be a series of drawings, well-organized typed notes, ( Don't handwrite) You must include ALL the following terms: Gene DNA Transcription Translation Codon RNA Amino Acid Protein Ribosome tRNA Promoter Plasmid Frameshift Mutation Base Substitution Missense Mutation Nonsense Mutation Silent Mutation
QUESTION 1 The Jubail Bicycle Shop operates 7 days per week, closing 5 days each for...
QUESTION 1 The Jubail Bicycle Shop operates 7 days per week, closing 5 days each for Eid-ul-Fitr and Eid- Ul -Adah (this gives 355 working days in a year). The shop pays SAR 600 for a particular bicycle purchased from the manufacturer. The annual holding cost per bicycle is estimated to be 25% of the SAR value of inventory. The shop sells an average of 25 bikes per week. Frequently, the dealer does not have a bike in stock when...
A police department released the numbers of calls for the different days of the week during...
A police department released the numbers of calls for the different days of the week during the month of​October, as shown in the table to the right. Use a 0.01 significance level to test the claim that the different days of the week have the same frequencies of police calls. What is the fundamental error with this​ analysis? Day Sun Mon Tues We Thurs Fri Sat Frequency 155 206 220 244 176 215 240 Calculate the test​ statistic,chi squaredχ2. Calculate...
The HR department of a certain corporation wants to know if some days of the week...
The HR department of a certain corporation wants to know if some days of the week had more workers call in sick than others. 100 sick day reports are randomly selected. Test the claim that sick days occur with the same frequency on every day of the week using a 0.05 significance level. Day Mon Tue Wed Thu Fri # of sick calls 22 15 17 16   30
A police department released the numbers of calls for the different days of the week during...
A police department released the numbers of calls for the different days of the week during the month of​ October, as shown in the table to the right. Use a 0.01 significance level to test the claim that the different days of the week have the same frequencies of police calls. What is the fundamental error with this​ analysis? Day Sun Mon Tues Wed Thurs Fri Sat Frequency 153 210  224 248 174 212 231 Determine the null and alternative hypotheses....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT