CSN101 Project Report Sample

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

PROJECT REPORT (CSN101)

A report submitted in partial fulfilment of the requirement for the course

PROGRAMMING FOR PROBLEM SOLVING


Part of the degree of

BACHELOR OF COMPUTER SCIENCE AND ENGINEERING

Submitted to
Faculty Name
Assistant Professor
Submitted by:
Name- Divya Pal
Roll no-230102552
SAP ID- 1000020372
Section-C(P1)

SCHOOL OF COMPUTING
DIT UNIVERSITY, DEHRADUN
(State Private University through State Legislature Act No. 10 of 2013 of Uttarakhand and approved by UGC)

Mussoorie Diversion Road, Dehradun, Uttarakhand - 248009, India.


November 2023
CANDIDATES DECLARATION

I hereby certify that the work, which is being presented in the Report, entitled “PRINTING
CALENDER”, in partial fulfilment of the requirement as part of the course Programming for
Problem Solving of the Degree of Bachelor of Computer Science and Engineering and
submitted to the DIT University is an authentic record of my work carried out during the
period 22/11/2023 to 27/11/2023 under the guidance of Faculty name.

Date:
Signature of the Candidate

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


TABLE OF CONTENT
CHAPTER PAGE No.

Cover Page 01

Candidate’s Declaration 02

Table of Contents 03

Introduction 04

Project Description 05
Purpose
Problem Statement
System Requirements

Methods and Implementation 06 - 15

Functions used
Source Code
Output
Result Analysis

Conclusion 16

Bibliography 17

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Introduction
Printing a calendar is a classic programming exercise that demonstrates several fundamental
concepts in C programming. It involves manipulating data structures, performing calculations,
and formatting output. This project will guide you through the process of creating a C
program that prints a calendar for a given year.

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Project Description
Purpose:
The purpose of this project is to create a C program that prints a calendar for a given year.
The program should be able to handle different lengths of months, including February in leap
years. It should also determine the starting day of the week for each month and print the calendar
in a structured format with proper alignment and spacing.

Problem statement:
Given a year, the program should:
1. Determine the number of days in each month, including adjustments for leap years.
2. Calculate the starting day of the week for each month.
3. Format the calendar output with proper alignment and spacing.

System Requirements:
The code should adhere to the following system requirements:
• Programming Language: C
• Development Environment: Any compatible C compiler and editor
• Input: The year for which the calendar should be printed
• Output: A formatted calendar for the specified year
This function takes an integer representing the year as input and returns an integer indicating
whether the year is a leap year. A leap year is a year that has 29 days in the month of February.

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Methods and Implementation

The project includes functions to input the year, determine the day code, check for leap years,
and print the calendar for each month. The code is well-structured and utilizes arrays and nested
loops efficiently. Here's a breakdown of the code:

Main Function (main()):

Prompts the user to enter a year using inputyear()

Calculates the day code for the given year using determinedaycode()

Checks if the given year is a leap year using determineleapyear()

Prints the calendar for the given year using calendar()

Input Year Function (inputyear()):

Prompts the user to enter a year using printf()

Scans the input year using scanf()

Returns the entered year

Day Code Function (determinedaycode()):

Calculates the day code for the given year using Zeller's congruence

Returns the calculated day code

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Leap Year Function (determineleapyear()):

Checks if the given year is a leap year using the Gregorian calendar rules

Modifies days_in_month[2] to 29 for leap years

Returns 1 if a leap year, 0 otherwise

Calendar Function (calendar()):

Iterates through all months (1-12) using a for loop

Prints the month name using printf()

Prints the header line with weekday abbreviations using printf()

Determines the starting spaces using the day code and prints them

Iterates through the days of the month using a for loop

Prints each day with leading spaces and handles newlines

Updates the day code for the next month

Overall, the code effectively fulfills the task of printing a calendar for any given year,
demonstrating a clear understanding of the Gregorian calendar and programming concepts.

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Source code of Printing Calender in C language:-

#include<stdio.h>
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()
{
int year;

printf("Please enter a year (example: 1999) : ");


scanf("%d", &year);
return year;

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


}
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 == 0 && year%100 != 0 || year%400 == 0)
{
days_in_month[2] = 29;
return 1;
}
else
{
days_in_month[2] = 28;
return 0;
}
}

void calendar(int year, int daycode)


{

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


int month, day;
for ( month = 1; month <= 12; month++ )
{
printf("%s", months[month]);
printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );

for ( day = 1; day <= 1 + daycode * 5; day++ )


{
printf(" ");
}

for ( day = 1; day <= days_in_month[month]; day++ )


{
printf("%2d", day );

if ( ( day + daycode ) % 7 > 0 )


printf(" " );
else
printf("\n " );
}

daycode = ( daycode + days_in_month[month] ) % 7;


}
}
int main()

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


{
int year, daycode, leapyear;

year = inputyear();
daycode = determinedaycode(year);
determineleapyear(year);
calendar(year, daycode); printf("\
n");
}

/*******************************************************************
END OF CODE
********************************************************************/

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Outputs:-

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE
Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE
Result analysis:-

This project effectively achieves the task of printing calendars for various years entered by the
user, demonstrating a well-structured implementation of programming concepts and a clear
understanding of the Gregorian calendar. The code provides a solid foundation for further
enhancements and could serve as a useful tool for visualizing and understanding the structure of
the calendar.

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


Conclusion

Developing a program to print a calendar in C language was an insightful and practical


exercise in applying fundamental programming concepts and algorithms. The project
involved understanding and implementing concepts such as data structures, arrays,
loops, and conditional statements. It also required careful consideration of the
Gregorian calendar system and its rules for determining the number of days in a month
and leap years.The program successfully demonstrated the ability to generate and
display a calendar for any specified year. It accurately calculated the number of days in
each month, identified leap years, and correctly aligned days within each week. The
program's modular design made it easy to understand and maintain, and its use of arrays
and nested loops provided an efficient approach to handling calendar data. The project
highlighted the importance of careful planning and attention to detail in programming.
It also demonstrated the value of breaking down complex tasks into smaller,
manageable steps. The resulting program serves as a useful tool for visualizing and
understanding the structure of the Gregorian calendar.

Future enhancements to the program could include:

 Incorporating functions to calculate specific dates, such as finding the day of


the week for a given date.
 Adding options to customize the calendar's appearance, such as changing the
font or color of the days.

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE


 Implementing a graphical user interface (GUI) to provide a more interactive
and user-friendly experience.
Overall, the development of the calendar printing program provided valuable learning
experiences in C programming and reinforced the principles of algorithm design and
implementation. The program successfully achieved its objectives and serves as a
practical example of applying programming concepts to real-world applications.

Bibliography
Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE
REFERENCE:-
1. Google
2. Wikipedia
3. Let Us C by “Yashavant Kanetkar”
4. www.indiabix.com

Software used for the coding of this project is ‘CodeBlocks’.

Name:- Divya Pal SAP ID:- 1000020372 Branch:- CSE

You might also like