Question

In: Computer Science

Write a menu driven C++ program that prints the day number of the year , given...

Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008 are divisible by 4 and not divisible by 400. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example , 1600 and 2000 are divisible by 400 , however , 1800 is not a leap year because 1800 is not divisible by 400. Program terminates when the user type in n or N. Fall 2020 – Introduction to C++ Programming Fall 2020 - Husain Gholoom – Senior Lecturer in Computer Science Page 2 Note : Your program must contain the following 6 functions : 1. A function that returns a Boolean value indicating whether or not the day entered is between 1 and 31. 2. A function that returns a Boolean value indicating whether or not the month entered is between 1 and 12. 3. A function that returns a Boolean value indicating whether or not the year entered is greater than 0 and less than or equal to current year. 4. A function that returns a Boolean value indicating whether or not the year entered is a leap year. 5. A function that returns a string value indicating the name of the month. 6. A function that returns a integer value indicating actual number of day that is equivalent to day, month, and year that is entered.

Rules : 1. Your program must compile and run using Code:Blocks version 17.12 under windows. 2. Your program must be documented according the style above . See the website for the sample programming style program. 3. You must use the appropriate libraries in writing this program. 4. You can not use any concept that was not discussed in the class such as arrays , global variables … etc . 5. Must use functions ( prototypes and definitions ) , repetitions , control structures and switch statements. 6. Must properly format the output by use the appropriate library. See the output below. Note that in the following 3 lines : Day Manipulation program by Husain Gholoom 11 / 02 / 2020 • Replace my first / last name with your own first / last name.

Solutions

Expert Solution

code:

#include <iostream>

#include <string>

#include <fstream>

#include <sstream>

using namespace std;

bool isValidDay(int dataIn){

if(dataIn>=1 && dataIn<=31){

return true;

}else{

return false;

}

}

bool isValidMonth(int dataIn){

if(dataIn>=1 && dataIn<=12){

return true;

}else{

return false;

}

}

bool isValidYear(int dataIn){

if(dataIn>0 && dataIn<=2018){

return true;

}else{

return false;

}

}

bool isLeapYear(int year)

{

// If a year is multiple of 400,

// then it is a leap year

if (year % 400 == 0)

return true;

// Else If a year is muliplt of 100,

// then it is not a leap year

if (year % 100 == 0)

return false;

// Else If a year is muliplt of 4,

// then it is a leap year

if (year % 4 == 0)

return true;

return false;

}

string nameOfMonth(int month){

month--;

string months[] ={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

return months[month];

}

int numberOfDay(int day,int month,int year){

int numDaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int count = 0;

for(int i=0;i<month-1;i++){

count+=numDaysInMonth[i];

}

count+=day;

if(isLeapYear(year) && month>2){

count++;

}

return count;

}

int main()

{

while(true){

string date;

cout<<"\nEnter the date : ";

cin>>date;

if(date.compare("n")==0 || date.compare("N")==0){

break;

}

string line;

stringstream ss(date); //stream to other variable

int day;

int month;

int year;

ss>>month>>day>>year;

day = -day; //- symbol read as negative so changing to positive

year = -year; //- symbol read as negative so changing to positive

if(!isValidDay(day)){

cout<<"Invalid day entered!!!"<<endl;

}else if(!isValidMonth(month)){

cout<<"Invalid month entered!!!"<<endl;

}else if(!isValidYear(year)){

cout<<"Invalid year entered!!!"<<endl;

}else{

int getDay = numberOfDay(day,month,year);

cout<<"Number of day is : "<<getDay;

}

}

return 0;

}


Related Solutions

C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of tasks relating to student marks scored in a number of assessments including: displaying all marks, adding new student marks, calculating the mean score, median score, finding the minimum and maximum scores as well as displaying the average mark of a given student. The problem: Student marks are kept in a text file as a single column. Each student may have a different number of...
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and...
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and "#include<cmath>" The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:       0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file has unknown number of records of inventory items, but no more than 100; one record per line in the following order: item ID, item name (one word), quantity on hand , and a price All fields in the input file are separated by a tab (‘\t’) or a blank ( up to you) No error checking of the data required Create a menu which...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
No Global variables No goto statement No break outside switch Write a menu driven C program...
No Global variables No goto statement No break outside switch Write a menu driven C program using functions and switch. Feel free to use “Empty Outlines” template from Canvas to design the functions as needed to build the code. Make sure to submit your work through Canvas. You can show me your code running in class when you are done. The program shows following menu to the user repetitively until user selects option 3 to exit. Circle Triangle Exit Based...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Write a menu-driven program to handle the flow of widgets into and out of a warehouse....
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.     The warehouse will have numerous deliveries of new widgets and orders for widgets     The widgets in a filled order are billed at a profit of 50 percent over their cost     Each delivery of new widgets may have a different cost associated with it     The accountants for the firm have instituted a last-in, first-out system for filling orders         the newest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT