Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a particular date (also your choosing) with an asterisk. Make sure the calendar displays the week, the days of the week and the year. Make sure the MSU Programming Class appears in the title of the Calendar. I will choose May 1st for the month and date. The code below is what I will be using. Please show where I can go to in the code to place an asterisk for a different day and month.
#include<stdio.h> #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril", "\n\n\nMay", "\n\n\nJune", "\n\n\nJuly", "\n\n\nAugust", "\n\n\nSeptember", "\n\n\nOctober", "\n\n\nNovember", "\n\n\nDecember" }; int inputyear(void) { int year; printf("Please enter a year (example: 1999) : "); scanf("%d", &year); return year; } int determinedaycode(int year) { int daycode; int d1, d2, d3; d1 = (year - 1.)/ 4.0; d2 = (year - 1.)/ 100.; d3 = (year - 1.)/ 400.; daycode = (year + d1 - d2 + d3) %7; return daycode; } int determineleapyear(int year) { if((year% 4 == FALSE && year%100 != FALSE) || (year%400 == FALSE)) { days_in_month[2] = 29; return TRUE; } else { days_in_month[2] = 28; return FALSE; } } void calendar(int year, int daycode) { int month, day; for ( month = 1; month <= 12; month++ ) { printf("%s", months[month]); printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" ); // Correct the position for the first date for ( day = 1; day <= 1 + daycode * 5; day++ ) { printf(" "); } // Print all the dates for one month for ( day = 1; day <= days_in_month[month]; day++ ) { printf("%2d", day ); // Is day before Sat? Else start next line Sun. if ( ( day + daycode ) % 7 > 0 ) printf(" " ); else printf("\n " ); } // Set position for next month daycode = ( daycode + days_in_month[month] ) % 7; } } int main(void) { int year, daycode, leapyear; year = inputyear(); daycode = determinedaycode(year); determineleapyear(year); calendar(year, daycode); printf("\n"); }
The program has been modified to put an asterisk on the date entered by the user:
Code:
#include<stdio.h>
#include<string.h>
#define TRUE 1
#define FALSE 0
int
days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
" ",
"\n\n\nJanuary",
"\n\n\nFebruary",
"\n\n\nMarch",
"\n\n\nApril",
"\n\n\nMay",
"\n\n\nJune",
"\n\n\nJuly",
"\n\n\nAugust",
"\n\n\nSeptember",
"\n\n\nOctober",
"\n\n\nNovember",
"\n\n\nDecember"
};
int inputyear(void)
{
int year;
printf("Please enter a year (example: 1999) : ");
scanf("%d", &year);
return year;
}
int determinedaycode(int year)
{
int daycode;
int d1, d2, d3;
d1 = (year - 1.)/ 4.0;
d2 = (year - 1.)/ 100.;
d3 = (year - 1.)/ 400.;
daycode = (year + d1 - d2 + d3) %7;
return daycode;
}
int determineleapyear(int year)
{
if((year% 4 == FALSE && year%100 != FALSE) || (year%400 ==
FALSE))
{
days_in_month[2] = 29;
return TRUE;
}
else
{
days_in_month[2] = 28;
return FALSE;
}
}
void calendar(int year, int daycode, int monthNum,int
dayNum)
{
int month, day;
for ( month = 1; month <= 12; month++ )
{
printf("%s", months[month]);
printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );
// Correct the position for the first date
for ( day = 1; day <= 1 + daycode * 5; day++ )
{
printf(" ");
}
// Print all the dates for one month
for ( day = 1; day <= days_in_month[month]; day++ )
{
if(monthNum==month && day==dayNum){
printf("%2d*", day );
}
else
printf("%2d", day );
// Is day before Sat? Else start next line Sun.
if ( ( day + daycode ) % 7 > 0 )
printf(" " );
else
printf("\n " );
}
// Set position for next month
daycode = ( daycode + days_in_month[month] ) % 7;
}
}
int getMonthNumber(char * month){
if(strcmp(month,"January")==0 || strcmp(month,"january")==0)return
1;
else if(strcmp(month,"February")==0 ||
strcmp(month,"february")==0)return 2;
else if(strcmp(month,"March")==0 || strcmp(month,"march")==0)return
3;
else if(strcmp(month,"April")==0 || strcmp(month,"april")==0)return
4;
else if(strcmp(month,"May")==0 || strcmp(month,"may")==0)return
5;
else if(strcmp(month,"June")==0 || strcmp(month,"june")==0)return
6;
else if(strcmp(month,"July")==0 || strcmp(month,"july")==0)return
7;
else if(strcmp(month,"August")==0 ||
strcmp(month,"august")==0)return 8;
else if(strcmp(month,"September")==0 ||
strcmp(month,"september")==0)return 9;
else if(strcmp(month,"October")==0 ||
strcmp(month,"october")==0)return 10;
else if(strcmp(month,"November")==0 ||
strcmp(month,"november")==0)return 11;
else if(strcmp(month,"December")==0 ||
strcmp(month,"december")==0)return 12;
}
int main(void)
{
int year, daycode, leapyear;
year = inputyear();
printf("Enter month (example: ):");
char month[20];
scanf("%s",month);
int day;
printf("Enter day :");
scanf("%d",&day);
int monthNum = getMonthNumber(month);
daycode = determinedaycode(year);
determineleapyear(year);
calendar(year, daycode,monthNum,day);
printf("\n");
}
Sample output:
Please enter a year (example: 1999) : 2019
Enter month (example: ):april
Enter day :21
1,21
January
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21* 22 23 24 25 26
27 28 29 30 31
February
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
March
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
April
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
May
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
June
Sun Mon Tue Wed Thu Fri Sat
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
July
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
August
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
September
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
October
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
November
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
December
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
radas-macOS:Desktop radas$ g++ a.cpp
a.cpp:10:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
" ",
^
a.cpp:11:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nJanuary",
^
a.cpp:12:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nFebruary",
^
a.cpp:13:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nMarch",
^
a.cpp:14:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nApril",
^
a.cpp:15:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nMay",
^
a.cpp:16:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nJune",
^
a.cpp:17:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nJuly",
^
a.cpp:18:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nAugust",
^
a.cpp:19:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nSeptember",
^
a.cpp:20:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nOctober",
^
a.cpp:21:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nNovember",
^
a.cpp:22:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nDecember"
^
a.cpp:112:1: warning: control may reach end of non-void function
[-Wreturn-type]
}
^
14 warnings generated.
radas-macOS:Desktop radas$ ./a.out
Please enter a year (example: 1999) : 2019
Enter month (example: ):april
Enter day :21
4,21
January
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
February
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
March
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
April
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21* 22 23 24 25 26 27
28 29 30
May
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
June
Sun Mon Tue Wed Thu Fri Sat
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
July
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
August
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
September
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
October
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
November
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
December
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
radas-macOS:Desktop radas$ clear
radas-macOS:Desktop radas$ g++ a.cpp
a.cpp:10:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
" ",
^
a.cpp:11:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nJanuary",
^
a.cpp:12:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nFebruary",
^
a.cpp:13:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nMarch",
^
a.cpp:14:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nApril",
^
a.cpp:15:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nMay",
^
a.cpp:16:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nJune",
^
a.cpp:17:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nJuly",
^
a.cpp:18:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nAugust",
^
a.cpp:19:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nSeptember",
^
a.cpp:20:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nOctober",
^
a.cpp:21:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nNovember",
^
a.cpp:22:9: warning: conversion from string literal to 'char *' is
deprecated
[-Wc++11-compat-deprecated-writable-strings]
"\n\n\nDecember"
^
a.cpp:111:1: warning: control may reach end of non-void function
[-Wreturn-type]
}
^
14 warnings generated.
radas-macOS:Desktop radas$ clear
radas-macOS:Desktop radas$ ./a.out
Please enter a year (example: 1999) : 2019
Enter month (example: ):april
Enter day :21
January
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
February
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
March
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
April
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21* 22 23 24 25 26 27
28 29 30
May
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
June
Sun Mon Tue Wed Thu Fri Sat
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
July
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
August
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
September
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
October
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
November
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
December
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a part...
Can someone fix my coding please it's a calendar some days are placed wrong. I just want the Main menu to display first and second option and four option to end the program properly. Please remove option number 3 Find the number of days between 2 selected dates and the code that belongs to this function. #include<stdio.h> void days(int,int,int,int,int,int); int month(int,int); int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31}; #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril",...
Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class. (Code given below) import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayList<Month> months; private int number; public Year() { this(2013); } public Year(int number) { this.number = number;...
Please create a C++ class called myDate. It should have the following operations: myDate() – default constructor. This will set the date to May 10, 1959. myDate(int M, int D, int Y) – overloaded constructor. This will set the date to the values passed in through the parameter list represented by Month, Day and Year. void display() – display the date in the following format (May 11, 1959) Do NOT print a linefeed after the date. void incrDate(int N) –...
Please help me figure out why my code is not working properly.I had thought my logic was sound but later found it will run one time through fine however if the user opts to enter another value it will always be returned as an error. #include <iomanip> #include <iostream> #include <cstdlib> using namespace std; int const TRUE = 1; int const FALSE = 0; // declares functions void GetZipcode(); void RunAgain(); int GetSum(char d1, char d2, char d3, char d4,...
Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...
modify the program pls so it then asks the user for another input making the program ask for a yes or no question looping it codeblocks #include <stdio.h> #include <ctype.h> #define NEWLINE '\n' int main(void) { /* Declare variables and function prototypes. */ int k=0, formula[20], n, current=0, done=0, d1, d2; double error=0, weight, total=0; double atomic_wt(int atom); /* Read chemical formula from keyboard. */ printf("Enter chemical formula for amino acid: \n"); while ((formula[k]=getchar()) != NEWLINE) k++; n = k; ...
Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr Sa 5 6 7 8 910 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 To find out the weekday of the first day of the month, call this function: Computes the weekday of a given date. @param year the year @param month the month (1=January 12=...
Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method declarations and Javadoc comments so that you understand what each method is supposed to do. To receive credit for a method, it must use one of the Java loops (your choice). Nested loops are not necessary. Write a Test Class for Your SpeedDating Class Your test class will have a main method that does the following: Create a SpeedDating object Since 1971, Columbus Day...
public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...
please rewrite or convert this C program into Assembly language and please make a notice of which function is which! #include <stdio.h> #include <stdlib.h> void printMonthYear(int mon,int year); void printDaysOfWeek(); void printDays(int mon,int year); int getFirstDayOfMonth(int mon, int year); int getNumOfDaysInMonth(int mon, int year); int main(void) { int mon=-1; int year= -1; printf("Month : "); fflush(stdout); scanf("%d",&mon); if(mon < 1|| mon > 12){ printf("Invalid month >.<!: %d ! Must be between 1 and 12\n",mon); return 1; } printf("Year...