Tabbing a Calendar console application using C - c

I am implementing a simple yearly calendar in traditional format in a console application using ANSI C. The calendar must be tabbed to show in the format of 3 x 4 months. Till now I managed to display all the months beneath each other as shown in the code below. Any help how can I tackled the tabbing part? I tried to split the month[] into 3 according to the column for example Jan, April, July and October will be the 1st column and then work column by column, but I don't know if it is the best thing to do...any help please?
#include<stdio.h>
int main()
{
int d,y,no_lp,n,i=1,j,month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("Enter year:");
scanf("%d", &y);
if (y%4==0)
{month[2]=29;}
no_lp= (27 + (42/5) + (y-1) + ((y-1)/4) - ((y-1)/100) + ((y-1)/400) + 1);
d= no_lp%7;
n=d;
for(j=1;j<=12;j++)
{
printf("\n\n %s",monthname[j]);
//printf ("\n\n%d",j);
printf("\n Su Mo Tu We Th Fr Sa\n");
while(d--!=0)
printf(" "); //spaces for empty days
while(i<=month[j])
{
if(i<10)
{printf(" %d ",i++);} //formating for dates with 2 digits
else{printf("%d ",i++);}//formatting for dates with 1 digit
n++;
if(n==7) //if 7 is reached start new line
{
n=0;
printf("\n");
}
}
d=n;
i=1; //n will be the 1st day of next month
}
return(0);
}

You can replace
if(i<10)
{printf(" %d ",i++);} //formating for dates with 2 digits
else{printf("%d ",i++);}//formatting for dates with 1 digit
with
printf("%2d ",i++);
In order to print 3 * 4, don't print on the fly
Store those values
char out[12][6][24];
| | |
n months <- | -> string containing week in calendar (e.g 10 11 12 13 14 15 17)
V
Max weeks in a month
and print
week 1 month 1 , week 1 month 2 , week 1 month 3
week 2 month 1 , week 2 month 2 , week 2 month 3
week 3 month 1 , week 3 month 2 , week 3 month 3
...
week 1 month 4 , week 1 month 5 , week 1 month 6
week 2 month 4 , week 2 month 5 , week 2 month 6
week 3 month 4 , week 3 month 5 , week 3 month 6
...
...

Related

Operator precedence is confusing on long statement

I have worked with a simple C program to find the Day for Given Date. For it, I have written a lot of lines to calculate the day and month and to find the kind of the given year. While Surfing I came to know about a single line code to find the day for the given date. The code is as below
( d += m < 3 ? y --: y- 2, 23 * m / 9 + d + 4 + y / 4 - y / 100 + y / 400) % 7 ;
// 0 - Sunday, 6 - saturday
It gave the correct answer for all inputs, but I couldn't understand the values used in this expression.
Why the sum of day and month is checked for less than 3.
Why the year is reduced by one and the condition fails it decreases the year by 2.
Why the numbers 3, 23 and 9 are used in this expression.
I have confused about the operator precedence on this statement. Can anyone explain how this works?
What I've found so far:
23 * m / 9 results in
1 2 3
2 5 2
3 7 3
4 10 2
5 12 3
6 15 2
7 17 3
8 20 3
9 23 2
10 25 3
11 28 2
12 30 3
This expression adds the days over 28 days of a month.
The expression y / 4 - y / 100 + y / 400 results in:
1995 483 0
1996 484 1
1997 484 1
1998 484 1
1999 484 1
2000 485 2
2001 485 2
with the result, adding one day every 4 years (except leap years)
Because every year with 365 days (mod 7 == 1) increments the weekday by 1, the years are added to the days.
The expression d + (m < 3 ? y --: y- 2) is for correcting the leap year calculation. If we have a leap year, we can correct by one day only if we have a month >= march.

How to find the max,min value for specific season per year of a column in an array in R?

I have the following array which I called station:
A1 <- matrix(runif(120),24,5)
A1[1:12,1]<-2012
A1[13:24,1]<-2013
A1[1:12,2]<-(1:12)
A1[13:24,2]<-(1:12)
A1[1:12,3]<-seq(1,24,by=2)
A1[13:24,3]<-seq(1,24,by=2)
A2 <- matrix(runif(120),24,5)
A2[1:12,1]<-2012
A2[13:24,1]<-2013
A2[1:12,2]<-(1:12)
A2[13:24,2]<-(1:12)
A2[1:12,3]<-seq(1,24,by=2)
A2[13:24,3]<-seq(1,24,by=2)
station <- array(NA,c(24,5,2))
station[,,1] <- A1
station[,,2] <- A2
dimnames(station)[[2]]<-c('year','month','day','win_3','win_7')
dimnames(station)[[3]]<-c('station1','station2')
print(station)
I would like to extract max value of win_3 which I called Max_3Days through spring season (i.e, month 3,4 and 5) of each year for each station and specify the corresponding value of day and month (either 3,4 or 5).
The same thing for min value, I want to extract it from win_7 which I called Min_7Days through summer season (i.e, month 6,7 and 8) of each year for each station and specify the corresponding value of month (either 6,7 or 8) and day
I would like to keep the result in array format if it possible.
The result should be like this:
, , 1
Year Month day Max_3Days Year Month Day Min_7Days
[1,] 2012 3 15 2800 2012 6 1 400
[2,] 2013 4 2 2730 2013 6 4 100
, , 2
Year Month day Max_3Days Year Month Day Min_7Days
[1,] 2012 4 15 2800 2012 7 10 250
[2,] 2013 5 2 2750 2013 7 14 271
I did specify spring and summer season and find the max, min values when I was having only one station as a data frame format, I want to do this for about 70 station in a (matrix) of an array format, and I want to keep the result in an array:
In case of data frame (only one station):
Summer<-station[which(station$month>"5"&station$month<"9"),]
Minima<-ddply(Summer, ~ year, summarise, month=month[which.min(win_7)],day=day[which.min(win_7)], Min_7Days =min(win_7, na.rm = TRUE))
Spring<-station[which(station$month>"2"&station$month<"6"),]
Maxima<-ddply(Spring, ~ year, summarise, month=month[which.max(win_3)],day=day[which.max(win_3)], Max_3Days =max(win_3, na.rm = TRUE))
Any suggestion would be appreciated!!
currently i have made them into a list and went ahead.
l = vector('list', 2)
l[[1]] = data.frame(station[,,1])
l[[2]] = data.frame(station[,,2])
spring_end <- 5
spring_start <- 3
summer_end <- 8
summer_start <- 6
library(dplyr)
func <- function(df){
df %>% group_by(year) %>%
summarise( Max_3Days = max(win_3[between(month, spring_start, spring_end)]),
Month_spring = month[between(month, spring_start, spring_end)][which.max(win_3[between(month, spring_start, spring_end)])],
Min_7Days = min(win_7[between(month, summer_start, summer_end)]),
Month_summer = month[between(month, summer_start, summer_end)][which.min(win_7[between(month, summer_start, summer_end)])])
}
lapply(l, func)
#[[1]]
# year Max_3Days Month_spring Min_7Days Month_summer
#1 2012 0.6521762 5 0.3547476 6
#2 2013 0.9627131 3 0.1754293 6
#[[2]]
# year Max_3Days Month_spring Min_7Days Month_summer
#1 2012 0.6115331 5 0.08505264 6
#2 2013 0.6051239 3 0.10938192 8

Difference between weeks in MDX

How I can calculate difference between each week and 2 weeks ago, for a given measure in MDX?
WEEK MEASURE NEW_MEASURE
---- ------- -----------
1 10 NULL
2 5 NULL
3 20 10
4 10 5
5 40 20
Below Members work, but only without CASE statement so I have to calculate it separately:
MEMBER [Measures].[12 Week temp]
AS
([Date].[Week Year].CurrentMember, [Measures].[Total Orders]) -
([Date].[Week Year].lag(13), [Measures].[Total Orders])
MEMBER [Measures].[12 Week]
AS
CASE WHEN [Measures].[12 Week temp] = [Measures].[Total Orders] THEN 0 ELSE [Measures].[12 Week temp] END

Edit Matrix in ReportViewer Using Code in Vb

I have this in my DataBase :
Table Days:
IdDay NameDay
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
Table Time:
IdTime Time
1 9am
2 10am
3 11am
Table Work:
IdWork NameWork IdDay IdTime
1 cleaning 6 3
2 Studying 1 2
I am trying to edit a Matrix in My ReportViewer:
Day [Time]
[NameDay]
I want to use code and edit my Matrix like this Algo :
if database day = day in the matrix && database Time= time in matrix
Put NameWork
Is there a way to do that ?

SAS Creating entries by group

I have an array that I want to add years and months sequentially to using a SAS program:
Original:
ID
1
2
3
End result:
ID YEAR; MONTH
1 2014 11
1 2014 12
1 2015 1
1 2015 2
1 2015 3
2 2014 11
2 2014 12
2 2015 1
2 2015 2
2 2015 3
3 2014 11
3 2014 12
3 2015 1
3 2015 2
3 2015 3
I also need to set the upper lower limits for the years and months I want to add to the table.
Any help is appreciated. Thanks!
As the comments suggest, I'm taking a bit of a guess on what you're looking for. From what you're asking, I'd recommned using a data step to loop through your original data, outputing multiple rows for each line in the original data.
This uses intnx to advance to the next month (intnx documentation)
*Enter start and end date here;
%Let startdt = '01NOV2014'd;
%Let enddt = '01MAR2015'd;
data want (drop=_date);
set original;
*Create multiple records for each observation in 'original'- one for each month;
_date = &startdt;
DO UNTIL (_date > &enddt);
year = year(_date);
month = month(_date);
output;
*Advance to next month;
_date = intnx('month', _date, 1, 'beginning');
END;
run;

Resources