Write a C++ program that, given a person's birth date, computes and displays the day of the week the person was born. Cr
Posted: Fri Jul 08, 2022 6:15 am
statement to compute the m value based on month) If the original birth month is January or February: subtract 1 from the year value. In our case, birth month is January, therefore, modified year-year-1-2064-1-2063. For all other birthday months, do not subtract 1 from the birth year, i.e., modified year = year. D is the last two digits of the modified year. In this example, D-modified year % 100-2063 %100-63. C stands for century: it's the first two digits of the modified year value. In our case, C-2063/100-20. Now let's substitute our example numbers into the formula: f-d+[(13 m-1)/5]+D+ [D/4]+[C/4] -2°C 29+[(13*11-1)/5]+63+ [63/4] [20/41-2-20 29+ [28]+63+ [15]+[5]-40 29+28+63+15+5-40 100.
This f number modulo 7 gives the day of week: (0:Sunday, 1:Monday, 2:Tuesday, 3: Wednesday, 4:Thursday, 5:Friday, 6:Saturday). Use multi-way if statement to display the day of the week. For example, 100%7=2. Therefore Jan 29th, 2064 is on Tuesday. If the remainder is negative, add 7 to the remainder. Given an example data as 6 15 1988 115 2001 1:37 2001 $ 12 2005 219 2000 229 2001 The program should output the following (the format of the output should be exactly as shown below): 6 15 1988 1 15 2001 Wednesday Monday 1 37 2001> Incorrect Data 5 12 2005 Thursday 2 19 2000 Saturday Incorrect Data 2 29 2001 To check whether your program is producing the correct answers, refer to past calendars. On ranger, the command "cal 1988" will display the entire calendar for year 1988. Documentation and program indentation and formatting Make sure to write the program with indentation and documentation style as discussed in "General Program Requirements page: for Labs" on the course web Open https://www.cs.mtsu.edu/-cen/2170/priva ... ements.pdf. .
Electronically submit the program First create a script file by following the steps below: S script logolal Spr-n-t-e4 weekday.cpp $c++ weekday.cpp -o runl S run l<birthday.dat Sexit • (these steps generate a script file named logolal) Then, submit the program with the following command: handin olal weekday.cpp logolal You can submit multiple times, only the last submission will be kept and used for grading. A program template is provided for you to start the project. You may download this program start template from the course page.
Given the example data file: 6 15 1988 1 15 2001 1 37 2001 5 12 2005 219 2000 2 29 2001 4:31 2009 1 27 2021 229 2021 The program output should be: Wednesday Monday Incorrect Data Thursday Saturday Incorrect Data Incorrect Data Wednesday Incorrect Data #include <iostream> // for cin, cout, endl, etc using namespace std; int main() ( int day; // a person's day of birth from user input. int month; // a person's month of birth from user input. int year; // a person's year of birth from user input. // declare other variables here // This loop will read one birthday at a time til the end // of the data file is reached // For each birthday read: // (1) check whether the birthday is valid // if it is not valid, display the message // (2) if it is valid compute and display the day of the week while (cin >> month >> day >>year)
#include <iostream> // for ein, cout, endl, etc using namespace std; int main() ( int day; // a person's day of birth from user input. int month; // a person's month of birth from user input. int year, // a person's year of birth from user input. // declare other variables here // This loop will read one birthday at a time til the end // of the data file is reached // For each birthday read: // (1) check whether the birthday is valid // if it is not valid, display the message // (2) if it is valid compute and display the day of the week while (cin >> month >> day >>year) { cout << month <<""<< day <<"" << year << "=>"; // Check for birthday validity // if the birthday is valid, compute and display its corresponding weekday // end while return 0;
3. For each program module (function), describe/define each variable used in that module. Variable names must be descriptive. Separate variable definitions from variable descriptions. Use the following form for this description: variable declared; // variable description in English sentence(s) Properly indent all code according to descriptions given in "Indent C Programs" (http://www.cs.arizona.edu/-mccann/indent_c.html). You must be consistent in the number of spaces used for indentation. . To improve readability, use a moderate amount of white space, i.e., insert blank lines between blocks of code, and between different modules/functions. Comments need to be written for each logically related block of code. This include a while or for loop, a if decision statement, a switch statement, a group of statements that compute a value, a block of code that read in user data, a group of statements that displays output, etc. 4. For each user defined function, comments need to be written above the function describing: o What does this function do? o What are the expected input values? o What are the expected return values? 5. Programs with syntax error, have compilation error, will not be graded.
Program Development Documentation Style Correctness Description If program has compilation error. If program terminates with run time error. Main Comment Block contains: (due date (1), author name(1), course- section #(1), and program description (2)). Comments have been added to each group of logically related statements above each decision statement (if, if/else) above each loop statement above one or more sequence statements that together accomplish a cohesive task Variable: . . Meaningful variable names are used unless specified by the program description Indentation and white spaces are used to make the program easier to read. . Variable naming convention is followed No global variable is used HALAY All the decision statements are indented properly. All the repetition statements (loops) are indented properly Blank lines are used in front of each block of logically rela statements Program solves the assigned problem using methods described in the program description: Check for user input (5) Week day calculation (20) - negative f value is properly handled in the program (5) Program produces the correct output when tested using different user input. Correct error message was produced if user input is incorrect (10) tan-Correct week day is displayed for valid user input (40)
Write a C++ program that, given a person's birth date, computes and displays the day of the week the person was born. Create a directory named OLAI under the OLA directory. Leave all the files for this assignment in the OLA1 directory. Name your source program "weekday.cpp". Create the source file in the OLAI directory. Copy the data file into your OLAI directory with the following command: S cp-cen/data/birthday.dat birthday.dat The description of the assignment is given below. Check for User inputs Your program should first check for user inputs. If the date entered is not a valid, send out an error message as shown in the example below: 1:37 2001-> Incorrect Data If the date entered is valid, proceed to compute for the corresponding week of the day. Determine the day of the week one was born We use the formula called: Zeller's Rule to compute the day of the week for a person's birthday. The following formula is named Zeller's Rule after a Reverend Zeller. Here's the formula: f-d+(13 m-1)/5 +D+D/4+C/4-2°C. ←declare all variables to be of integer type d is the day of the month. Let's use January 29, 2064 as an example. For this date, d=29. m is the month number. Months have to be counted in a special way for Zeller's Rule: March is 1, April is 2, and so on to January is 11, and February is 12. (This makes the formula simpler, because on leap years February 29 is counted as the last day of the year.) Because of this rule, January and February are always counted as the 11th and 12th months of the previous year. In our example, m-11. (use multi- way if This f number modulo 7 gives the day of week: (0:Sunday, 1:Monday, 2:Tuesday, 3: Wednesday, 4:Thursday, 5:Friday, 6:Saturday). Use multi-way if statement to display the day of the week. For example, 100%7=2. Therefore Jan 29th, 2064 is on Tuesday. If the remainder is negative, add 7 to the remainder. Given an example data as 6 15 1988 115 2001 1:37 2001 $ 12 2005 219 2000 229 2001 The program should output the following (the format of the output should be exactly as shown below): 6 15 1988 1 15 2001 Wednesday Monday 1 37 2001> Incorrect Data 5 12 2005 Thursday 2 19 2000 Saturday Incorrect Data 2 29 2001 To check whether your program is producing the correct answers, refer to past calendars. On ranger, the command "cal 1988" will display the entire calendar for year 1988. Documentation and program indentation and formatting Make sure to write the program with indentation and documentation style as discussed in "General Program Requirements page: for Labs" on the course web Open https://www.cs.mtsu.edu/-cen/2170/priva ... ements.pdf. .
Electronically submit the program First create a script file by following the steps below: S script logolal Spr-n-t-e4 weekday.cpp $c++ weekday.cpp -o runl S run l<birthday.dat Sexit • (these steps generate a script file named logolal) Then, submit the program with the following command: handin olal weekday.cpp logolal You can submit multiple times, only the last submission will be kept and used for grading. A program template is provided for you to start the project. You may download this program start template from the course page.
Given the example data file: 6 15 1988 1 15 2001 1 37 2001 5 12 2005 219 2000 2 29 2001 4:31 2009 1 27 2021 229 2021 The program output should be: Wednesday Monday Incorrect Data Thursday Saturday Incorrect Data Incorrect Data Wednesday Incorrect Data #include <iostream> // for cin, cout, endl, etc using namespace std; int main() ( int day; // a person's day of birth from user input. int month; // a person's month of birth from user input. int year; // a person's year of birth from user input. // declare other variables here // This loop will read one birthday at a time til the end // of the data file is reached // For each birthday read: // (1) check whether the birthday is valid // if it is not valid, display the message // (2) if it is valid compute and display the day of the week while (cin >> month >> day >>year)
#include <iostream> // for ein, cout, endl, etc using namespace std; int main() ( int day; // a person's day of birth from user input. int month; // a person's month of birth from user input. int year, // a person's year of birth from user input. // declare other variables here // This loop will read one birthday at a time til the end // of the data file is reached // For each birthday read: // (1) check whether the birthday is valid // if it is not valid, display the message // (2) if it is valid compute and display the day of the week while (cin >> month >> day >>year) { cout << month <<""<< day <<"" << year << "=>"; // Check for birthday validity // if the birthday is valid, compute and display its corresponding weekday // end while return 0;
3. For each program module (function), describe/define each variable used in that module. Variable names must be descriptive. Separate variable definitions from variable descriptions. Use the following form for this description: variable declared; // variable description in English sentence(s) Properly indent all code according to descriptions given in "Indent C Programs" (http://www.cs.arizona.edu/-mccann/indent_c.html). You must be consistent in the number of spaces used for indentation. . To improve readability, use a moderate amount of white space, i.e., insert blank lines between blocks of code, and between different modules/functions. Comments need to be written for each logically related block of code. This include a while or for loop, a if decision statement, a switch statement, a group of statements that compute a value, a block of code that read in user data, a group of statements that displays output, etc. 4. For each user defined function, comments need to be written above the function describing: o What does this function do? o What are the expected input values? o What are the expected return values? 5. Programs with syntax error, have compilation error, will not be graded.
Program Development Documentation Style Correctness Description If program has compilation error. If program terminates with run time error. Main Comment Block contains: (due date (1), author name(1), course- section #(1), and program description (2)). Comments have been added to each group of logically related statements above each decision statement (if, if/else) above each loop statement above one or more sequence statements that together accomplish a cohesive task Variable: . . Meaningful variable names are used unless specified by the program description Indentation and white spaces are used to make the program easier to read. . Variable naming convention is followed No global variable is used HALAY All the decision statements are indented properly. All the repetition statements (loops) are indented properly Blank lines are used in front of each block of logically rela statements Program solves the assigned problem using methods described in the program description: Check for user input (5) Week day calculation (20) - negative f value is properly handled in the program (5) Program produces the correct output when tested using different user input. Correct error message was produced if user input is incorrect (10) tan-Correct week day is displayed for valid user input (40)