CSIT 575-Programming Fundamentals for Computer Science Lab #3A Objectives To lea
ID: 3596361 • Letter: C
Question
CSIT 575-Programming Fundamentals for Computer Science Lab #3A Objectives To learn to code, compile and run a program containing SELECTION structures Assignment A. Plan and code a C++ program utilizing the if then-else structure to solve the following B. Write an interactive C++ program to determine the day of the week for any given date from 1900-2099 Following are the steps you should use: Input the date in 3 separate parts, month, day and 4-digit year. Error check to make sure the month is between 1and 12, the day between 1and 31, and the year between 1900-2099. If there is an error, identify the type of error and stop the program. C. D. If the data is good, divide the last two digits of the year by 4. Store the quotient (ignoring the remainder) in Total. For example, for 1983, divide 83 by 4 and store 20 in Total Add the last 2 digits of the year to Total E. F. G. Add the two digits of the day of the month to Total Using the following table, find the "value of the month" and add it to Total January = 1 February 4 March 4 April = 0 May 2 June 5 July August 3 September 6 October = 1 November = 4 December 6 If the year is 2000 or later, add 6. If the year is 2000 exactly and the month is January or February subtract 1 H. Then, determine if the year is a leap year. A leap year is divisible by 4 but not divisible by 100. If it is a leap year and the month is January or February, subtract 1. Find the remainder when the Total is divided by 7 Use the remainder to find the day I. 3 Tuesday 1= Sunday 2 Monday 0 = Saturday 5 = Thursday 6 Friday 4 Wednesday Input Your three initials, the month, day, and 4-digit year of the date to analyze Output All of the input fields, a message if the data is OK and the day of the week of the date. Output the date and the appropriate error message if the data is bad Turn in Program listing and program output. Test today's date, your birthdate, and the dates your instructor gives you 3/13/2s14 Th3/ia/ 84s 1111991 0/33/1920Explanation / Answer
#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main(){
string inp;
cout << "Enter the dd/mm/yyyy :";
cin >> inp;
size_t pos;
int day;
int month;
int year;
string yr;
int mon[12];
string days[7];
days[0] = "Sunday";
days[1] = "Monday";
days[2] = "Tuesday";
days[3] = "Wednesday";
days[4] = "Thursday";
days[5] = "Friday";
days[6] = "Saturday";
mon[0] = 1;
mon[1] = 4;
mon[2] = 4;
mon[3] = 0;
mon[4] = 2;
mon[5] = 5;
mon[6] = 0;
mon[7] = 3;
mon[8] = 6;
mon[9] = 1;
mon[10] = 4;
mon[11] = 6;
string delimiter = "/";
if ((pos = inp.find(delimiter)) != string::npos) {
day = atoi(inp.substr(0, pos).c_str());
inp.erase(0, pos + delimiter.length());
}
if ((pos = inp.find(delimiter)) != string::npos) {
month = atoi(inp.substr(0, pos).c_str());
inp.erase(0, pos + delimiter.length());
}
yr = inp;
year = atoi(inp.c_str());
if (year < 1900 && year > 2099){
cout << "Invalid date ";
return 0;
}
if (month > 12 || day > 31){
cout << "Invalid date ";
return 0;
}
int last_two = atoi(yr.substr(2,2).c_str());
int total = last_two/4;
total = total + last_two;
total = total + mon[month-1];
if (year == 2000 && (month == 1 || month==2))
total = total -1;
if (year >= 2000 && month != 1 && month!=2)
total = total + 6;
if (year % 4 == 0 && year % 100 != 0)
if (month == 1 || month == 2)
total = total -1;
cout << days[total % 7] << endl;
}