Epic Systems Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

//One more approach
//======================================
#include<stdio.h>
int main()
{
    int months[]={31,28,31,30,31,30,31,31,30,31,30,31};
    int i,j,year;
    printf("Enter year ");
    scanf("%d",&year);
    if(year%4==0)
        months[1]=29;
    for(i=0;i<12;i++)
        for(j=0;j<months[i];j++)
            printf("%d/%d/%d\n",i+1,j+1,year);
}

//================================================

- Rock September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

leap year calculation is not correct.

if ((year%400 == 0) || (year%4 == 0 && year%100 != 0))
  months[1] = 29;

- Psycho October 10, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import calendar

def printCal():
    year = raw_input(int("Which year?"))
    print calendar.calendar(year)

- manoj August 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

lmao

- Anonymous February 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@manoj
ain't we supposed to write full code for printing the calendar and not use any existing functionality to do the same?

Have a look here
http://coverage.livinglogic.de/Lib/calendar.py.html

- lickie August 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do we need to print out the weekday corresponding to a date in the calendar? for example, Jan. 1st is Friday.

- Anonymous August 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How do u know the day of the week for 1st Jan of the given year??

- raj August 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can make the calender by using the concept of odd days
like for example......
suppose the give year is 1980 now calculate the odd days for the 1 Jan 1980.
Odd days in a year 365mod7 gives 1
Odd days in a year 366mod7 gives 2 leap year.
so by this we can calculate the odd days in
100 year = 5 odd days
200 year = 3 odd days
300 year = 1 odd days
and 400,800,1600 have 0 odd days.
now claculate the odd days for 1 Jan 1980
No. of Year odd days
1600 0
300 1
79 0 ((79/4)*2+(79-(79/4)))mod7=0
-----------------
1979 1
n for 1 Jan 1
-----------------
total 2 odd days

and 0 is Sunday 1 is Monday 2 is Tuesday and so on
so the year 1980 start with Tuesday now we can easily make the calender for the year.

i hope this will help............

- ravi August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what do u mean by odd days??Can u explain please..

- Anonymous September 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry this is print all dates for a year. Not calendar

- Anon September 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it will print, u just have to set according to the months.
means u have day of year's very first date(1st January). if it is a leap year then set all months according to feb of 29 othervise set it normaly.

- aashi September 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

any good answer? c'mon guys. put some solution/ideas!

- klpd September 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if only printing date, it'll be much easier

- jackiewu09 September 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am telling you guys. When I said calendar, I meant just dates not the real calendar.

- Anon September 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//The following program should print the calender given a year

// to preserve whitespace
//============================================================================
// Name        : CalendarCPP.cpp
// Author      : 
// Version     :
// Copyright   :
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int main() {
    int year;
    bool leap = false;
    char *months[] = {"January","February", "March", "April", "May", "June",
            "July", "August", "September", "October", "November", "December"};
    cout << "Enter the year: " << endl;
    cin>>year;
    // check for leap year
    /*
    **    The logic is that the year is either divisible by both
    **    100 and 4 , OR its only divisible by 4 not by hundred
    */
    if(year%400 ==0 || (year%100 != 0 && year%4 == 0)) {
        cout<<"Year %d is a leap year\n"<<year;
        leap = true;
    }
    else {
        cout<<"Year %d is not a leap year\n"<<year;
    }

    //January to June
    for(int i=0; i<=6; i++) { // month
        for(int j=1; j<=31; j++) { // days
            if(i!=1) { //Not February
                if(i%2==0){ //31 days
                    cout<<months[i]<<" "<<j<<","<<year<<endl;
                } else { //30 days
                    if(j<31) {
                        cout<<months[i]<<" "<<j<<","<<year<<endl;
                    }
                }
            } else { //February
                if(j<30) {
                    if(leap) {
                        cout<<months[i]<<" "<<j<<","<<year<<endl;
                    } else {
                        if(j<29) {
                            cout<<months[i]<<" "<<j<<","<<year<<endl;
                        }
                    }
                }
            }
        }
    }
    //August to December
    for(int i=7;i<31;i++) { //month
        for(int j=1;j<=31;j++){ //days
            if(i%2!=0){ //31 days
                cout<<months[i]<<" "<<j<<","<<year<<endl;
            } else { //30 days
                if(j<31)
                    cout<<months[i]<<" "<<j<<","<<year<<endl;
            }
        }
    }
    return 0;
}
//================================================================

// to preserve whitespace

- Rock September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take the current date and day of the week.
Find the difference in days between the current date and 1 Jan <given year>
(diff number) mod 7 should return you the correct day of the week for given year
Start printing the calendar (in which ever way you want!)

- Sudhakar September 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree with Sudhakar...

- amit September 20, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes, in order to find the current date/day of the week, you would use inbuilt functions -- which are not allowed. I believe Rock's method looks simple and sweet. Anyway, in the assessment test they just ask you the psudo code and the logical approach.

- Krish December 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ravi

how you calculated odd days in 100 years or so ?
Did you find how many leap and non-leap years in a hundred years, then added all the days in these 100 years. Finally did mod 7 ?

Is there a shorter way ?

- Britney February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ravi

I got what you are saying ! Thanks.

- Britney February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Unix
cal year

- Anonymous October 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

using namespace std;

void printMonthTitle(int year, int month);
int getTotalNumOfDays(int year, int month);
int getNumOfDaysInMonth(int year, int month);
int getStartDay(int year, int month);
bool isLeapYear(int year);
void printMonthBody(int startDay, int numOfDaysInMonth);
const char* getMonthName(int month);

  /** Print the calendar for a month in a year */
   void printMonth(int year, int month) {
    // Get start day of the week for the first date in the month
    int startDay = getStartDay(year, month);

    // Get number of days in the month
    int numOfDaysInMonth = getNumOfDaysInMonth(year, month);

    // Print headings
    printMonthTitle(year, month);

    // Print body
    printMonthBody(startDay, numOfDaysInMonth);
  }

  /** Get the start day of the first day in a month */
   int getStartDay(int year, int month) {
    // Get total number of days since 1/1/1800
    int startDay1800 = 3;
    int totalNumOfDays = getTotalNumOfDays(year, month);

    // Return the start day
    return (int)((totalNumOfDays + startDay1800) % 7);
  }

  /** Get the total number of days since Jan 1, 1800 */
   int getTotalNumOfDays(int year, int month) {
     static int tillYear=0;
    
    if (!tillYear)
    {
        // Get the total days from 1800 to year -1
        for (int i = 1800; i < year; i++)
        {
            if (isLeapYear(i))
              tillYear = tillYear + 366;
            else
              tillYear = tillYear + 365;
        }
    }
    int total = tillYear;
    // Add days from Jan to the month prior to the calendar month
    for (int i = 1; i < month; i++)
      total = total + getNumOfDaysInMonth(year, i);

    return total;
  }

  /** Get the number of days in a month */
   int getNumOfDaysInMonth(int year, int month) {
    if (month == 1 || month==3 || month == 5 || month == 7 ||
      month == 8 || month == 10 || month == 12)
      return 31;

    if (month == 4 || month == 6 || month == 9 || month == 11)
      return 30;

    if (month == 2)
      if (isLeapYear(year))
        return 29;
      else
        return 28;

    return 0; // If month is incorrect.
  }

  /** Determine if it is a leap year */
   bool isLeapYear(int year) {
    if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
      return true;

    return false;
  }

  /** Print month body */
   void printMonthBody(int startDay, int numOfDaysInMonth) {
    // Pad space before the first day of the month
    int i = 0;
    for (i = 0; i < startDay; i++)
      cout <<"    ";

    for (i = 1; i <= numOfDaysInMonth; i++) {
      if (i < 10)
        cout <<"   "<<i;
      else
        cout <<"  "<< i;

      if ((i + startDay) % 7 == 0)
        cout<<endl;
    }

    cout <<"\n";
  }

  /** Print the month title, i.e. May, 1999 */
   void printMonthTitle(int year, int month) {
    
    cout <<"-----------------------------\n";
    cout <<" Sun Mon Tue Wed Thu Fri Sat\n";
    cout <<"         "<< getMonthName(month) <<", "<< year<<endl;
  }

  /** Get the English name for the month */
   const char* getMonthName(int month) {
    switch (month) {
      case 1: return "January"; break;
      case 2: return "February"; break;
      case 3: return "March"; break;
      case 4: return "April"; break;
      case 5: return "May"; break;
      case 6:  return "June"; break;
      case 7:  return "July"; break;
      case 8:  return "August"; break;
      case 9:  return "September"; break;
      case 10:  return "October"; break;
      case 11:  return "November"; break;
      case 12:  return "December";
    }

    return "";
  }


  int main() 
  {
    // Convert string into integer
    int month = 1;
    int year = 2015;

    // Print calendar for the month of the year
    printMonth(year, month);
    return 0;

}

- vg July 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

raj:
use the base 1970 epoc and then get moving

- Anonymous August 30, 2009 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More